create type in boxes?

Started by HovSky, Sat 18/11/2017 00:27:33

Previous topic - Next topic

HovSky

Is it possible to create type in boxes in AGS. Lets say player comes to a door and now has to type in a password. Main thing is that the answer is not like a dialogue option, but player has to enter it from memory.

Gurok

You can use Game.InputBox for this. From the manual:

Code: ags
String name = Game.InputBox("!What is your name?");


If you put an ! before the prompt, both an OK and Cancel button will be shown. Remove it to just show the OK button.
[img]http://7d4iqnx.gif;rWRLUuw.gi

HovSky

Quote from: Gurok on Sat 18/11/2017 01:57:46
You can use Game.InputBox for this. From the manual:

Code: ags
String name = Game.InputBox("!What is your name?");


If you put an ! before the prompt, both an OK and Cancel button will be shown. Remove it to just show the OK button.

Thank you...
Continuing on last question, how can i edit this GUI. It doesn't show on project tree?



I am really sorry for not reading manual throughout, but I'm short on time. Demo is due tomorrow, and after that I will focus more on manual reading and script playing :-D

Cassiebsg

I think the only way is for you to create a costume text GUI and tell it to use that just one.
It's kind of tricky though.
There are those who believe that life here began out there...

Snarky

Quote from: HovSky on Sat 18/11/2017 03:20:14
I am really sorry for not reading manual throughout, but I'm short on time. Demo is due tomorrow, and after that I will focus more on manual reading and script playing :-D

Yeah, OK, but don't you think it would be quicker to look up stuff like this in the manual after all? If you'd just pressed F1 and done a search for "InputBox" (we're talking literally less than ten seconds, here), you would have seen:

Quotestatic String Game.InputBox(string prompt)

Pops up a window asking the user to type in a string, with PROMPT as the text in the window. Whatever they type in will be returned from this function.

This command displays a very basic input box, mainly useful for debugging purposes. Due to the size of the window, only small strings up to about 20 characters can be typed in.

The recommended way to obtain user input is to create your own GUI with a text box on it, which allows you full customization of the look of the window.
(My emphasis)

In other words, you can't edit it. Instead you should create your own GUI with the text box, label and buttons you want (let's call it gInput, with lblInput, txtInput, btnOkInput and btnCancelInput), and set its Visibility to "Popup modal" (which means that the game blocks whenever it is visible).

Hook up the OK and Cancel button click events like this:

Code: ags
btnOkInput_OnClick(GUIControl *control, MouseButton button)
{
  gInput.Visible = false;
}

btnCancelInput_OnClick(GUIControl *control, MouseButton button)
{
  txtInput.Text = "";    // Don't use the input entered
  gInput.Visible = false;
}


And finally write a function that will display the box and return the content of the text box:

Code: ags
String CustomInputBox(String prompt)
{
  lblInput.Text = prompt;
  gInput.Visible = true;  // This should block until Visible is set to false
  return txtInput.Text;
}


Now you can just call CustomInputBox() instead of Game.InputBox().

SMF spam blocked by CleanTalk