Global vars in script

Started by stryker, Mon 18/08/2003 23:18:20

Previous topic - Next topic

stryker

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.

Download Discworld Template ODIS ver1.2
(right-click and "save as")

Dr Snark


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?


stryker

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?

Download Discworld Template ODIS ver1.2
(right-click and "save as")

Dr Snark


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.


Ishmael

#4
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! ;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
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

stryker

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?

Download Discworld Template ODIS ver1.2
(right-click and "save as")

Ishmael

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...
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Pumaman

The  GetGraphicalVariable  command allows you to retrieve the value of an interaction editor variable. Look it up in the manual for more information. :)

stryker

Yea, that's it! Thankyou once again :)

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

Download Discworld Template ODIS ver1.2
(right-click and "save as")

SMF spam blocked by CleanTalk