Variables

Started by kantor_98, Thu 25/08/2005 07:29:11

Previous topic - Next topic

kantor_98

1. How many global variables can I use ?
2. In version 2.7 can I give them specific names ?

strazer

1.) Manual -> Reference -> System limits:
  500 script GlobalInts (indexes 0 to 499)
  50 script GlobalStrings (0 to 49)

And of course you can have self-defined variables (4KB's worth inside a function, not sure about global ones).
Global ("static"):

Code: ags

// global script

int MyVariable; // defined outside of any functions -> accessible to whole global script
export MyVariable; // export so it can be used everywhere


Code: ags

// main script header

import int MyVariable; // import in script header so it can be used in all scripts


Code: ags

  // some script

  MyVariable = 5;


Local ("dynamic"):

Code: ags

// global/room script

function DoStuff() {

  int myvariable; // -> defined inside function: local variable, only accessible in here

  //...

  myvariable = 5;

}


2.) Not directly and you won't be able to use these names in dialog scripts, but you could set up an enum like this:

Code: ags

// main script header

enum MyGlobalIntNames {
  eGlobalSolvedFirstPuzzle = 77 ,
  // ^ arbitrary name, but I like to prefix "eGlobal" so the autocomplete pops them all up when I need them
  //...
  eGlobalHasShoes = 78;
};


and use these names in your script like this:

Code: ags

  // some script

  SetGlobalInt(eGlobalSolvedFirstPuzzle, 1);
    // instead of "SetGlobalInt(77, 1);"


Also, I think you can name the graphical variables that are used in the interaction editor. To access them from the script, use the Get/SetGraphicalVariable functions.
But they're not supported very much so I suggest doing it the other way.

SMF spam blocked by CleanTalk