Difference between revisions of "Cross Script Variables"
no edit summary
imported>Bruneauinfo |
imported>Bruneauinfo |
||
|
{{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
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.
=== 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
The script:
*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'''''.)
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.
| |||