Author Topic: have.key sucks  (Read 2482 times)

0 Members and 1 Guest are viewing this topic.

Offline Xqzzy Rcxmcq

have.key sucks
« on: May 18, 2003, 07:26:27 PM »
Code: [Select]
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);
  new.room(2);
}
}

Code: [Select]

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?


Pathfinder. After I finish CIMS 2004.

Joker

  • Guest
Re:have.key sucks
« Reply #1 on: May 19, 2003, 02:39:56 AM »
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);
  new.room(2);
  }
}

That should do the trick.  ;D

Offline Eigen

Re:have.key sucks
« Reply #2 on: May 19, 2003, 07:16:22 AM »
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);
  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
Artificial Intelligence Competition

Offline Joel

Re:have.key sucks
« Reply #3 on: May 19, 2003, 05:23:27 PM »
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.

Offline Nick Sonneveld

Re:have.key sucks
« Reply #4 on: May 19, 2003, 08:11:39 PM »
From NAGI's source code.

at the start of each cycle:

Code: [Select]
state.var[V19_KEYPRESSED] = 0;
the have.key() eval (obviously haven't cleaned it up since the disassembly):

Code: [Select]
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
Nick Sonneveld  |  AGI Dev  |  NAGI


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.039 seconds with 15 queries.