Difference between revisions of "Cross Script Variables"
Jump to navigation
Jump to search
Simplified the beginning and took out some unnecessary information.
imported>Bruneauinfo m (Get Script Variable moved to Cross Script Variables: Renaming the page and putting a link to it under scripting basics.) |
imported>Bruneauinfo (Simplified the beginning and took out some unnecessary information.) |
||
Line 1: | Line 1: | ||
A time may come when you will wish to have a repository to store variable values that can be read from and written to by any script. This article addresses a basic method for not only storing and retrieving non-float numeric values, but object references as well. This could prove very handy when creating dynamic game scenarios. | |||
== The Basics == | == The Basics == | ||
Line 7: | Line 5: | ||
A scenario for creating and testing this type of functionality includes at least three features: | A scenario for creating and testing this type of functionality includes at least three features: | ||
1 - A script that acts as the database for storing values. In this article | 1 - A script that acts as the database for storing values. In this article a Quest Script will be used to demonstrate this. | ||
2 - A script that writes a value to one of the variables in the "database" Quest script when it is activated. | 2 - A script that writes a value to one of the variables in the "database" Quest script when it is activated. | ||
Line 17: | Line 15: | ||
=== The Quest Script === | === The Quest Script === | ||
The quest script acts | The quest script acts sort of like a very basic database. The next two scripts will demonstrate the command syntax for reading and writing to the quest script's variables from other scripts. | ||
The script: | The script: | ||
Line 41: | Line 39: | ||
Make sure you set the Script Type as "Quest" in the script editor window and then save your script. | Make sure you set the Script Type as "Quest" in the script editor window and then save your script. | ||
The script is very simple. You just declare all the variables you need for storing values. | The script is very simple. You just declare all the variables you need for storing values. | ||
====Notes==== | ====Notes==== | ||
Line 49: | Line 47: | ||
*The variable names listed in the script can be named whatever you like - preferably something meaningful to their purpose. | *The variable names listed in the script can be named whatever you like - preferably something meaningful to their purpose. | ||
*You must declare a variable in the quest script BEFORE you can reference them in the read/write scripts described below. If you attempt to code your read/write commands and the variable has not yet been declared in the quest script you will receive a compiling error in your read/write script. (''specifically this error message will state that your variable is an unknown variable or command even though you have declared the variable already within the read/write script.'') | *You must declare a variable in the quest script and compile it BEFORE you can reference them in the read/write scripts described below. If you attempt to code your read/write commands and the variable has not yet been declared in the quest script you will receive a compiling error in your read/write script. (''specifically this error message will state that your variable is an unknown variable or command even though you have declared the variable already within the read/write script.'') | ||