Get GlobalVariable via its number

Started by Sledgy, Sun 15/06/2014 19:30:53

Previous topic - Next topic

Sledgy

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
Global[2]=true; 
Display( Global[2].Name );

Khris

("Really x?" => "Is there x?" / "Does AGS have x?" ;))

AGS has this:
Code: ags
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:
Code: ags
// global header 
import int health[10];

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

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

SMF spam blocked by CleanTalk