Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: rock_chick on Fri 11/04/2008 14:12:05

Title: How variables work in AGS 3?
Post by: rock_chick on Fri 11/04/2008 14:12:05
I was able to work it out much easier in 2.72 or whatever version I used to use but I'm looking for a way to set it so that after a certain things happens when doing the same action on a hotspot after the first to display a different message, not only for that action but it could be for any action, for example say the hotspot is a box, the player interacts at an unopened unopened envelope, and therefore the message says they've open it and the letter is now in their inventory, so afterwards I'd want a message saying something different if the player tries the same thing but also if they use another action for the same object, how would I be able to do that? My example may not be the best but I think it sums up what I'm talking about.
Title: Re: How variables work in AGS 3?
Post by: TwinMoon on Fri 11/04/2008 15:56:26
What I usually do is declare a variable at the top of the globalscript, in your case something like:
bool EnvelopeOpened;

in game_start you put:
EnvelopeOpened = false;

if you need to use it in rooms, put "export  EnvelopeOpened;" at the end of the global script and "import bool EnvelopeOpened;"  in the global header (globalscript.ash)
Both without the "" of course.

If the letter gets opened, simply set EnvelopeOpened to true.


For things that only have two states of being (open and unopened) it's easiest to use a bool.
If there's more than two states (for example a numberlock being set to a number between 0 and 9) you use an int. See the entry 'Variables' in the manual.
Title: Re: How variables work in AGS 3?
Post by: Khris on Fri 11/04/2008 19:52:03
There's a brand new function exactly for that purpose:
http://www.adventuregamestudio.co.uk/manual/Game.DoOnceOnly.htm
Title: Re: How variables work in AGS 3?
Post by: OneDollar on Sun 13/04/2008 01:54:06
Nice, didn't know about that function.

Just thought I'd add that instead of doing
Quote from: TwinMoon on Fri 11/04/2008 15:56:26
What I usually do is declare a variable at the top of the globalscript, in your case something like:
bool EnvelopeOpened;

in game_start you put:
EnvelopeOpened = false;

You can just do

//top of global script (or room script if you don't need to know if the envelope has been opened in any other rooms)
bool EnvelopeOpened = false;

which declares the variable and initially sets it to false.
Title: Re: How variables work in AGS 3?
Post by: TwinMoon on Sun 13/04/2008 20:00:11
Quote from: OneDollar on Sun 13/04/2008 01:54:06
You can just do

//top of global script (or room script if you don't need to know if the envelope has been opened in any other rooms)
bool EnvelopeOpened = false;

Yes, you're right. They makes it two things I've learned from this thread. ;)