Jump to content

Access variable from other script


Recommended Posts

There is a quite a bit online about how to do this but I just can't make it work. Apparently I have to turn a variable into a property?

 

So please, some example code for the following:

 

script_1 - has the variables in it that other scripts will use

 

script_2 - will use the variables from script_1

 

i currently have something like

 

in script_2:

dz_mcm_undressing_script property dz_mcm auto

 

and in script_1 (dz_mcm_undressing_script):

bool property disrobes auto

 

according to what I've read this should mean that in script_2 I can use:

dz_mcm.disrobes

to access the disrobes variable in script1

 

for info script_1 is intended to be a mcm menu and there will more than one mod that will access the same menu variables.

 

Now using this format I can compile my actual scripts, but the second script never acknowledges the value of 'disrobes' as being anything other than false, even if I assign it true in script_1.

The form dz_mcm.disrobes is accepted when compiling script_2 but when the mcm menu changes (script_1) the value of 'disrobes'; dz_mcm.disrobes doesn't change.

 

I've read that I need to attach both scripts to the same object, if so what about the fact that one script is already attached to a trigger box and the mcm script (script_1) is attached to a quest (as per mcm menu instructions)?

 

Thanks in advance

 

diziet

Link to comment
Share on other sites

The scripts do not need to be attached to the same object. If they did then my Random Mining MCM mod would not work. I access the MCM script to get the player selected values in order to modify the ore vein script's behavior.

 

The way you have described your set up, it should work. Perhaps posting script 2's code will help shed some light. There could be some logic issues preventing the script from executing as desired even if the value is being properly updated.

Link to comment
Share on other sites

Okay, I'll post the two scripts here, they are my first attampts at writing scripts and one borrows a lot from someone else, first the mcm menu script (alll mine), note it's full of commented debugs and attempts to get the value of 'disrobes' displayed by the mcm menu - which in fact worked and gave the expected values!

 

 

  Reveal hidden contents

 

 

then the script that needs to use variables, note all I've tried to do so far is get the variable recognised by the script (line 53), the logic using the variable after that has yet to be written:

 

 

  Reveal hidden contents

 

 

this script also full of commented fragments:)

 

the scond script is attached to a trigger box and the first toa quest as described in the mcm instructions

 

diziet

Link to comment
Share on other sites

Change that line 53 in your second script to this.

	If mcm.disrobes == True
		debug.MessageBox("Disrobes variable from MCM script is true")
	Else
		debug.messagebox("Disrobes variable from MCM script is false")
	EndIf

Basically, forcing papyrus to get the variable value and compare it to a known quantity.

 

Did you fill the property for the script with the quest that has the target script attached? If not, that would explain why the variable fails to update.

Link to comment
Share on other sites

  On 12/19/2019 at 11:14 PM, IsharaMeradin said:

 

Did you fill the property for the script with the quest that has the target script attached? If not, that would explain why the variable fails to update.

Is this what you mean?

 

the quest name is dz_mcm for the mcm menu.

I've done this and altered the script as suggested, but still no joy, the message box still says the variable is false,

 

diziet

Link to comment
Share on other sites

  On 12/20/2019 at 2:54 AM, IsharaMeradin said:

Are you testing on a new game? I can see some scenarios where it might not work if your testing is not done on a new game or a save that has not had any part of the mod in question loaded yet.

 

Otherwise, I am at a loss as to the reason why it is not working for you.

I'm testing on a save that has never has this mcm in it, or the mod that the menu is intended for either; that mod I already wrote, I just want to be clever and add an mcm menu to it!

I'll mention that I'm creating a new esp for the mcm stuff, though the scripts from the exisitng mod are being edited to recognise the mcm variables. Is this wrong? Should the mcm menu be in the main mod? Currently my mod has most of its functionality without skse and I was hoping to make the mcm menu a simple add-on.

 

The save is one that I downloaded from nexus especially for the purpose of modding:)

Link to comment
Share on other sites

That would be the issue. By having two separate plugins, you have to make the one being referenced a parent master. Otherwise, any referencing being done will not work. Having your MCM as a parent master ruins the "simple add-on" aspect.

 

If you really want the MCM to be a separate plugin, here is your solution:

  • Create MCM script in its plugin

  • Make the following changes to your script(s) that are referencing variables / functions on the MCM script.

  • Ditch the property that is pointing to the MCM quest script

  • Add a local variable that you will use for the MCM script

  • Use GetFormFromFile to obtain the quest from your MCM plugin and cast it into the script and assign it to the local variable


 

Example code taken from my Random Mining MCM mod.

 

  Reveal hidden contents

 

 

 

Otherwise, just update the mod's initial plugin to have the MCM. There is nothing wrong with having two files available on your mod page. One with MCM and one without.

Link to comment
Share on other sites

  • 3 weeks later...
  On 12/20/2019 at 10:23 PM, dizietemblesssma said:

Okay, this is interesting stuff thankyou!

I'll be playing and testing for a while....

 

I may be back :smile:

 

diziet

Well I am back!

 

First off I managed to get the variable access from another scrip working, but only when both scripts are in the same esp.

Which is a problem for my mods, since each can be used individually; if I put an mcm quest in their esp, using two or more results in the mcm menu being repeated, and I only want one mcm menu.

I tried putting the mcm quest in a separate esp and making that a master of the other mods, I also tried putting my custom spell in that master mod to avoid the ugliness of duplicate spells (though that didn't seem to cause a problem).

 

I get the following error i papyrus.0.log:

Error: Property dz_naked_spell_ver2 on script dz_skse_ver2_nakedactivator attached to (0E005905) cannot be bound because <nullptr form> (0E000D62) is not the right type

 

this is with just the spell in the master mod, with the mcm quest in the master mod I get extra similar errors.

 

All the properties of the dz_skse_ver2_nakedactivator script are filled in via the creation kit, including "spell property dz_naked_spell_ver2 auto"

 

Is it not possible for a mod to use custom spells in other mods? D I have to reference them in a different way?

 

edit:

master mod has a spell made from the following scripts:

 

  Reveal hidden contents

 

which provides the magic effect used by the spell

 

 

  Reveal hidden contents

 

 

which is attached to a trigger box, the trigger box being in an individual mod, the intent is to have multiple esps with trigger boxes that players can use as wished and all use the spell in the master mod, and eventually all access the mcm menu variables in the master mod - that version of the script not shown.

 

 

diziet

Link to comment
Share on other sites

  • Recently Browsing   0 members

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