Problem with IsKeyPressed

Started by Rejectdial, Wed 11/06/2008 22:48:28

Previous topic - Next topic

Rejectdial

I'm sorry to bother at my first post, but I have a strange problem (strange for me, at least).
My purpose is to make my character walk left/right by holding the left/right arrow key, so I used the IsKeyPressed script, as said in the Tutorial:

if (IsKeyPressed(372) == 1)
  cEgo.Walk(cEgo.x, cEgo.y+3);

I changed the various parts that I had to change (keycode 377 instead of 372, the name of my character instead of cEgo, and I wrote x+6 and y instead of x and y+3). Then I tested the game: result? My character moves only as I RELEASE the right arrow, while normally animating. I tried to change the form using on_key_press, but it works the same. Now, tell me if something I did is wrong: I tried to write these lines in two sections (repeatedly_execute and on_key_press) of global.asc, wich one of them is the right one? Maybe both, maybe neither of them? Do I have to write them in the Room's scripting, or perhaps in the Global.ash? Did I use the wrong command?
I don't really know, I'm still too unexperienced.
I'll explain what happens in the game test once again, just to be shure that anyone comprehends:
I press the Right arrow key; the character's animation starts, while he moves one bit to the right, then he stays still on the place while the animation keeps running; as I release the key, the character moves to the right (supposedly by 6 pixels), then the animation ends, and the character stops moving.
Thanks in advance!

Khris

Check the default game's Keyboard_Movement script.

monkey0506

As Khris suggests, there has been a module written to simplify moving your characters using the arrow keys.

Just FYI you would probably also need to make sure the character isn't moving or else they wouldn't start until the key is released (presuming the script was in rep_ex like it should be).

Rejectdial

Quote from: KhrisMUC on Wed 11/06/2008 23:16:50
Check the default game's Keyboard_Movement script.

Many thanks!
I'm sorry, I didn't notice that in the global script of the default game there were all those explanations.
Thanks again!

SMF spam blocked by CleanTalk