Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: stryker on Mon 18/08/2003 23:18:20

Title: Global vars in script
Post by: stryker on Mon 18/08/2003 23:18:20
Let's suppose I set a global var to 1 in AGS editor, let's say I call it "box open" because it turns 1 when a box is opened by player.
Now I have to run a SCRIPT (not a normal interaction with conditional) that does something if global var is 0, and something else if it's 1.

My question is: how to handle conditionals in script? How can I put in the code "if box open is 1 then do this"? I tried with:
if (box open == 1)
but it doesn't work. It doesn't work too if I use
if (1 == 1)
(box open is the global var n. 1). I also tried:
if (GetGlobalInt(1)==1)
but it doesn't work as well.

It can be done? How?

thanx


oh and another question that doesn't concern the topic: there is no "display speech" command in the list in ags editor interactions. is that right? that's strange.
Title: Re:Global vars in script
Post by: Dr Snark on Tue 19/08/2003 00:17:14

Its:
SetGlobalInt(4,1);

will set the Global Integer 4 to 1.

Don't Mix and Match your Global int's

like say SetGlobal(4,1)// Set Box Open to 1

4 being your "Set Box"

and use the GetGlobalInt(4)==1);
I hope this helps as  I can't explain Easily, LOL

ok?

Title: Re:Global vars in script
Post by: stryker on Tue 19/08/2003 01:19:37
umm... I don't think I understood very well.

Are you saying I can't get the global var value froma a script and I have to use a Global int from the beginning?
Can't I set an event to change a global var if I know the value will be retrived by a scipt? Have I to use scripts for the beginning using Global ints?
Title: Re:Global vars in script
Post by: Dr Snark on Tue 19/08/2003 01:26:35

What I'm saying is:

In the function_gameStart:

SetGlobalInt(4,1);

and you can call it From ANYWHERE in the Script.

You Cant name them as far as I know. I've tried naming them and i get an error.

Title: Re:Global vars in script
Post by: Ishmael on Tue 19/08/2003 09:04:01
Global Ints are meant to be accesable from ANYWHERE in the game scritpts. Use SetGlobalInt(num, val); to set the value, and GetGlobalInt(num); to check it. If you use AJA's Script Editor (you should (http://koti.mbnet.fi/dima/scripteditor/)! ;D) you can use the game memo to 'name' your GlobalInts... Like I do:

in the GlobalInts section:

GlobalInt 1 : Cupboard open
GlobalInt 2 : Player been in room 5

or so... they dont have names or anything in script, but you can name them outside it, and then just match the names to number in your head...

;D
Title: Re:Global vars in script
Post by: stryker on Tue 19/08/2003 22:26:35
Ok, I know how Global Ints work (thanks for the script editor tip!), but I'm just asking if I can retrive the value of a global VAR (the ones you use in the ags editor) from a script.
I set a global var with the editor, and I have to retrive the value in a script. The options are:
1) it can be done (how?)
2) it cannot be done: if I know that a certain value must be retrived with a script, I MUST use a global int (not a var) to SET it too.
wich one of those is true?
Title: Re:Global vars in script
Post by: Ishmael on Wed 20/08/2003 05:24:52
um... Do you mean like if you have decleared an int, say my_counter, in the beginning of the global script, how do you acces it from say, a room script?
If this is what you mean, then just put

export (intname);

to the end of the global script, and add

import int (intname);

to the script header. You need to rebuild all rooms after modifying the script header. After that you should be able to use your int in all scripts...
Title: Re:Global vars in script
Post by: Pumaman on Wed 20/08/2003 20:52:26
The  GetGraphicalVariable  command allows you to retrieve the value of an interaction editor variable. Look it up in the manual for more information. :)
Title: Re:Global vars in script
Post by: stryker on Fri 22/08/2003 00:30:29
Yea, that's it! Thankyou once again :)

sorry for my english, it's hard to explain all that technical stuff!!