Jump to content

Accessing data from other mod without making it a master


HautdenLukas

Recommended Posts

Let's say I have two mods (Mod1.esm and Mod2.esp). Mod2 is supposed to query a global variable from Mod1, but I don't want to add Mod1 as a master to Mod2. My idea was to use something like this:

    set tempref to GetFormFromMod "Mod1.esm" "04FC1B"

Now I have the pointer to that global variable, but how do I get the actual content? When I do:

    PrintToConsole "tempref is %i %.0f" tempref tempref

I get:

tempref is 0404FC1B 0

although the global variable has a value of 1. At least the pointer is correct.

Link to comment
Share on other sites

If it really is a global variable in the other mod, then you just reference the variable. Here's an example from my mod Oblivion XP Update:

scn ObXPfnSDRVersionCheck

Short SDRversion

Begin Function{}

	SetFunctionValue 0
	If (IsModLoaded "SDR.esm")
		let SDRversion := GetGS iSDRsVersion
		if (ObXPMain.debugMode)
			scribe "SDR Version: %.0f" SDRversion
		endif
		; requires 8.2.1 b3 at the minimum
		If (SDRversion >= 8213)
			; code to check that SDR's poison script is active
			if (GetGS iSDRsApplyPoisonBugFix == 1)
				; disable Ob XP poison fix
				; SDR will dispatch an sdrPoisonKill event
				let ObXPSettings.enablePoisonFix := 0
			endif
			SetFunctionValue 1
		Endif
	Endif

End

saebel created a game setting for the version number, so I retrieve it by using getGameSetting or getGS for short.

If the form is a quest, then you need to reference the specific quest variable.

Link to comment
Share on other sites

In fact I faced same problem and my question about it on forum was unanswered too. With OBSE I came to this:

scn RomRAccessQSTScript
ref form
float value
short present
short valid

begin GameMode
	if GetGameRestarted || GetGameLoaded
		set form to 0
		set valid to 0
		if IsModLoaded "MagicTorch.esp"
			set present to 1
		else
			set present to 0
		endif
		if present != 0
			let form := GetFormFromMod "MagicTorch.esp" 6a01 ;form for MagicTorchZ global
			if form != 0
				if GetObjectType form == 4 ;is it global?
					set valid to 1
				endif
			endif
		endif
	endif

	if valid != 0 
		print "MagicTorchZ global variable is present."
		let value := GetGlobalValue form
		print "Its value is: "+$value+"."
	endif
end

This example quest script will periodically print value of MagicTorchZ global variable defined in my Magic Torch mod into console.

Link to comment
Share on other sites

@LenaWolfBravil: Yes, I was quite suprised when I found this function working in script too. I tested script before posting and it works as it should, reacting also to change of global's value. Still only for reading though. 

Link to comment
Share on other sites

1 hour ago, RomanR said:

@LenaWolfBravil: Yes, I was quite suprised when I found this function working in script too. I tested script before posting and it works as it should, reacting also to change of global's value. Still only for reading though. 

This is good to know, thanks! I'll keep it in mind. 🙂

Link to comment
Share on other sites

?? I don't know what you guys are referring to. They are saying that they've made the function available only as a condition function.

To quote that page:

Quote

In scripts, you can simply use the global variable name directly:

So you can access the values of global variables directly - you don't have to use GetGlobalValue.

All the variables listed here are accessed by simply using the names.

There's also GetQuestVariable. Once again, you don't need to use the function. That's what I was referring to in my response.

@HautdenLukas, you check if the mod is loaded. If it is, then you reference the variable directly. What's the name of the global variable? You would get the value by simply using the name. If you use GetFormFromMod, then you need to use GetGlobalValue. Basically when you retrieve the form, you are getting a class. A global variable won't have many attributes, but you can't just use the reference to get the value. A form like character has a lot of attributes, so trying to get a value doesn't make any sense. You know what you're after, but the game only knows it's a form and treats them all the same way.

I'm a bit rusty, so I dug up a script that I had on hand. Anyway I think we got to the point and Roman and Lena have given you some good links. I also think it was a lot clearer in the actual CS wiki, which is still offline...

Edit: Here’s what I mean by class

Edited by AndalayBay
explanation of term
Link to comment
Share on other sites

"... you check if the mod is loaded. If it is, then you reference the variable directly. What's the name of the global variable? You would get the value by simply using the name."

Well, Construction Set (at least original one) will create problem on saving - if you use a name from another mod and this mod is a regular one, it will not save it onto parent masters list. This will create problem on runtime, as Oblivion will not run such script. Making the source mod master (by using TES4Gecko for example) will work, but such file must be always present. In this case there's no need to check it for load - Oblivion will load it itself and if one of master files is missing, it will quit to Windows after showing logos.

And that's why the original poster asked for alternative way, to avoid mentioned problems.

Link to comment
Share on other sites

59 minutes ago, RomanR said:

"... you check if the mod is loaded. If it is, then you reference the variable directly. What's the name of the global variable? You would get the value by simply using the name."

Well, Construction Set (at least original one) will create problem on saving - if you use a name from another mod and this mod is a regular one, it will not save it onto parent masters list. This will create problem on runtime, as Oblivion will not run such script. Making the source mod master (by using TES4Gecko for example) will work, but such file must be always present. In this case there's no need to check it for load - Oblivion will load it itself and if one of master files is missing, it will quit to Windows after showing logos.

And that's why the original poster asked for alternative way, to avoid mentioned problems.

The functions you are using to get the references are OBSE functions, so it will require OBSE. Other than that, there is no dependency. The mod you are referencing does not need to be a master. Saebel's Sneaking Detection Recalibrated is not a requirement for Oblivion XP Update, nor are any of the other mods it references.

It's quite possible this is another bug that the Construction Set Extender fixes. I wouldn't know. I haven't used the regular CS with OBSE since the CSE was released.

Link to comment
Share on other sites

On 10/29/2024 at 11:50 PM, AndalayBay said:

?? I don't know what you guys are referring to. They are saying that they've made the function available only as a condition function.

This is one of the situations when the Wiki may not be correct.

We are talking about a global variable that is mod-added, so it is not going to be on any list of global variables on the Wiki, since those are from Oblivion.esm only.

I would suggest to the OP, try using GetGlobalValue as in the @RomanR example. This may just do the trick. 🙂 I didn't think myself that you could feasibly access the value of a global variable when you only had a generic reference that you got with GetFormFromMod, as @AndalayBay pointed out. If GetGlobalValue works for you there, you're all set. If it doesn't work... I would try to find a different way to do it. 🙂 I have used both quest variables and script variables that I got from another mod with GetFormFromMod - you access them with GetQuestVariable and GetScriptVariable, respectively. So that works, but global values may be treated differently.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...