Accessing Global Variables from Other Mods in Scripts?

Post » Sun Nov 18, 2012 6:28 am

Does anyone how know to write a script which can access the value of a global variable provided by another mod? For example Mod A has global variable called _sycUninstallCCO set to "0" while Mod B has the same _sycUninstallCCO set to "1", how do I write a script in Mod A to access the value of _sycUninstallCCO in Mod B?

I tried declaring the global variable as a property and then calling GetValue() on it (http://www.creationkit.com/Global#Scripting), but for some reason the script from Mod A always access the value of _sycUninstallCCO from Mod A ("0"), instead of the value from Mod B ("1"). Funny thing is that when I type the showvars command in the console _sycUninstallCCO == 1.

Any help would be appreciated. Here is my script from ModA:
ScriptName _sycMaintenanceRefAliasScript extends ReferenceAlias; This script must be attached to the Player Alias defined in the Quest Alias tab of a Quest; Declare Variables and Properties_sycMainQuestScript Property _sycMainQuest Auto ; This points the property to the appropriate quest scriptGlobalVariable Property _sycUninstallCCO AutoFloat fUninstallCCOEvent OnInit()Debug.MessageBox("_sycMaintenanceRefAliasScript OnInit Fired")GoToState("Maintenance")EndEventEvent OnPlayerLoadGame()Debug.MessageBox("_sycMaintenanceRefAliasScript OnPlayerLoadGame Fired")GoToState("Maintenance")EndEventState MaintenanceEvent OnBeginState()  fUninstallCCO = _sycUninstallCCO.GetValue()  Debug.MessageBox("fUninstallCCO = " + fUninstallCCO)  If fUninstallCCO == 1   Debug.MessageBox("Uninstall Successful")   _sycMainQuest.UninstallCCO()  Else   _sycMainQuest.VersionControl()   _sycMainQuest.Maintenance()  EndIfEndEventEndState
User avatar
Avril Louise
 
Posts: 3408
Joined: Thu Jun 15, 2006 10:37 pm

Post » Sun Nov 18, 2012 12:52 pm

Some time ago, Bethesda did announce a new (experimental?) feature, whereby one plugin could directly access data from another plugin through a special function, that would have to refer to the other plugin by its file name. Unfortunately, I can't recall what the thread was where that was discussed. Perhaps someone else might remember it better or you could try searching for it. It does exist.
User avatar
OTTO
 
Posts: 3367
Joined: Thu May 17, 2007 6:22 pm

Post » Sun Nov 18, 2012 1:28 pm

experimental?
It's in since 1.6 and, most likely, here to stay.

Topoic: If the GLOB's FormID is XX000420 and it's in ModA.esp, ModB,esp can access it with http://www.creationkit.com/GetFormFromFile_-_Game.

Global ModAGlobal = Game.GetFormFromFile(0x00000420, "ModA.esp") As Global
ModA.esp can do the same with a form in ModB.esp even if ModA.esp is loading first since it all happens at runtime w/o any master dependencies.
User avatar
jeremey wisor
 
Posts: 3458
Joined: Mon Oct 22, 2007 5:30 pm

Post » Sun Nov 18, 2012 9:29 am

By the way, I don't know if this is still relevant, or has ever been, but the initial discussion I saw about that feature left me with an impression, that there might be a twist to it. Namely, that it might require loading the game twice or something like that to function reliably. And that was something that the developer participating in the discussion pointed out, if I remember correctly.

Anyway, I don't know if that really is so, as I have never tested it, but in case the function misbehaves, reloading might be something to try.
User avatar
Bee Baby
 
Posts: 3450
Joined: Sun Jun 18, 2006 4:47 am

Post » Sun Nov 18, 2012 4:49 pm

It works right off the bat. It's probably the http://www.creationkit.com/OnPlayerLoadGame_-_Actor event which was also introduced with 1.6 you're thinking of?
User avatar
Tamika Jett
 
Posts: 3301
Joined: Wed Jun 06, 2007 3:44 am

Post » Sun Nov 18, 2012 4:45 pm

Could well be. I simply remember that sticking to my mind from some discussion, because it sounded so odd at the moment. I would have thought that it might be related to this, but who knows? Anyway, reloading seems to be the trend these days on several fronts.

Edit:
Yes, on second thought, it is likely I have my recollections somehow mixed up.
User avatar
Jonathan Egan
 
Posts: 3432
Joined: Fri Jun 22, 2007 3:27 pm

Post » Sun Nov 18, 2012 7:13 am

Was probably that event they were speaking of 'cause GetFormFromFile, assuredly, will work even if it's a brand new save. That function rocks!
User avatar
rebecca moody
 
Posts: 3430
Joined: Mon Mar 05, 2007 3:01 pm

Post » Sun Nov 18, 2012 2:26 pm

This technic work only for read a value

Actor Property VariableName Auto


"Property" variables belong to one script but can be accessed by other scripts.

http://www.creationkit.com/Variables_and_Properties

To access it from another script first define a Property that refers to the script containing the Property you want to access:

PropertyScriptName Property myScript Auto


If the script containing the Property is a quest, first make a Property which you can fill with the quest ID. Fill this one manually in the CK so you can refer to the quest:
Quest Property myQuest Auto

Then do this in one of your Events/functions:

myScript = myQuest as PropertyScriptName


Here you make the myScript variable point to the script called PropertyScriptName of myQuest. Now you can address the property called VariableName by addressing it like this:

MyScript.VariableName

For write a values i use an onupdate

I assign the new value in the secondscript
Update the first script
The first script read the value from the second and write it
User avatar
Harry Leon
 
Posts: 3381
Joined: Tue Jun 12, 2007 3:53 am

Post » Sun Nov 18, 2012 5:43 am

Thank you! thank you! thank you! :biggrin:

@JustinOther: GetFormFromFile works perfectly, it is exactly what I need.

@shayologo: You answered my next question, I was just about to ask if it is possible to access a script's property in a different mod. Thank you for the detailed step-by-step explanation, that helped tremendously.
User avatar
Carlos Rojas
 
Posts: 3391
Joined: Thu Aug 16, 2007 11:19 am

Post » Sun Nov 18, 2012 2:51 am

This technic work only for read a value
GetFormFromFile can be used to set a property or value to the form in another plugin, enabling more than merely reading its value.

(Game.GetFormFromFile(0x00000420, "ModA.esp") As Global).SetValue(1.0)
...or ...
Global ModAGlobal = Game.GetFormFromFile(0x00000420, "ModA.esp") As GlobalModAGlobal.SetValue(1.0)
..will both change the other mod's global's value.
@JustinOther: GetFormFromFile works perfectly, it is exactly what I need.
NP :) That function is quite enabling.
User avatar
Kat Lehmann
 
Posts: 3409
Joined: Tue Jun 27, 2006 6:24 am


Return to V - Skyrim