Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: NiksterG on Wed 15/04/2009 01:49:57

Title: Correct way to process keypresses [SOLVED]
Post by: NiksterG on Wed 15/04/2009 01:49:57
I was just wondering if what I'm thinking is the correct way of doing things or not.

I want to have the player press an arrow key on the keyboard, but depending on which room it's pressed in, it does different things. There's the default action (move character) which I placed in the global script. In one room, however, I want to scroll the room with ViewPort.

So my question is this:
Can I make a on_key_press function in a room script? Or do I put the code in the room's repeatedly_execute?

Either way, I believe I need to put a ClaimEvent call somewhere in the room, correct?

Thank you!
Title: Re: Correct way to process keypresses
Post by: Gilbert on Wed 15/04/2009 02:03:10
Yes. (http://www.adventuregamestudio.co.uk/manual/TextScriptEvents.htm)

QuoteThe on_key_press and on_mouse_click events can also be handled by individual room scripts. If you add their function definitions to your room script in a similar way to how they are in the global script, the room script can intercept the keypress/mouseclick first, and then decide whether to pass it on to the global script or not. See the ClaimEvent function for more.

Basically what you put in the room script is something like this:

function on_key_press(eKeyCode key){
  if (key==eKeyA) {
     blah bla bla
     ClaimEvent(); //Not needed if you don't detect this key in the global script, or if you want the action in the global script to also be taken
  } else if (key==eKeyB){
     ...
  }
}

Title: Re: Correct way to process keypresses
Post by: NiksterG on Wed 15/04/2009 02:06:32
Wow, that was fast  ;D

That's kind of what I thought, but I wasn't certain and I couldn't find it in the manual.

Thanks for the quick reply!