Difference between revisions of "Cross Script Variables"

818 bytes removed ,  12:58, 30 December 2010
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.)
 
It is possible aA time willmay come in writing a script when you will wish to have a repository to store variable values that can be read from and written to by any script. Fortunately this is possible. 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. ▼
If you are looking for a way to get the value of a variable from one script running on one object to a script running on another object I imagine you may have entered the above article name or something similar to it in your search for an answer. As you first begin writing mods you will probably notice that Oblivion assumes the only variables that should be universally accessible are the Global variables. This would not be a terrible thing except that all Global variables are treated as ''floats''. (See [[Floating Point]].)
 
▲It is possible a time will come in writing a script when you will wish to have a repository to store variable values that can be read from and written to by any script. Fortunately this is possible. 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 ==
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 thea Quest Script method will be demonstrated. (One might wantused to read over the article [[Quest scripts]] to get familiar with the source ofdemonstrate this. idea.)
 
2 - A script that writes a value to one of the variables in the "database" Quest script when it is activated.
=== The Quest Script ===
 
The quest script acts assort of like a very basic database. The next two scripts will demonstrate the command syntax for reading and writing to athe quest scriptsscript's variables from externalother scripts.
 
The 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. Too bad there isn't a way to create variables dynamically as with an SQL database. Still, this functionality is much better than nothing at all!
 
====Notes====
*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 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.'')
 
 
Anonymous user