Correct way to process keypresses [SOLVED]

Started by NiksterG, Wed 15/04/2009 01:49:57

Previous topic - Next topic

NiksterG

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!
Check out my games! (Not all made with AGS)

Gilbert

Yes.

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:
Code: ags

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){
     ...
  }
}


NiksterG

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!
Check out my games! (Not all made with AGS)

SMF spam blocked by CleanTalk