Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: steptoe on Sat 26/11/2011 06:58:02

Title: Disable the keyboard for every room
Post by: steptoe on Sat 26/11/2011 06:58:02
Hi

I am trying to disable the keyboard for every room.

The below code in each room works but does not stop Alt + x, though it does disable Esc, F save, F Load etc.

In each Room I have:


function on_key_press(eKeyCode k) {

 // kill all keyboard functionality
 ClaimEvent();
}


Even tried this Top of Global:


bool kb_on = true;


and with this in Global:


function on_key_press(eKeyCode keycode)

{
 if (!kb_on)   // and with if (kb_on)
 {
   ClaimEvent();
   return;


Can you help?

Cheers




Title: Re: Disable the keyboard for every room
Post by: Snarky on Sat 26/11/2011 10:47:17
You can't disable Alt-X. It's built into the engine as a failsafe so that it's always possible to quit in case your game locks up.
Title: Re: Disable the keyboard for every room
Post by: Dualnames on Sat 26/11/2011 11:09:30
QuoteThe keycode for Abort Game, which allows the you to quit even if your script is stuck. Default 324 (Alt+X).

So if you disable it then if you game gets stuck, people have to use alt ctrl delete or some other way.

Apart from pointing that, your code seems to work, though just keeping all the stuff on a global script or a module script and having only one instance of the on_key_press function is definitely the way I would go. Just a global boolean variable and on instance of keypress.


function on_key_press(eKeyCode keycode)
{
  if (kb_on) 
  {
//rest of script ecc inside the if
  }
}
Title: Re: Disable the keyboard for every room
Post by: Khris on Sat 26/11/2011 12:06:16
Or

  if (!kb_on) return;   // exit the function

You can disable Alt-X by changing the value of game.abort_key.
If you do that though, please mention it when you publish the game so people know not to download it.
Title: Re: Disable the keyboard for every room
Post by: monkey0506 on Sat 26/11/2011 15:47:19
For maximum troll points, set game.abort_key to -1, completely disabling it.
Title: Re: Disable the keyboard for every room
Post by: steptoe on Sat 26/11/2011 17:18:46
Hi

thanks for your answers guys.   

It was more of a quest to find an answer than to actually use it so no total Troll points monkey  ;D

It is fine as it is with alt + x to quit.

I do have a visual Quit option available during the game.

Thanks again.




Title: Re: Disable the keyboard for every room
Post by: monkey0506 on Sat 26/11/2011 21:43:44
The benefit of the abort key is that it is still functional even when other interface items (such as keypresses and button clicks) may not be. You can change the abort key if you want, but document it clearly if you do so. Disabling it completely is just stupid (unless it's an Oceanspirit Dennis game).

I'm aware you said already that you're not planning to disable it, but Khris' comment may have come across the wrong way, so I wanted to clarify that as long as you make it known what the abort key is you should still be fine (even if you do choose to change it for some reason).
Title: Re: Disable the keyboard for every room
Post by: Khris on Sat 26/11/2011 21:59:20
Yeah, I just wanted to express how stupid I find it to take away the only failsafe for a hanging game. This is were I think the line between design choices and being a control freak is crossed.

I briefly considered to post something along the lines of "if you don't know how to disable it, you probably shouldn't do it in the first place".
Title: Re: Disable the keyboard for every room
Post by: steptoe on Sun 27/11/2011 09:41:15
Khris:

It was a thought I had, but opted out for fail-safe reasons as mentioned (after consideration).

I overlooked Abort because I was looking at 407(Alt) + X.

In game design you do need an exit, period. I do have an exit sign visible and of course good old Alt + X is available as well.

I appreciate your words of wisdom for future reference.

Monkey:

Likewise as with Khris, thanks.

OSP: How to script crap in the best possible way.

Don't steal any crap ideas from us minor urchins :D

Thanks guys

Title: Re: Disable the keyboard for every room
Post by: Gilbert on Sun 27/11/2011 13:42:21
Quote from: Khris on Sat 26/11/2011 21:59:20
Yeah, I just wanted to express how stupid I find it to take away the only failsafe for a hanging game.
Shouldn't Ctrl-Alt-End always work? It doesn't help if the player is not familiar with AGS or didn't read the game's documents even if it's mentioned.