TripleSixes Posted August 1, 2017 Share Posted August 1, 2017 Preface: I am going to simplify my scripts to ease troubleshooting.I have script "A", which is used to declare properties that global functions in script "B" can use. Script "A": ScriptName rsAPI_Properties Extends Quest {Contains all the properties for rsAPI scripts} MiscObject Property myMiscObjectProperty Auto Script "B": ScriptName rsAPI_Functions Extends Quest Hidden {Contains all the functions for the rsAPI scripts} ;This function gets the forms from Script "A" rsAPI_Properties Function GetFrameworkProperties() Global return (Game.GetFormFromFile(0x294A97, "MyPlugin.esp") as Quest) as rsAPI_Properties EndFunction ;This function gets a specific form from Script "A" with the help of the above function. MiscObject Function GetMiscObject() Global return GetFrameworkProperties().myMiscObjectProperty EndFunction ;This function is an example of how I would like to handle the miscobject passed from Script "A" Function GivePlayerMiscObject(int howMany) Global Game.GetPlayer().AddItem((GetMiscObject()), howMany); I have tried declaring a MiscObject outside this command as well, but neither worked. EndFunction The second function in Script "B" is used to return a miscobject, but it only returns NONE. This way of obtaining a property from another script seems to only work for certain types of forms. The properties have been defined in the CK in Script "A".Any pointers papyrus wizards?p.s. The reason I am approaching it this way is because Script "A" and Script "B" are an API of sorts. I want to use a function in Script "B" that references properties in Script "A" after passing parameters directly from Script "C", which would utilize the third function in Script "B" like this: Script "C": ScriptName GivePlayerItem Extends Activator {Utilizes the rsAPI framework to give the player 2 MiscObjects} Event OnActivate(Actor akActionRef) rsAPI_Functions.GivePlayerMiscObject(2) EndEvent Has anyone had any luck returning a form aside from Globalvariables in this context? Link to comment Share on other sites More sharing options...
Lisselli Posted August 1, 2017 Share Posted August 1, 2017 (edited) Nevermind. Edited August 1, 2017 by Lisselli Link to comment Share on other sites More sharing options...
IsharaMeradin Posted August 1, 2017 Share Posted August 1, 2017 You may need a slight change. Pretty sure that you cannot have a script return as the result of a function. ScriptName rsAPI_Functions Extends Quest Hidden {Contains all the functions for the rsAPI scripts} rsAPI_Properties PropertyScript ;This function gets the forms from Script "A" rsAPI_Properties Function GetFrameworkProperties() Global PropertyScript = (Game.GetFormFromFile(0x00294A97, "MyPlugin.esp") as Quest) as rsAPI_Properties EndFunction ;This function gets a specific form from Script "A" with the help of the above function. MiscObject Function GetMiscObject() Global GetFrameworkProperties() return PropertyScript.myMiscObjectProperty EndFunction ;This function is an example of how I would like to handle the miscobject passed from Script "A" Function GivePlayerMiscObject(int howMany) Global Game.GetPlayer().AddItem((GetMiscObject()), howMany); I have tried declaring a MiscObject outside this command as well, but neither worked. EndFunction However, it may simply be that you do not have enough digits in your GetFormFromFile call. You are missing the leading zeros. It should be: 0x00294a970x tells Papyrus that it is a hex value00 is load order position and must be present. In this case, it is viewed from the perspective of the target plugin irregardless of any other loaded plugin. Thus it will always be 00.The last 6 digits are the object's editor ID number as found in the target plugin. I would test again with the corrected hex value before doing anything else. Link to comment Share on other sites More sharing options...
foamyesque Posted August 1, 2017 Share Posted August 1, 2017 I've used properties to pass all kinds of form information back and forth, ranging from ActiveMagicEffects (which don't even inherit from Form!) to Quests to custom extensions. That is probably not the problem. I think your issue is likely in the GetFrameworkProperties function; does it return correctly? Have you instrumented it or looked at a debug log? Link to comment Share on other sites More sharing options...
cdcooley Posted August 1, 2017 Share Posted August 1, 2017 It looks like those calls should all work. Yes, you can return any form type including those defined by scripts. Are you getting any errors in the Papyrus log?You can try adding some Debug.Trace lines to get a better idea of what exactly is failing. ScriptName rsAPI_Functions Extends Quest Hidden {Contains all the functions for the rsAPI scripts} ;This function gets the forms from Script "A" rsAPI_Properties Function GetFrameworkProperties() Global Form mp = Game.GetFormFromFile(0x294A97, "MyPlugin.esp") Debug.Trace("Form: " + mp) Debug.Trace("Quest: " + (mp as Quest)) Debug.Trace("Props: " + ((mp as Quest) as rsAPI_Properties)) return (Game.GetFormFromFile(0x294A97, "MyPlugin.esp") as Quest) as rsAPI_Properties EndFunction ;This function gets a specific form from Script "A" with the help of the above function. MiscObject Function GetMiscObject() Global Debug.Trace("FWP: " + GetFrameworkProperties()) Debug.Trace("MOP: " + GetFrameworkProperties().myMiscObjectProperty) return GetFrameworkProperties().myMiscObjectProperty EndFunction ;This function is an example of how I would like to handle the miscobject passed from Script "A" Function GivePlayerMiscObject(int howMany) Global Game.GetPlayer().AddItem((GetMiscObject()), howMany); I have tried declaring a MiscObject outside this command as well, but neither worked. EndFunction Link to comment Share on other sites More sharing options...
TripleSixes Posted August 1, 2017 Author Share Posted August 1, 2017 You may need a slight change. Pretty sure that you cannot have a script return as the result of a function. The quest that script "A" is attached to is the object being returned by GetFrameworkProperties(). This allows me to reach into the quest and get the properties. However, it may simply be that you do not have enough digits in your GetFormFromFile call. You are missing the leading zeros. It should be: 0x00294a97 0x tells Papyrus that it is a hex value 00 is load order position and must be present. In this case, it is viewed from the perspective of the target plugin irregardless of any other loaded plugin. Thus it will always be 00. The last 6 digits are the object's editor ID number as found in the target plugin. I would test again with the corrected hex value before doing anything else. I will most certainly try this, although I can return Globalvariables as it is right now anyways. Link to comment Share on other sites More sharing options...
TripleSixes Posted August 1, 2017 Author Share Posted August 1, 2017 I've used properties to pass all kinds of form information back and forth, ranging from ActiveMagicEffects (which don't even inherit from Form!) to Quests to custom extensions. That is probably not the problem. I think your issue is likely in the GetFrameworkProperties function; does it return correctly? Have you instrumented it or looked at a debug log? When I used this process to return Globalvariable objects, it works. When I try to return a MiscObject, it returns NONE instead. Very strange though I admit I should be running checks more often. Link to comment Share on other sites More sharing options...
TripleSixes Posted August 1, 2017 Author Share Posted August 1, 2017 (edited) It looks like those calls should all work. Yes, you can return any form type including those defined by scripts. Are you getting any errors in the Papyrus log?You can try adding some Debug.Trace lines to get a better idea of what exactly is failing. ScriptName rsAPI_Functions Extends Quest Hidden {Contains all the functions for the rsAPI scripts} ;This function gets the forms from Script "A" rsAPI_Properties Function GetFrameworkProperties() Global Form mp = Game.GetFormFromFile(0x294A97, "MyPlugin.esp") Debug.Trace("Form: " + mp) Debug.Trace("Quest: " + (mp as Quest)) Debug.Trace("Props: " + ((mp as Quest) as rsAPI_Properties)) return (Game.GetFormFromFile(0x294A97, "MyPlugin.esp") as Quest) as rsAPI_Properties EndFunction ;This function gets a specific form from Script "A" with the help of the above function. MiscObject Function GetMiscObject() Global Debug.Trace("FWP: " + GetFrameworkProperties()) Debug.Trace("MOP: " + GetFrameworkProperties().myMiscObjectProperty) return GetFrameworkProperties().myMiscObjectProperty EndFunction ;This function is an example of how I would like to handle the miscobject passed from Script "A" Function GivePlayerMiscObject(int howMany) Global Game.GetPlayer().AddItem((GetMiscObject()), howMany); I have tried declaring a MiscObject outside this command as well, but neither worked. EndFunction I will check the logs and get back to you. Edited August 1, 2017 by TripleSixes Link to comment Share on other sites More sharing options...
foamyesque Posted August 1, 2017 Share Posted August 1, 2017 I've used properties to pass all kinds of form information back and forth, ranging from ActiveMagicEffects (which don't even inherit from Form!) to Quests to custom extensions. That is probably not the problem. I think your issue is likely in the GetFrameworkProperties function; does it return correctly? Have you instrumented it or looked at a debug log?When I used this process to return Globalvariable objects, it works. When I try to return a MiscObject, it returns NONE instead. Very strange though I admit I should be running checks more often. You're certain the property is filled out? Have you instrumented that as well? Link to comment Share on other sites More sharing options...
Lisselli Posted August 2, 2017 Share Posted August 2, 2017 I feel there is an easier way of doing that without so much "nested" function calling. But... no one is going to listen to me so.. Link to comment Share on other sites More sharing options...
Recommended Posts