Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Sledgy on Sun 15/06/2014 19:30:53

Title: Get GlobalVariable via its number
Post by: Sledgy on Sun 15/06/2014 19:30:53
Really get/set Global Variable (from the right panel or from the global script) via its number?

For ex., globvar DoorOpened (boolean). And for ex, it has number 2 in the globvar list. Can I work with this globvar via its number? Smth like
Code (ags) Select
Global[2]=true;
Display( Global[2].Name );
Title: Re: Get GlobalVariable via its number
Post by: Khris on Sun 15/06/2014 21:32:44
("Really x?" => "Is there x?" / "Does AGS have x?" ;))

AGS has this:
Code (ags) Select
void SetGlobalInt(number, value)
int GetGlobalInt(number)

They are obsolete, but you can still use them; named global variables and pointers are much more readable though, right?
You can create them in the editor's Global variables pane.

If you want index numbers, AGS supports global arrays:
// global header
import int health[10];

// global script
int health[10];
export health;

// in any script:
  health[3] = 20;
  Display("HP: %d", health[2]);