TAB on / TAB off (SOLVED)

Started by Husky, Mon 09/10/2006 00:26:10

Previous topic - Next topic

Husky

Ã,  Ã,  Ã, I'm trying to have the TAB button toggle the inventory on and off.Ã,  I'm having a problem because my code makes the inventory flicker, on , off, on ,off.
Ã,  Ã,  Ã, I've been trying to combat this by writing code that checks if the TAB button is pressed.Ã,  I think I'm going in the right direction in theory, but in practice I really have no clue what I'm doing.

In main global script file:
Code: ags

//Helps with Inventory on/off
bool pressingTAB;


In repeatedly_execute():
Code: ags

//Help with Inventory on/off
if (pressingTAB == true) {
Ã,  if (IsKeyPressed(9) == false) pressingTAB = false;Ã,  Ã, 
}


In - function on_key_press(int keycode):
Code: ags

if ((keycode==9) && (pressingTAB == false)} { // TAB, show inventory toggle
Ã,  if (gInventory.Visible == false) {
Ã,  Ã,  openInventory();
Ã,  Ã,  pressingTAB = true;
Ã,  }
Ã,  else {
Ã,  Ã,  gInventory.Visible = false;
Ã,  Ã,  Ã, pressingTAB = true;
Ã,  }


Ã,  Ã,  Ã, As usual, if anybody has any ideas, I'd be grateful to hear.
Thanks in advance.

Ashen

Try this:

Top of the Global script:
Code: ags

bool pressingTAB;


Rep_ex:
Code: ags

if (IsKeyPressed(9)) {
  if (pressingTAB == false) {
    if (gInventory.Visible == false) openInventory();
    else if (gInventory.Visible == true) gInventory.Visible = false;
  }
  pressingTAB = true;
}
else pressingTAB = false;


And you shouldn't need the on_key_press code. You had the right idea, using the bool to check if the button was being held so the GUI didn't 'flicker', but I think you had the conditions a little screwy.
I know what you're thinking ... Don't think that.

Husky

Excellent!  It works perfect.  Thanks, Ashen.

SMF spam blocked by CleanTalk