Difference between revisions of "Cross Script Variables"

Jump to navigation Jump to search
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.)
 
Line 1: Line 1:
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]].)
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.  
 
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 ==
== 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 the Quest Script method will be demonstrated. (One might want to read over the article [[Quest scripts]] to get familiar with the source of this idea.)
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 as a very basic database. The next two scripts will demonstrate the command syntax for reading and writing to a quest scripts variables from external scripts.
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. 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!
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.'')




Anonymous user

Navigation menu