So it just occured to me... I've got no idea how to capture string values from the player to re-use at a later time. For example, what kind of code would I need if I asked the player to name their favorite fruit, they say orange. Later I ask, what was your favorite fruit again? And if they said orange, it would say something like " oh yeah, that's right." and If they say anything else it replies with " no I don't think that was it. " I am using this for a text parser game. Thanks in advance for any and all help and I am sorry for my poor typing quality, still getting used to this damned iPod!
How about using structs? They are IMHO the best way to store data in AGS.
I haven't tested this:
global script header
// Struct definition
struct char_stats
{
String nickname;
String fav_fruit;
int age;
}
global script itself
//creating a var out of the struct called mainchar
char_stats mainchar;
// making accessible for other scripts
export mainchar;
later in the global script, you can use the struct like this:
mainchar.nickname = "Alf";
mainchar.age = 28;
mainchar.fav_fruit = "Banana";
If you want to access the struct in a room script, do this:
//first line, outside of the functions
import char_stats mainchar;
// inside a function - this is just bogus
function hotspot_interact {
mainchar.nickname = "Brian";
}
You can ask the player to type a string using the InputBox function.
As an alternative to its bland, grey box, you can use a GUI with a TextBox.
abstauber told you how to create global string variables from script; you can also use the Global variables pane.
In the TextBox's OnActivate function, call e.g.
fav_fruit = tbInput.Text; // tbInput is the scriptname of the TextBox
Later, you can use similar code to compare the contents of fav_fruit and tbInput.Text:
if (fav_fruit.CompareTo(tbInput.Text) == 0) Display("Oh yeah, that's right."); // non-case-sens. comparison
I very much appreciate the help, but now it throws the error:
room4.asc(6): Error (line 6): undefined symbol 'tbInput'
As Khris wrote in his comment, tbInput is the scriptname of the TextBox.
That means you have to create a gui, put a textbox inside it, and in the textbox properties write "tbInput" in the script name.
Yes, my post wasn't a step by step, rather a skeleton.
You'd also have to create a global string variable called "fav_fruit".
Quote from: tzachs on Tue 19/01/2010 09:06:12
As Khris wrote in his comment, tbInput is the scriptname of the TextBox.
That means you have to create a gui, put a textbox inside it, and in the textbox properties write "tbInput" in the script name.
Ah. Heh. Okay, I see. I was under the impression tbInput was a function of AGS script.
I did throw a new global variable in the global variable window, though, so when I try this out later I think everything will go smoothly, I'll update this later.