Jump to content

Calling function from another script


Recommended Posts

Hi,

I have succesfully referenced variables etc. in one script from another script in the past, but I've noticed that it has always been a script attached to a quest (MCM quest) that was referenced as a property in the CK.

I've noticed this because I can't reverse this, I can't write:

script1 property sc auto

in my script2 when script2 is the quest script, and script1 is just another script that I compiled.

 

So I made a dummy quest and attached script1 to it, but still in the CK I cannot choose it as property for script 2.

 

What would script1 need to be attached to for the CK to offer it as an option when filling properties?

 

 

diziet

 

 

edit: sudden thought, is it whether the script1 is referenced by something in the same plugin that has script2 attached?

Link to comment
Share on other sites

I'm probably misunderstanding the question but here goes..

 

Script1 needs to be the exact name of the quest script.

 

Example.

 

Say your quest script is named TeleportWhiterunQuestScript, the script property needs to be:

TeleportWhiterunQuestScript property TWQScript auto

You can do it the opposite way as well through casting and assignment.

Quest property TeleportWhiterunQuest auto
 
 
Event OnInit()
 
    TeleportWhiterunQuestScript TWQScript = TeleportWhiterunQuest as TeleportWhiterunQuestScript
 
    TWQScript.SomeFunctionItHas()

EndEvent

This method is not exclusive to quest objects and its scripts, this works for all objects and their scripts, including ActiveMagicEffect scripts(those are the least useful through since by design they don't stick around).

Edited by Rasikko
Link to comment
Share on other sites

Yes, to reference another script, they both have to be attached to something in the same plugin. To get around that, you can use the GetFormFromFile function in an Event: https://www.creationkit.com/index.php?title=GetFormFromFile_-_Game

 

Example:

 

TestModQuestScript ScriptRef

Event OnInit()
    ScriptRef = ((Game.GetFormFromFile(0x02000D62, "TestMod.esp") As Quest) as TestModQuestScript)
    Utility.Wait(1) 
    ScriptRef.SomeFunction()
EndEvent

The form ID you use in GetFormFromFile should be the form the script you're trying to reference is attached to in the other plugin. Change TestModQuestScript to the name of the script you're trying to access.

Link to comment
Share on other sites

Thanks for this.:)

 

 

The form ID you use in GetFormFromFile should be the form the script you're trying to reference is attached to in the other plugin.

Woudn't the formid depend on load order?

 

When compling a script the plugin with the other script to be referenced needs to be loaded in the CK? Is this somehow automagically dealt with by the game engine?

 

 

diziet

Link to comment
Share on other sites

Thanks for this. :smile:

 

 

The form ID you use in GetFormFromFile should be the form the script you're trying to reference is attached to in the other plugin.

Woudn't the formid depend on load order?

 

When compling a script the plugin with the other script to be referenced needs to be loaded in the CK? Is this somehow automagically dealt with by the game engine?

 

 

diziet

No. It is not dependent on load order. The ID used is relative to the supplied plugin and thus the first two digits will always be 00.

 

I do not recall if the PSC needs to be present or not when using GetFormFromFile. All my uses had them present anyway. Sure way to find out would be to try compiling without said PSC present, if the compiler complains then you need it. As far as the game goes, if the supplied plugin is not present and papyrus logging is on there will be a harmless notice written. This means that you should always do a sanity check to ensure that the variable intended to hold the result of GetFormFromFile is not null.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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