How variables work in AGS 3?

Started by rock_chick, Fri 11/04/2008 14:12:05

Previous topic - Next topic

rock_chick

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.

TwinMoon

What I usually do is declare a variable at the top of the globalscript, in your case something like:
Code: ags
bool EnvelopeOpened;


in game_start you put:
Code: ags
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.

Khris


OneDollar

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:
Code: ags
bool EnvelopeOpened;


in game_start you put:
Code: ags
EnvelopeOpened = false;


You can just do
Code: ags

//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.

TwinMoon

Quote from: OneDollar on Sun 13/04/2008 01:54:06
You can just do
Code: ags

//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. ;)

SMF spam blocked by CleanTalk