-
Notifications
You must be signed in to change notification settings - Fork 0
ImportingFunctionsAndVariables
Functions and variables declared in script A could be used in script B if two conditions are met:
- Script B is located below script A in the list of scripts;
- They are correctly exported/imported.
NOTE: Room and Dialog scripts can use functions and variables from all the regular script modules, but not from other rooms or dialogs.
All script functions are exported automatically, so they only need an import declaration to let other scripts know that they exist. This is done by declaring a function with an import keyword somewhere where script B can "see" it. The best practice is to place them in script A's header.
For example, suppose you have following function in script A:
function ScriptAFunction(int param1, int param2)
{
// some actions here
}
Then import declaration in the script A header will looks like:
import function ScriptAFunction(int param1, int param2);
The name, type and arguments of the function must be the same ofcourse, otherwise there will be errors either during compilation or at runtime.
Script variables are not exported by default, so that has to be done explicitly inside the script which has them declared, using export keyword.
Suppose you have following declaration in the script A:
int public_variable;
and you want to export this to be used in other scripts, all you do is put following statement inside the same script:
export public_variable;
And then declare variable's import for other scripts to see, presumably in the script A header:
import int public_variable;
The name and type must match the script's variable.
To put this simply, the import declaration lets other scripts see this variable, and the export command actually connects existing variable to that declaration.
NOTE: AGS Editor has a special menu "Global Variables" meant for easier creation of public variables which could be accessible everywhere. This may be a better alternative for beginners, as it takes care of all this import/export stuff behind the scenes.
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