-
Notifications
You must be signed in to change notification settings - Fork 0
GlobalVariables
The Global Variables pane allows you to easily add variables to your game which can then be accessed from all your scripts.
In previous versions of AGS, declaring a global variable in the script involved defining it in three different places, with import and export clauses in the appropriate locations. Now, this whole process is vastly simplified with the new Global Variables Editor.
When should I use a global variable?
Use a global variable when you need to store some information that you need to access from different scripts. For example, if you want to store the player's health and you want all your different scripts to be able to access this value, then use a global variable.
If you just need to store some information locally (for example, a "door opened" flag that only applies to one particular room) then you should declare the variable manually at the top of the room's script file instead.
What about GlobalInts and Graphical Variables?
GlobalInts and Graphical Variables were ways in which previous versions of AGS provided global variable capabilities. They are now considered obsolete, and are replaced with this new Global Variables system instead.
How do I use global variables?
The Global Variables Editor is pretty self-explanatory. To add a variable, right-click and choose "Add". You can name the variable, and choose its type and initial value. Most of the time you'll probably be using the int and String types. Optionally, you can also set a default value for the variable.
Then, in your scripts it's a simple matter of just using the variable with the name that you gave it. Simple! So, for example if you add an int global variable called "myVariable", then in your script you can just do things like this:
if (myVariable == 3)
{
myVariable = 4;
}
or
Display("myVariable: %d", myVariable);
That's it! Just use it as you'd use any other variable declared in the script.
Note that some of the types available are managed instance pointers, like "GUI", "DynamicSprite" and "Character". These are for more advanced users only. If you create one of these you cannot set a default value, and it will initially be set to null. You will need to initialize the pointer in your script to point to something before you use it.
Getting Started in AGS
Editor Reference
- Music and sound
- Distributing your game
- Backing up your game
- The text parser
- Translations
- Global variables
- Custom Properties
- Plugins
- Lip sync
- New Game templates
- Debugging features
- Auto-number speech files
- Integration with Windows
- Source Control integration
Engine
Scripting
- Scripting tutorial part 1
- Scripting tutorial part 2
- Pointers in AGS
- Calling global functions from local scripts
- The script header
- String formatting
- Multiple Scripts
- Understanding blocking scripts
- Dynamic Arrays
- Extender functions
- Game variables
- Predefined global script functions
- repeatedly_execute (_always)
- Custom dialog options rendering
- Built-in enumerated types
- Script language keywords
- AudioChannel functions and properties
- AudioClip functions and properties
- Character functions and properties
- DateTime functions and properties
- Dialog functions and properties
- DialogOptionsRenderingInfo functions and properties
- DrawingSurface functions and properties
- DynamicSprite functions and properties
- File functions and properties
- Game / Global functions
- GUI functions and properties
- GUI control functions and properties
- GUI Button functions and properties
- GUI InvWindow functions and properties
- GUI Label functions and properties
- GUI List Box functions and properties
- GUI Slider properties
- GUI Text Box functions and properties
- Hotspot functions and properties
- Inventory item functions and properties
- Maths functions and properties
- Mouse functions and properties
- Multimedia functions
- Object functions and properties
- Overlay functions and properties
- Palette functions
- Parser functions
- Region functions and properties
- Room functions
- Screen functions
- Speech functions and properties
- String functions
- System functions and properties
- Text display / Speech functions
- ViewFrame functions and properties
Working on Legacy games
Upgrading from a previous version
- Upgrading to AGS 2.7
- Upgrading to AGS 2.71
- Upgrading to AGS 3.0
- Upgrading to AGS 3.1
- Upgrading to AGS 3.2
- Upgrading to AGS 3.3
- Upgrading to AGS 3.3.5
- Upgrading to AGS 3.4
- Upgrading to AGS 3.4.1
Legal Notice
Getting in touch