This wiki is a copy of the original Oblivion CS wiki created and maintained by the UESP.net. See CSwiki:Copy Notice for more info.

Difference between revisions of "Cross Script Variables"

Jump to navigation Jump to search
1,318 bytes added ,  23:52, 22 December 2010
no edit summary
imported>Bruneauinfo
imported>Bruneauinfo
Line 1: Line 1:
{{Discussion}}
{{Discussion}}


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 can imagine you may have entered the above article name in your search or something similar to it. As you first begin writing mods you may notice that the scripting language of Oblivion assumes the only universally accessible variables should be Global variables. This would not be terrible except that all Global variables are treated as ''floats''. (See [[Floating Point]].)
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 in that can be read from and written to by any script. Fortunately this is possible. This article addresses a 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 in that can be read from and written to by any script. Fortunately this is possible. This article addresses a 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.  
Line 19: Line 19:
=== The Quest Script ===
=== The Quest Script ===


The quest script acts as a database. Unfortunately Oblivion doesn't provide the powerful database features you would find in an SQL database service. Still, it does provide the quest script where the most basic database functionality can be achieved - a command syntax for reading and writing to its variables from outside of the script from external scripts.   
The quest script acts as a database. Unfortunately Oblivion doesn't provide the powerful database features you would find in an SQL database service. Still, it does provide the quest script where the most basic database functionality can be achieved - a command syntax for reading and writing to its variables from external scripts.   


The script:
The script:
Line 53: Line 53:


*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 do not need to start the quest! The values within the quest can be written to and read from even if it is never started. And anyway it saves on CPU cycles.


The next part of this step is to create a quest. You can read up on the steps for creating a quest on the wiki. Just keep in mind that the only setting needed for creating this functionality is the "Script" setting under the ''Quest Data'' tab. Once you create and name your quest select your quest script from above under the ''script setting'' for the quest. (''For these examples the quest is named '''MyQuest'''''.)
The next part of this step is to create a quest. You can read up on the steps for creating a quest on the wiki. Just keep in mind that the only setting needed for creating this functionality is the "Script" setting under the ''Quest Data'' tab. Once you create and name your quest select your quest script from above under the ''script setting'' for the quest. (''For these examples the quest is named '''MyQuest'''''.)
Line 125: Line 127:


Again the quotes around the name of your quest are critical for this to work. Also, if you use this script exactly as written the message box will show the name of your reference rather than the reference. See [[MessageBoxEx]] for more. But the reference value is there and ready for use.  
Again the quotes around the name of your quest are critical for this to work. Also, if you use this script exactly as written the message box will show the name of your reference rather than the reference. See [[MessageBoxEx]] for more. But the reference value is there and ready for use.  
== Practical Applications ==
So one might be wondering where functionality like this might prove useful. If you're just writing simple mods this type of functionality may seem a bit excessive. But take as an example a mod where the player will only belong to one faction (''other than the player faction of course.'') Oblivion is designed assuming the player might be a member of many factions. But what if your mod required and only allowed the player be a member of one faction? And what if the relationships between factions was critical to the playing out of your mod? In this situation you might find yourself writing scripts where you would have to do a long series of repetitive checks like these:
if (player.GetInFaction ''FactionRef'' == 1)
These checks would go through each possible faction and could start to get a little hard on the eyes and make trouble shooting scripts a bit more difficult.
Using the functionality discussed in this article you could store the player's faction in a quest script and just retrieve it with a few lines of code! If the player's faction did switch you would just code so the value is changed in the quest script. 




Anonymous user

Navigation menu