Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Sat 07/06/2003 19:56:03

Title: Help needed for Global Variables
Post by: on Sat 07/06/2003 19:56:03
Hi everyone...
                 This is a simple problem but i cant get it through.I want to have a variable accessible by all room scripts in other words,throughout the game.But somehow i cant do it.And damn these Global Variables String...What Are They...........,,
   I know how to modify a variable but only this problem.Also what is the difference between STRING and INT???

Thankx for your corporation
Title: Re:Help needed for Global Variables
Post by: evilspacefart on Sat 07/06/2003 20:05:19
an INT is an integer, a number without decimals

SetGlobalInt(10,1);


a STRING is alphnumerical , like

SetGlobalString(1,"your mother");

you can only have 50 STRINGS, numbered 0 - 49


Title: Re:Help needed for Global Variables
Post by: on Sun 08/06/2003 08:38:47
Thankx for telling me the difference.But still i cant get through the problem.Can anyone tell me how to use a varibale accessible throughout the game.my variable is
int t_counter;
I want to use this throughout the game ie in different rooms.I can modify it from anywhere and access it from anywhere.So please anyone can help me.I read the tutorial but still i cant get through.
Thankx for ur corporation
Title: Re:Help needed for Global Variables
Post by: miguel on Sun 08/06/2003 10:34:16
In the global script after this line "function game_start() {"

SetGlobalInt(10,5);//global int10  has value 5

then you can call it in every room or change it's value in every room
Title: Re:Help needed for Global Variables
Post by: on Sun 08/06/2003 13:18:07
Hey guyz...
     I tried ur script but still no luck.The problem is that i have 2 rooms.
When the player picks up an item from one room the variable(int t_counter) increases by 1
then when he places that item in another it further increases by 1.So a thing appears in the current room when the variable is 2.
I tried doing this by typing int t_counter; at the top of the main global script file.
Then i tried modifying it from different locations but it says undefined token.
I tried using Globalints but i dont know how to use them and also wht r they.Can anyone give me a good example.PLEASE!!!!.
Also one more thing.Do Globalints require a normal int to work.

Thankx....
Title: Re:Help needed for Global Variables
Post by: Scummbuddy on Sun 08/06/2003 16:35:51
You can not rename a global int, it just stays as a number.  Is that the problem?  Just increase a specified global int, then check it when in the other room.
Title: Re:Help needed for Global Variables
Post by: on Mon 09/06/2003 07:50:11
Thank you all guys for your help.I finally got this globalint thing.But I just want to ask that i know how to change its value but how to increase it.I tried doing:
SetGlobalInt(10) +=(1);
But it does not work.So plz if anyone can help me in how to increase or decrease a global variable

Thankx A Lot
Title: Re:Help needed for Global Variables
Post by: Gilbert on Mon 09/06/2003 08:33:06
SetGlobalInt(10,GetGlobalInt(10)+1);
Title: Re: Help needed for Global Variables
Post by: Rainbow Guy on Sat 07/08/2004 10:59:52
Hi, after reading this thread and the help file i found this :-

"SetGraphicalVariable

Example:

SetGraphicalVariable("climbed rock", 1);

will set the interaction editor "climbed rock" variable to 1."


so couldn't he/i used variables instead  ??? It would be allot easyer if i could give the Variables names instead of numbers.

( but i'm a little worried by the term "Graphical" what's that mean ??? )
Title: Re: Help needed for Global Variables
Post by: Mr Jake on Sat 07/08/2004 11:03:29
you can.
Putting:

#define saveselected 2

in the script header will name global int 2 'saveselected' so you can do

SetGlobalInt (saveselected, 1); and GetGlobalInt (saveselected) etc. etc.
Title: Re: Help needed for Global Variables
Post by: Snarky on Sat 07/08/2004 18:47:52
You don't need to use GlobalInts. You can define and export variables in the global script, and import them in the script header. That way they will be available everywhere in your code.
Title: Re: Help needed for Global Variables
Post by: Rainbow Guy on Sat 07/08/2004 18:52:08
Quote from: Hotspot on Sat 07/08/2004 11:03:29
you can Putting:
#define saveselected 2
in the script header will name global int 2 'saveselected' so you can do
SetGlobalInt (saveselected, 1); and GetGlobalInt (saveselected) etc. etc.

Thanks man, thats well worth knowing  ;D ;D ;D
Title: Re: Help needed for Global Variables
Post by: Ashen on Sat 07/08/2004 18:53:26
1. 'Graphical' variables refers to variables created using the interaction editor, rather than using scripting.

2. What Snarky said. Look up import and export in the manual for how to create global ints with useful names.