[SOLVED!] Keyboard cursor control (re-opened for discussion)

Started by monkey0506, Sun 12/09/2004 01:52:49

Previous topic - Next topic

monkey0506

I already had the interface_click(...) called in on_mouse_click(...).  :P And I created the my_int/on_mouse_click functions, and now it acts... Wierd. If I click on a button, it doesn't set the cursor mode until I click again, whether it's on a button or not. I.E., I click the button for give, and nothing happens, and then I click the button for pick up, and it sets the mode give. AAAAAHHH!!! It's so fursturaturing. Yes, fursturaturing, not just frustrating.

Mr. Mozzarella

OK, this is not about Cursors, but I thought I'd rather post here than opening a new thread:
I want to move the character around by using the arrow keys. This is my code:

Code: ags

Ã,  if (keycode==372){ //up
Ã,  Ã,  MoveCharacter(EGO, character[EGO].x, character[EGO].y-5);
Ã,  Ã,  }
Ã,  if (keycode==380){ //down
Ã,  Ã,  MoveCharacter(EGO, character[EGO].x, character[EGO].y+5);
Ã,  Ã,  }Ã,  
Ã,  if (keycode==375){ //left
Ã,  Ã,  MoveCharacter(EGO, character[EGO].x-5, character[EGO].y);
Ã,  Ã,  } 
Ã,  if (keycode==377){ //right
Ã,  Ã,  MoveCharacter(EGO, character[EGO].x+5, character[EGO].y);
Ã,  Ã,  } 


Of course, the way it is now, the character only walks one time. But I want him to walk as long as the key is pressed. I already tried while (IsKeyPressed(377)==1) but this doesn't work.

What am I supposed to do?  ???
Night of Fire - Thread

I control, I am in charge of
Everyones future, red button is mine

Rui 'Trovatore' Pires

#22
Use variables. Hang on, lemme hunt for some code I had...

EDIT - Ok, I used this in my SQ2 template, the "joystick movement" mode. I put it in rep_exec and it worked quite well. Mind you, since this is out of context I'm sure there's an extra bracket here somewhere.

Code: ags
Ã,  Ã,  if (IsKeyPressed(372)) {Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  //UP arrowÃ,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, 
Ã,  Ã, if (IsKeyPressed(375) && walkwhere!=5) {Ã,  Ã,  Ã,  Ã,  Ã, //UP-LEFTÃ,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  player.WalkStraight(player.x-500, player.y-500, eNoBlock);Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  
Ã,  Ã,  Ã,  walkwhere=5;
Ã,  Ã,  }
Ã,  Ã,  else if (IsKeyPressed(377) && walkwhere!=6) {Ã,  Ã,  Ã,  Ã,  //UP-RIGHT
Ã,  Ã,  Ã,  player.WalkStraight(player.x+500, player.y-500, eNoBlock);
Ã,  Ã,  Ã,  walkwhere=6;
Ã,  Ã,  }
Ã,  Ã,  else if (walkwhere!=1 && IsKeyPressed(375)==0 && IsKeyPressed(377)==0){
Ã,  Ã,  Ã,  player.WalkStraight(player.x, player.y-500, eNoBlock);
Ã,  Ã,  Ã,  walkwhere=1;
Ã,  Ã,  }
Ã,  }
Ã,  if (IsKeyPressed(375)) {Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, //LEFT arrow
Ã,  Ã,  if (IsKeyPressed(372) && walkwhere!=5) {Ã,  //LEFT-UP
Ã,  Ã,  Ã,  player.WalkStraight(player.x-500, player.y-500, eNoBlock);
Ã,  Ã,  Ã,  walkwhere=5;
Ã,  Ã,  }
Ã,  Ã,  else if (IsKeyPressed(380) && walkwhere!=7) { //LEFT-DOWN
Ã,  Ã,  Ã,  player.WalkStraight(player.x-500, player.y+500, eNoBlock);
Ã,  Ã,  Ã,  walkwhere=7;
Ã,  Ã,  }
Ã,  Ã,  else if (walkwhere!=2 && IsKeyPressed(372)==0 && IsKeyPressed(380)==0){
Ã,  Ã,  Ã,  player.WalkStraight(player.x-500, player.y, eNoBlock);
Ã,  Ã,  Ã,  walkwhere=2;
Ã,  Ã,  }
Ã,  }
Ã,  if (IsKeyPressed(377)) { 
Ã,  Ã,  if (IsKeyPressed(372) && walkwhere!=6) {Ã,  Ã,  Ã,  Ã,  //RIGHT-UP
Ã,  Ã,  Ã,  player.WalkStraight(player.x+500, player.y-500, eNoBlock);
Ã,  Ã,  Ã,  walkwhere=6;
Ã,  Ã,  }
Ã,  Ã,  else if (IsKeyPressed(380) && walkwhere!=8) { //RIGHT-DOWN
Ã,  Ã,  Ã,  player.WalkStraight(player.x+500, player.y+500, eNoBlock);
Ã,  Ã,  Ã,  walkwhere=8;
Ã,  Ã,  }
Ã,  Ã,  else if (walkwhere!=3 && IsKeyPressed(380)==0 && IsKeyPressed(372)==0){ //RIGHT Arrow
Ã,  Ã,  Ã,  player.WalkStraight(player.x+500, player.y, eNoBlock);
Ã,  Ã,  Ã,  walkwhere=3;
Ã,  Ã,  }
Ã,  }
Ã,  if (IsKeyPressed(380)) {
Ã,  Ã,  if (IsKeyPressed(375) && walkwhere!=7) { //DOWN-LEFT
Ã,  Ã,  Ã,  player.WalkStraight(player.x-500, player.y+500, eNoBlock);
Ã,  Ã,  Ã,  walkwhere=7;
Ã,  Ã,  }
Ã,  Ã,  else if (IsKeyPressed(377) && walkwhere!=8) { //DOWN-RIGHT
Ã,  Ã,  Ã,  player.WalkStraight(player.x+500, player.y+500, eNoBlock);
Ã,  Ã,  Ã,  walkwhere=8;
Ã,  Ã,  }
Ã,  Ã,  else if (walkwhere!=4 && IsKeyPressed(377)==0 && IsKeyPressed(375)==0){ //Down ArrowÃ,  Ã, //**Ã,  Ã, END OF JOYSTICK MOVEMENT CODE
Ã,  Ã,  Ã,  player.WalkStraight(player.x, player.y+500, eNoBlock);Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, //**
Ã,  Ã,  Ã,  walkwhere=4;Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, //**
Ã,  Ã,  }Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  //**
Ã,  }Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  //**
//*********************************************************************************************
Ã,  if (IsKeyPressed(372)==0) {Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  //**
Ã,  Ã,  if (IsKeyPressed(375)==0 && walkwhere==5) {//UP-LEFTÃ,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, //**
Ã,  Ã,  Ã,  player.StopMoving();Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, //**
Ã,  Ã,  Ã,  walkwhere=0;Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, //** START OF JOYSTICK "STOP MOVEMENT"
Ã,  Ã,  }Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  //**Ã,  CODE
Ã,  Ã,  else if (IsKeyPressed(377)==0 && walkwhere==6) { //UP-RIGHT
Ã,  Ã,  Ã,  player.StopMoving();
Ã,  Ã,  Ã,  walkwhere=0;
Ã,  Ã,  }
Ã,  Ã,  else if(walkwhere==1) {Ã,  //UP
Ã,  Ã,  Ã,  player.StopMoving();
Ã,  Ã,  Ã,  walkwhere=0;
Ã,  Ã,  }
Ã,  }
Ã,  if (IsKeyPressed(375)==0) {
Ã,  Ã,  if (IsKeyPressed(372)==0 && walkwhere==5) {//LEFT-UP
Ã,  Ã,  Ã,  player.StopMoving();
Ã,  Ã,  Ã,  walkwhere=0;
Ã,  Ã,  }
Ã,  Ã,  else if (IsKeyPressed(380)==0 && walkwhere==7) {//LEFT-DOWN
Ã,  Ã,  Ã,  player.StopMoving();
Ã,  Ã,  Ã,  walkwhere=0;Ã,  Ã,  
Ã,  Ã,  }
Ã,  Ã,  else if (walkwhere==2) {
Ã,  Ã,  Ã,  player.StopMoving();
Ã,  Ã,  Ã,  walkwhere=0;
Ã,  Ã,  }
Ã,  }
Ã,  if (IsKeyPressed(377)==0) {
Ã,  Ã,  if (IsKeyPressed(372)==0 && walkwhere==6) { //RIGHT-UP
Ã,  Ã,  Ã,  player.StopMoving();
Ã,  Ã,  Ã,  walkwhere=0;
Ã,  Ã,  }
Ã,  Ã,  else if (IsKeyPressed(380)==0 && walkwhere==8) { //RIGHT-DOWN
Ã,  Ã,  Ã,  player.StopMoving();
Ã,  Ã,  Ã,  walkwhere=0;
Ã,  Ã,  }
Ã,  Ã,  else if (walkwhere==3) {Ã,  //DOWN Arrow
Ã,  Ã,  Ã,  player.StopMoving();
Ã,  Ã,  Ã,  walkwhere=0;
Ã,  Ã,  }
Ã,  }
Ã,  if (IsKeyPressed(380)==0) {
Ã,  Ã,  if (IsKeyPressed(372)==0 && walkwhere==7) {//DOWN-LEFT
Ã,  Ã,  Ã,  player.StopMoving();
Ã,  Ã,  Ã,  walkwhere=0;Ã,  Ã,  
Ã,  Ã,  }
Ã,  Ã,  else if (IsKeyPressed(377)==0 && walkwhere==8) { //DOWN-RIGHT
Ã,  Ã,  Ã,  player.StopMoving();
Ã,  Ã,  Ã,  walkwhere=0;
Ã,  Ã,  }
Ã,  Ã,  else if (walkwhere==4) { //DOWN
Ã,  Ã,  Ã,  player.StopMoving();Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, //**Ã,  Ã,  END OF JOYSTICK"STOP MOVEMENT" CODE
Ã,  Ã,  Ã,  walkwhere=0;Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, //**
Ã,  Ã,  }Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  //**
Ã,  }								Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, //**
}
//*************************************************************************************
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Mr. Mozzarella

Night of Fire - Thread

I control, I am in charge of
Everyones future, red button is mine

monkey0506

Basically it's just that you needed to put the if (IsKeyPressed(XXX)) {...} statements in repeatedly_execute instead of on_key_press.  That way the statement gets run while the key is held (unless character movement is blocking (I don't know) in which case you would have to use repeatedly_execute_always).  And if you only use if (IsKeyPressed(XXX)) {...} statements instead of if ... else if... then the character can move in multiple directions at once (i.e., north-east (up-left)).

Also I noticed that your code (Mr. Mozzarella) was 2.62 style while Rui's post had 2.7 scripting.  If you are using AGS v. 2.62 then Rui's code won't work correctly.

In either case just moving your code to rep_ex should fix it...

Rui 'Trovatore' Pires

Yeah, essentially that plus the use of a variable to check whether the character is already moving and in which direction (if walkwhere==0 then he ain't moving, else he's moving in some direction). If he just moved HIS code to rep_exec this wouldn't work, it needs more "bulk" than that.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

SMF spam blocked by CleanTalk