Jump to content

How to pass data between scripts?


gigantibyte

Recommended Posts

In the old days, I'd just create some quest variables which were easy enough to manipulate from other scripts. With Papyrus I'm ignorant. Is there a tutorial on this subject somewhere? Specifically, I'd like to obtain and save an Object Reference in one script, then use that object reference in another script.

 

Also, for debugging purposes, sometimes it would be useful to see the contents (like the form ID) of an object reference variable in a debug.messagebox. Is that possible?

Link to comment
Share on other sites

Yes for object references either expose the variable as a script property or use a quest alias to share it.

 

Be aware that Object References are made persistent when they have direct pointers to them from scripts or quests, so best to clear then when finished.

 

An example of two scripts A and B attached to a quest:

ScriptName myQuestScriptA extends Quest 

ObjectReference Property myObjectA Auto ;not Const so it can be cleared

Event OnQuestInit()
   Debug.Trace("myQuestScriptA myObjectA " + myObjectA)
EndEvent
ScriptName myQuestScriptB extends Quest 

Quest Property myQuest Auto Const Mandatory

Event OnQuestInit()
   Debug.Trace("myQuestScriptB myObjectA " + (myQuest as myQuestScriptA).myObjectA)
   (myQuest as myQuestScriptA).myObjectA = None ;clear it to release.
EndEvent 
Link to comment
Share on other sites

It is called CASTING or type conversion, best look it up.

 

I am not aware on any specific tutorials, the BEST way to learn Creation Kit and scripting and how it all hangs together is to start by creating a fetch quest. You probably dont want to make a fecth quest, but it really is the best way to learn and there are plenty of written and youtube tutorials dpemnding if you want the WHY explaining or just monkey-see-monkey-do button pressing.

Link to comment
Share on other sites

 

Is there a name for this wizardry?

It is called CASTING

Of course that's what's it called! :laugh: Turns out, casting was the last little bit I needed to get the fundamentals of my mod working. In the end, no quasi global exposed variable wannabes were required, but they were useful for debugging,

 

 

start by creating a fetch quest

 

Thanks for the advice! If I ever publish my little mod, a fetch quest might be more interesting than just adding the utility to the player's inventory.

Link to comment
Share on other sites

The casting conversion in papyrus is super flexible if you understand the underlying OO class inheritances (yeah, like who actually bothers when breasts need animating).

 

Example: you can even avoid the quest property as its the script parent, so;

 

(myQuest as myQuestScriptA).myObjectA

 

can become

 

((Self as Quest) as myQuestScriptA).myObjectA

Link to comment
Share on other sites

Casting does seem to be a good alternative to having several different functions tor type conversions, like string(integer).

 

When my mod is finalized, may I post the scripts here for review? The first script is just for adding a tool to inventory, and the other two are fairly short. Initial tests are producing the desired results, but there are any number of things I could be doing wrong.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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