Gui phone

Started by zeta_san, Wed 02/03/2022 09:54:11

Previous topic - Next topic

zeta_san

good morning
I created a GUI, a simple phone keypad. I would like to set a number (if you type for example 0012345)
proceed with an action
thanks

Khris

Please add some details. How are you processing keypad clicks? Etc.

zeta_san

hi Khris how are you?

for now I have created a gui with 12 keys.
123
456
789
* 0 #

click event and in globalscript

Button6_OnClick function (GUIControl * control, MouseButton button) {
  // USE INV
  OptionGui.OnClick (control, button); {
    player.Say ("1");
  }
}

Button7_OnClick function (GUIControl * control, MouseButton button) {
  // USE INV
  OptionGui.OnClick (control, button); {
    player.Say ("2");
  }
}

etc .. I wish that if the player typed the right number, the animation starts

Khris

#3
Righty, so you can do this for instance:

Code: ags
String keypadKeys;

function Type(String number) {
  if (keypadKeys == null) keypadKeys = "";
  keypadKeys = keypadKeys.Append(number);

  // display typed number in a label?
  // lblDisplay.Text = keypadKeys;

  if (keypadKeys == "0012345") {
    // stuff happens
  }
}

function button6_OnClick(GUIControl* control, MouseButton button) {
  Type("1");
}

function button7_OnClick(GUIControl* control, MouseButton button) {
  Type("2");
}


Note that if you created the keys in order, the digit on the key is  control.ID + 5, which means you can use a single function for all your 0-9 buttons.

zeta_san

ok, it seems clear but I get this error

GlobalScript.asc(335): Error (line 335): cannot assign initial value to global pointer

Khris

#5
Which line is 335?

Never mind, code fixed.

zeta_san

#6

zeta_san

#7

zeta_san

Quote from: Khris on Wed 02/03/2022 22:37:27

  // display typed number in a label?
  // lblDisplay.Text = keypadKeys;


lbl.Text = keypadKeys;
this works

Khris

Yeah, it was an example that needed a label called lblDisplay, which is why I put it as comment.

zeta_san

yes then I understood .. thanks

SMF spam blocked by CleanTalk