Variables and Text Boxes...

Started by , Mon 30/10/2006 21:23:45

Previous topic - Next topic

wolverine88002

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?

Khris

Code: ags
// 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

wolverine88002

#2
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?

Ashen

Please don't double post.

And re-read the manual. It sounds like what you want is the TextBox.Text property, e.g.:

Code: ags

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


(Or possibly just a = txtMyText.Text.AsInt; will work.)
I know what you're thinking ... Don't think that.

Khris

Then you'd have to put the code inside the _onClick-function of the OK-button.

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


EDIT: Ashen beat me.

SMF spam blocked by CleanTalk