user input and global var with a textbox **SOLVED**

Started by Knox, Thu 27/05/2010 17:49:01

Previous topic - Next topic

Knox

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

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

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

The button that takes the screenshot:
Code: ags

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

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?
--All that is necessary for evil to triumph is for good men to do nothing.

Calin Leafshade

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.

Khris

This should do the trick:

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

Knox

Dang it, thats dumb of me :P
Works great now...thanks once again guys!!
--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk