have.key sucks

Xqzzy Rcxmcq
if ((have.key() ||
controller(key_joystick))) {
set(menu_enabled);
display(1, 0, "TEXT");
if ((have.key()) {
stop.motion(ego);
reset(disable_game_functions);
clear.lines(1, 0, 0);
new.room(2);
}
}




Okay, this is how I have this set up.

The game goes to the title screen, where when the user presses any key (have.key) then it clears the screen and displays the text (from the display command). The problem is, when I have it like the code above, the interpreter does the two things at once. I want it to go to the first room after you press a key when it is displaying the text. Can anyone tell me how I can tell the interpreter that?
Joker Try placing the RETURN(); command at the following location:

if ((have.key() ||
controller(key_joystick))) {
set(menu_enabled);
display(1, 0, "TEXT");
RETURN();
if ((have.key()) {
stop.motion(ego);
reset(disable_game_functions);
clear.lines(1, 0, 0);
new.room(2);
}
}

That should do the trick. ;D
Eigen This code here works and it's tested:

....... your room code here.....

}
if((have.key()||
controller(key_joystick))) {
if(isset(f40)){
stop.motion(ego);
reset(disable_game_functions);
clear.lines(1, 0, 0);
new.room(2);
return();
}//else
set(menu_enabled);
display(1, 0, "TEXT");
set(f40);


.....other code here....

It checks if it's the first time pressed key then displays TEXT and sets f40. If f40 is set and you press a key it goes to the room 2.


-Eigen
Joel Does this mean that have.key always returns the same value during the same interpreter cycle? If so, that's probably something that should be added to the AGI Studio help file docs on have.key.
sonneveld From NAGI's source code.

at the start of each cycle:

state.var[V19_KEYPRESSED] = 0;

the have.key() eval (obviously haven't cleaned it up since the disassembly):

u8 cmd_have_key()
{
   u16 ax;
   ax = state.var[V19_KEYPRESSED];
   if ( ax == 0)
   {
      do
      {
         ax = char_poll();
      }
      while (ax == 0xFFFF);
   }

   if ( ax != 0 )
   {
      state.var[V19_KEYPRESSED] = ax;
      return 1;
   }
   else
      return 0;
}


but from the code, it looks like for each cycle it checks if var19 is 0 or not. If it's zero then it waits for a key press (if a key isn't in buffer already) and stores the key. If the key reading routine passes a non-zero number or var19 is already set, it returns true.

Shorter version: If it's found a key, it keeps on returning true and the same key in var19 until next cycle.

- Nick