Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Mon 30/10/2006 21:23:45

Title: Variables and Text Boxes...
Post by: on Mon 30/10/2006 21:23:45
I already did a search on this and it didn't turn anything up that I was looking for.

I was just wondering if there is some way to fill in a text-box, have that information get turned into a variable when you press OK and then be able to pass that on to another script somewhere else in the game?
Title: Re: Variables and Text Boxes...
Post by: Khris on Mon 30/10/2006 21:52:41
// global script
int a;    // variable
export a;  // add "import int a;" to the script header to make it global

// code itself
String n = Game.InputBox("Enter number:");
a=n.AsInt;  // convert to int
Title: Re: Variables and Text Boxes...
Post by: on Mon 30/10/2006 22:25:41
I hate simple answers. You never see them. ;)

Thanks a bunch, Khris.

EDIT:
I just realized something, this just generates a rudimentary input box. How about calling what is in a text field?
Title: Re: Variables and Text Boxes...
Post by: Ashen on Mon 30/10/2006 23:07:02
Please don't double post.

And re-read the manual. It sounds like what you want is the TextBox.Text (http://www.adventuregamestudio.co.uk/manual/TextBox.Text.htm) property, e.g.:


String n = txtMyText.Text;
a = n.AsInt;


(Or possibly just a = txtMyText.Text.AsInt; will work.)
Title: Re: Variables and Text Boxes...
Post by: Khris on Mon 30/10/2006 23:08:52
Then you'd have to put the code inside the _onClick-function of the OK-button.

Use TextBox.Text to get the number:
// if the textbox's script o-name was "Input"
a = Input.Text.AsInt;


EDIT: Ashen beat me.