Jump to content

Correct way to call a property from another script?


Fredas

Recommended Posts

Posted

This should be quick and easy.  Let's say I'm trying to ping the property PlayerIsVampire from Skyrim's own PlayerVampireQuestScript.

PlayerVampireQuest = Game.GetFormFromFile(0x000EAFD5, "Skyrim.esm") as PlayerVampireQuestScript
debug.notification("PlayerIsVampire: " + PlayerVampireQuest.PlayerIsVampire)

Compile result: "PlayerIsVampire is not a property on script form or one of its parents".

 
Why is it lying to me? ;p  I can see quite clearly that it is a property.  What'd I mess up?  (Please don't suggest making PlayerVampireQuest a property because there's a good reason why that's not an option in this case.)
 
Posted

PlayerVampireQuest needs to be defined as the script.

Quest PlayerVampireQuest = Game.GetFormFromFile(0x000EAFD5, "Skyrim.esm") as PlayerVampireQuestScript

Would make the variable a Quest variable, and thus only have access to the functions/properties of the Quest script and it's parents. Because PlayerVampireQuestScript extends the quest script, it seen as compatible and casting it as PlayerVampireQuestScript works, but it gets cast again down a level to match with the Quest type declaration. 

PlayerVampireQuestScript PlayerVampireQuest = Game.GetFormFromFile(0x000EAFD5, "Skyrim.esm") as PlayerVampireQuestScript

Would make the variable a PlayerVampireQuestScript variable, and thus only have access to the functions/properties of the PlayerVampireQuestScript script and it's parents

PlayerVampireQuestScript PlayerVampireQuest = Game.GetFormFromFile(0x000EAFD5, "Skyrim.esm") as PlayerVampireQuestScript
debug.notification("PlayerIsVampire: " + PlayerVampireQuest.PlayerIsVampire)

Compiles without issue.

Posted

Also if SKSE dependence isn't an issue for you, I'd suggest Quest.GetQuest() instead of Game.GetFormFromFile()

 

It's a matter of preference, but it's a helluva lot easier and an applicable option in this scenario.

PlayerVampireQuestScript PlayerVampireQuest = Quest.GetQuest("PlayerVampireQuest") as PlayerVampireQuestScript
; // Versus
PlayerVampireQuestScript PlayerVampireQuest = Game.GetFormFromFile(0x000EAFD5, "Skyrim.esm") as PlayerVampireQuestScript
Posted

Also if SKSE dependence isn't an issue for you, I'd suggest Quest.GetQuest() instead of Game.GetFormFromFile()

 

It's a matter of preference, but it's a helluva lot easier and an applicable option in this scenario.

PlayerVampireQuestScript PlayerVampireQuest = Quest.GetQuest("PlayerVampireQuest") as PlayerVampireQuestScript
; // Versus
PlayerVampireQuestScript PlayerVampireQuest = Game.GetFormFromFile(0x000EAFD5, "Skyrim.esm") as PlayerVampireQuestScript

 

Thanks.  It does compile and that's another hurdle cleared.

 

I made the foolish assumption of expecting this functionality to operate universally, but it's proving not to be the case.  What are the options when the script/properties in question are part of something that isn't a quest?  In my current case, the script is attached to an activemagiceffect.  Probably because of this, the above syntax doesn't happily compile.  (Obviously the Quest.GetQuest is off the menu, so I'm referring to the Game.GetFormFromFile approach.)

Posted

Edit: If it helps or matters, here is an example of me trying to define a script variable from a script that's attached to a magic effect rather than a quest:

 

 

rnd_checkneedsscript PM_CheckNeedsScript
 
PM_CheckNeedsScript = Game.GetFormFromFile(0x0002E0C9, "RealisticNeedsandDiseases.esp") as rnd_checkneedsscript

 

And the error returned is "cannot cast a form to a rnd_checkneedsscript, types are incompatible".  Same methods as in the above vampire quest example; only difference is the script being attached to something besides a quest.

 

Posted

Gonna guess at this point that it's not possible, since I can't find a single working example anywhere.

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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