Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: zeta_san on Wed 02/03/2022 09:54:11

Title: Gui phone
Post by: zeta_san on Wed 02/03/2022 09:54:11
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
Title: Re: Gui phone
Post by: Khris on Wed 02/03/2022 12:55:26
Please add some details. How are you processing keypad clicks? Etc.
Title: Re: Gui phone
Post by: zeta_san on Wed 02/03/2022 19:02:51
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
Title: Re: Gui phone
Post by: Khris on Wed 02/03/2022 22:37:27
Righty, so you can do this for instance:

Code (ags) Select
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.
Title: Re: Gui phone
Post by: zeta_san on Thu 03/03/2022 09:04:47
ok, it seems clear but I get this error

GlobalScript.asc(335): Error (line 335): cannot assign initial value to global pointer
Title: Re: Gui phone
Post by: Khris on Thu 03/03/2022 09:09:12
Which line is 335?

Never mind, code fixed.
Title: Re: Gui phone
Post by: zeta_san on Thu 03/03/2022 09:11:31
Quote from: Khris on Thu 03/03/2022 09:09:12
Which line is 335?
(https://i.ibb.co/2qp3f87/Immagine-2022-03-03-101011.jpg) (https://imgbb.com/)
Title: Re: Gui phone
Post by: zeta_san on Thu 03/03/2022 09:12:51
(https://i.ibb.co/2qp3f87/Immagine-2022-03-03-101011.jpg)
Title: Re: Gui phone
Post by: zeta_san on Thu 03/03/2022 17:22:05
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
Title: Re: Gui phone
Post by: Khris on Thu 03/03/2022 19:51:53
Yeah, it was an example that needed a label called lblDisplay, which is why I put it as comment.
Title: Re: Gui phone
Post by: zeta_san on Fri 04/03/2022 08:21:27
yes then I understood .. thanks