Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Dan_N on Sun 24/12/2006 15:01:58

Title: How do I use global variables in room scripts? (SOLVED)
Post by: Dan_N on Sun 24/12/2006 15:01:58
Hello.

From the "Possibly Stupid Questions asked by Dan" series, we bring you the "How do I use global variables in room scripts?" episode.

Right, so, I've declared a global variable and want to use it in a room script for a hotspot. But when I type up the script, it doesn't recognize it. How do I do it then? Someone, please help me.

Oh, and if it helps, here's how I declared the global variable: I made a conditional action (if variable is set to a certain value) in the interaction window for the hotspot and then edited the variables and added my global one.

I would really like a fast answer to this, 'cos my project depends on this.

Thanks in advance, you lovely person who have taken time out of your life to answer me.
Title: Re: How do I use global variables in room scripts?
Post by: SSH on Sun 24/12/2006 15:04:13
For each global script variable:

put "export varname;" at the end of the global script
put "import int varname;" in the script header

Or... use the DeNGVaT module (http://ssh.me.uk/moddoc/DeNGVaT) and just type Global.Set("myvar") and Global.Get("myvar")...
Title: Re: How do I use global variables in room scripts?
Post by: Gilbert on Sun 24/12/2006 15:08:06
Or better, use the conventional way of exporting (http://www.adventuregamestudio.co.uk/manual/exportkeyword.htm) the variable after declaring it and then importing (http://www.adventuregamestudio.co.uk/manual/importkeyword.htm) back in that room's script (or in the script header if you want it to be used in all the rooms' scripts).

Edit: Alright, SSH edited his post before me, so it might look a bit odd.
Title: Re: How do I use global variables in room scripts?
Post by: Dan_N on Sun 24/12/2006 15:17:21
Wow, that was quite fast. Thanks SSH and Gilbot, I now continue working on Update Quest.