Telephone/Keypad GUI Help

Started by Tenacious Stu, Mon 20/12/2010 16:49:45

Previous topic - Next topic

Tenacious Stu


want to create a GUI with Buttons on, so that when the player presses them in a certain sequence, something happens. But I just don't even know where to start with this one. I'm just wondering how you would write the script so that when a button is pressed the number is added to a sequence and then some way for the game to know if the sequence correlates with the correct answer?

Thanks in advance for any replies ;)

Khris

One way is too add the keypress to a String.
I'd create the ten buttons so that their ID corresponds to the keypad key they represent.
Then you can put "keypad_OnClick" in all their On Click event fields and use a single function:

Code: ags
function keypad_OnClick(GUICointrol*gc, MouseButton button) {
  int a = gc.ID;    //  or gc.AsButton.ID if that doesn't work.
  entered_combo = String.Format("%s%d", entered_combo, a);  // append pressed key
  
  if (entered_combo == "1234") blah();
}


You can use another button to clear the entered_combo String, or you can check the last 4 chars only so that the player doesn't have to clear previous input.

It all depends on how exactly you want the keypad to operate.

SMF spam blocked by CleanTalk