Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Knox on Thu 27/05/2010 17:49:01

Title: user input and global var with a textbox **SOLVED**
Post by: Knox on Thu 27/05/2010 17:49:01
Hi,

Im guessing this is pretty simple to answer but I cant debug this on my own. I first did the script in the manual for saving a screenshot:

 String input = Game.InputBox("Type the filename of your screenshot:");
 input = input.Append(".bmp");
 SaveScreenShot(input);


This works fine, it saves the bmp with the right filename the user inputs.
Next, I tried to accomplish the same but with my own gui:

function openScreenShotGUI()
{
 mouse.Mode = eModePointer;
 gScreenshotGUI.Visible = true;
 input = txtScreenshotInput.Text;
 input = input.Append(".bmp");
}

The button that takes the screenshot:

function btnScreenshot_OK_OnClick(GUIControl *control, MouseButton button)
{
 SaveScreenShot(input);
 gScreenshotGUI.Visible = false;
 mouse.Visible = false;
}

At the top of my global script, I declare the string "input":

String input;


However, with my custom GUI, the screenshot gets saved but there is no name...its just .bmp. Im guessing for some reason the input string gets reset to "null" when I call the function to take the screenshot?

What did I do wrong?
Title: Re: user input and global var with a textbox
Post by: Calin Leafshade on Thu 27/05/2010 18:14:43
Game.InputBox will pop up an input box and assign the value once you finish inputting.

Your function assigns the value when the gui is shown.. the user hasnt typed anything into it yet.

You need to assign the value to input when the gui is closed or just before the screenshot is saved.. i.e anytime after the user has typed the value.
Title: Re: user input and global var with a textbox
Post by: Khris on Thu 27/05/2010 19:20:39
This should do the trick:

function openScreenShotGUI() {
  mouse.Mode = eModePointer;
  gScreenshotGUI.Visible = true;
}

function btnScreenshot_OK_OnClick(GUIControl *control, MouseButton button) {
  input = txtScreenshotInput.Text;
  if (String.IsNullOrEmpty(input)) return;  // exit if name field is blank
  input = input.Append(".bmp");
  gScreenshotGUI.Visible = false;
  mouse.Visible = false;
  SaveScreenShot(input);
}


Note that I turned the GUI off before saving the screenshot, otherwise every screenshot contains the GUI.
Title: Re: user input and global var with a textbox
Post by: Knox on Thu 27/05/2010 19:24:10
Dang it, thats dumb of me :P
Works great now...thanks once again guys!!