Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: barefoot on Tue 16/08/2011 10:06:59

Title: SOLVED: Turn off/turn on keyboard
Post by: barefoot on Tue 16/08/2011 10:06:59
Hi

Somewhere, I am sure, though can't seem to find it in the manual or here, there was Disable keyboard command.

The reason is because I do not want any keyboard action at certain points in the game. So turn off/turn on keyboard is what I am looking for.

eKeyboardMovement ?

I will go through keyboard scripts see if i can see anything.

I'm sure this is a noob question sorry.

barefoot




Title: Re: Turn off/turn on keyboard
Post by: Gilbert on Tue 16/08/2011 10:52:47
Just mess with the on_key_press() function (or whatever its correct name is).

Use a variable (say, kb_on) to hold the state on whether you want the keyboard to be active, and do something like:

if (kb_on){
  if (keycode==blah) bla bla;
}
Title: Re: Turn off/turn on keyboard
Post by: monkey0506 on Tue 16/08/2011 11:33:29
To simplify it even further, instead of enclosing the entire contents of on_key_press inside of an if statement, you could add this to the top:

// GlobalScript.asc

bool kb_on = true;

function on_key_press(eKeyCode keycode)
{
 if (!kb_on)
 {
   ClaimEvent();
   return;
 }
 // ...put your normal interactions here...no need for an else block since we returned if we entered the if
}

// wherever

kb_on = false;


Edit: I specified the global script in the comments, but for best results you would want to do this in the top script (to prevent module scripts being processed before the GlobalScript's function gets called).
Title: Re: Turn off/turn on keyboard
Post by: barefoot on Tue 16/08/2011 14:21:51
Cheers a lot guys I'll give it a whirl  :=

barefoot


Title: Re: Turn off/turn on keyboard
Post by: barefoot on Tue 16/08/2011 17:17:04
Hi

after looking at things i decided that all I needed was to divert some keyboard keys (Arrows and Esc) and they only apply to 1 room so the below script seems to be more appropriate.



}


//ARROW KEYS DIVERT (GLOBAL)


if(player.Room==2)
if (keycode == eKeyRightArrow)

{
cfighter1a.Walk(1227, 79, eBlock, eAnywhere);


}


if(player.Room==2)
if (keycode == eKeyLeftArrow )

{
cfighter1a.Walk(1227, 79, eBlock, eAnywhere);


}


if (player.Room==2)
if (keycode == eKeyDownArrow )

{

  cfighter1a.Walk(1227, 79, eBlock, eAnywhere);

}


if (player.Room==2)
if (keycode == eKeyUpArrow)

{
 
  cfighter1a.Walk(1227, 79, eBlock, eAnywhere);


}


if (player.Room==2)
if (keycode == eKeyEscape )

{

   gPanel.Visible=false;
   Display("You can't view control panel just now");
   cfighter1a.Walk(1227, 79, eBlock, eAnywhere);

}

//END ARROW KEYS


Thanks for your help anyway

cheers

barefoot


Title: Re: SOLVED: Turn off/turn on keyboard
Post by: monkey0506 on Tue 16/08/2011 19:15:27
Instead of checking if the player is in room 2 multiple times in direct succession of itself, why haven't you included those statements inside of a set of braces??

  //ARROW KEYS DIVERT (GLOBAL)
  if ((player.Room == 2) && ((keycode == eKeyRightArrow) || (keycode == eKeyLeftArrow) || (keycode == eKeyDownArrow) || (keycode == eKeyUpArrow) || (keycode == eKeyEscape)))
  {
    if (keycode == eKeyEscape)
    {
      gPanel.Visible = false;
      Display("You can't view control panel just now");
    }
    cfighter1a.Walk(1227, 79, eBlock, eAnywhere);
  }
  //END ARROW KEYS


I also took the liberty of combining your multiple references to the exact same line of code.
Title: Re: SOLVED: Turn off/turn on keyboard
Post by: Khris on Tue 16/08/2011 19:18:14
What the hell is this?

Seriously, every Walk command is using the same arbitrary coordinates? All arrow keys and the escape key are doing exactly the same?

Are you sort of undoing the command afterwards?

I'll take a wild guess and assume that all you want to do is turn off keyboard commands in room 2.

All you need to do is either catch them in the room script:
function on_key_press(eKeyCode k) {

  // kill all keyboard functionality
  ClaimEvent();
}


Or put this at the start of on_key_press in Global.asc:

  if (player.Room == 2) return;

You know, if you want to shut out somebody from every room in your house, why not go ahead and lock the front door?
Title: Re: SOLVED: Turn off/turn on keyboard
Post by: barefoot on Tue 16/08/2011 20:33:46
Hi Guys

I did it because if someone presses an arrow key in the main Room (2) it would stop the player and the game and will render game practically useless.. other keys are fine.

Any arrow key pressed makes the player go to B where there is a Region which determines which scene to go to next.

Normally the player would go automatically after Timer has expired.

I have a sound (text to speech) before the players moves but there was a problem getting the sound to play before move. It's ok now.

Also, I have disabled mouse cursor views so pressing ESC will be useless because no mouse cursor to do anything so it does as arrow keys.

* This is a side scrolling game with the player only able to move up and down and fire weapons. The scenes have objects and a background object that scroll left giving the illusion of movement.

So I'm coming across things that need a thinking hat  :=

|| just remembered  ::)

Probably Ar** about Face... but it does work in this instance.

I've taken in what you have said and thanks Monkey and Khris for your help and guidance.

:=

barefoot