arrow key movement help

Started by proskiier, Wed 27/02/2008 21:44:36

Previous topic - Next topic

proskiier

i found code for arcade style (arrow keys) movement and i think it was from an old version

i had to rework some of the code i found and i got some help from the help file, but it still giving me a "(" error and ive checked all the counting of ( and {

i hope its not some dumb fix so I don't feel stupid but if anyone could help me out would be great

btw its in the function on_key_press(int keycode) in the global script

Code: ags

if (keycode==372) { // up arrow
    character[EGO].WalkStraight(player.x, player.y-200);    
		while ((IsKeyPressed(372)>0) && (character[EGO].WalkStraight)) Wait(1); 
    StopMoving(EGO);
}
if (keycode==375) { // left arrow
    character[EGO].WalkStraight(player.x, player.x-200, player.y);
    while ((IsKeyPressed(375)>0) && (character[EGO].WalkStraight)) Wait(1);
    StopMoving(EGO);
}
if (keycode==377) { // right arrow
    character[EGO].WalkStraight(player.x, player.x+200, player.y);
    while ((IsKeyPressed(377)>0) && (character[EGO].WalkStraight)) Wait(1);
    StopMoving(EGO);
}
if (keycode==380) { // down arrow
    character[EGO].WalkStraight(player.x, player.x, player.y+200);
    while ((IsKeyPressed(380)>0) && (character[EGO].WalkStraight)) Wait(1);
    StopMoving(EGO);
}


thanks alot guys/gals in advance :)

GarageGothic

#1
The problem is that you're using Character.WalkStraight as if it was a boolean. Instead of:

Code: ags
while ((IsKeyPressed(375)>0) && (character[EGO].WalkStraight)) Wait(1);


You should be using:

Code: ags
while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);


Let me know if it works. I think there might be dodgy stuff going on in other parts of the code too. In my opinion some of it should be moved from IsKeyPressed to repeatedly_execute. Could you possibly link to the code you found, it would make it easier to see how you came up with this?

proskiier

this is what i have now and it still giving me an error '(' expected, and i have no idea what is wrong... someone please help :)


Code: ags

if (keycode==372) { // up arrow
    character[EGO].WalkStraight(player.x, player.y-200);    
		while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving;
}
if (keycode==375) { // left arrow
    character[EGO].WalkStraight(player.x, player.x-200, player.y);
    while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving;
}
if (keycode==377) { // right arrow
    character[EGO].WalkStraight(player.x, player.x+200, player.y);
    while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving;
}
if (keycode==380) { // down arrow
    character[EGO].WalkStraight(player.x, player.x, player.y+200);
    while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving;
}

VK Dan

Character.StopMoving() is a function, so you need the parenthesis when you call it (even though there are no paramaters).

Code: ags

if (keycode==372) { // up arrow
    character[EGO].WalkStraight(player.x, player.y-200);    
		while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving();
}
if (keycode==375) { // left arrow
    character[EGO].WalkStraight(player.x, player.x-200, player.y);
    while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving();
}
if (keycode==377) { // right arrow
    character[EGO].WalkStraight(player.x, player.x+200, player.y);
    while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving();
}
if (keycode==380) { // down arrow
    character[EGO].WalkStraight(player.x, player.x, player.y+200);
    while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving();
}

proskiier

that helped but now only walking left works.... any idea why???


Code: ags

if (keycode==372) { // up arrow
    character[EGO].WalkStraight(player.x, player.y-200,eNoBlock);    
		while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving();
}
if (keycode==375) { // left arrow
    character[EGO].WalkStraight(player.x-200, player.y,eNoBlock);
    while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving();
}
if (keycode==377) { // right arrow
    character[EGO].WalkStraight(player.x+200, player.y,eNoBlock);
    while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving();
}
if (keycode==380) { // down arrow
    character[EGO].WalkStraight(player.x, player.y+200,eNoBlock);
    while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);
    character[EGO].StopMoving();
}

VK Dan

I can't test the code right now, but it looks like the error is in your while loop. You have each of them set as

Code: ags
while ((IsKeyPressed(375)>0) && (character[EGO].Moving)) Wait(1);


Where as you need to have the correct ASCII code for each loop (e.g, the up arrow should be)
Code: ags
 while ((IsKeyPressed(372)>0) && (character[EGO].Moving)) Wait(1);

SMF spam blocked by CleanTalk