Jump to content

Game.GetFormFromFile with variable


Recommended Posts

Hi! I got another basic (noob) question to which I could not find a proper answer in the forums.




I have to get some forms from a DLC and to do that I would do something like:




target.FormID = Game.GetFormFromFile(0x0001F0E6, RequiredDLC) as Form


Which works quite well. The thing is, this is hard coded, specific per object and prone to error.


I would prefer to do something like:


target.FormID = Game.GetFormFromFile(target.refId, RequiredDLC) as Form


Where refId is (I guess), an int.


If we go for the 0x08DIGITS format we can pass hexa values without issue. But not with ints. I tried converting the value to decimal and it did not work properly.

I also considered using a string which would have the "0x0001F0E6" value. But I don't think it would work.


So, how is the proper way to store this at editor time so I can parse it at runtime??


Thanks,

SameOldBard




Edit. Fixed weird format

Edited by SameOldBard
Link to comment
Share on other sites

I've used ints as variables successfully in GetFormFromFile().

 

The only time I've had to do this, I set the property with a default value in hex. The default value is converted to decimal in the CK's script properties tab, and then any subsequent values I've needed to put in that weren't the same as default, they needed to be put in as decimal as well.

 

And as a sanity check, I usually throw a debug trace in to report the returned form to the papyrus log to make sure I'm grabbing the correct form.

ScriptName Example extends SomeForm

int property iFormID = 0x00123456 Auto

string property sModName = "plugin.esp" Auto ;or esm depending on file

Event OnInit()
   GrabForm()
EndEvent

Function GrabForm()
   Form thisForm = GetFormFromFile(iFormID, sModName) ;you can cast the form directly as well
   ;Armor thisArmor = GetFormFromFile(iFormID, sModName) as Armor //for example
   debug.trace("Script returned form: " + thisForm")
   ;do whatever I need with the form
EndFunction

I've used this to make soft dependencies. I see no reason this wouldn't work with DLC plugins. So long as you're leading your hex ID with 0x00 before getting into the FormID proper. The leading zeros will get swapped out for the plugin's index with GetFormFromFile(). So with your example above, I would set it as:

 

int property iFormID = 0x0001F0E6 Auto

Edited by Carreau
Link to comment
Share on other sites

I've used ints as variables successfully in GetFormFromFile().

 

The only time I've had to do this, I set the property with a default value in hex. The default value is converted to decimal in the CK's script properties tab, and then any subsequent values I've needed to put in that weren't the same as default, they needed to be put in as decimal as well.

 

And as a sanity check, I usually throw a debug trace in to report the returned form to the papyrus log to make sure I'm grabbing the correct form.

ScriptName Example extends SomeForm

int property iFormID = 0x00123456 Auto

string property sModName = "plugin.esp" Auto ;or esm depending on file

Event OnInit()
   GrabForm()
EndEvent

Function GrabForm()
   Form thisForm = GetFormFromFile(iFormID, sModName) ;you can cast the form directly as well
   ;Armor thisArmor = GetFormFromFile(iFormID, sModName) as Armor //for example
   debug.trace("Script returned form: " + thisForm")
   ;do whatever I need with the form
EndFunction

I've used this to make soft dependencies. I see no reason this wouldn't work with DLC plugins. So long as you're leading your hex ID with 0x00 before getting into the FormID proper. The leading zeros will get swapped out for the plugin's index with GetFormFromFile(). So with your example above, I would set it as:

 

int property iFormID = 0x0001F0E6 Auto

 

Sorry for taking this long to reply, real life demanded some attention.

 

I had something similar to that already working, but again, it was hard coded.

 

What I managed to get working was to have the int var in my struct and store the value in there as decimal. So, basically I get the 6 digits hex (last 6), convert them to decimal and stores in my struct at the Creation Kit. It would be great if it was possible to have some editor scripts in the Creation Kit as we have on Unity3d, but that's something for a different discussion.

 

Anyway, thanks for the answer @Carreau as it put me in the right track to find the solution I needed.

 

Cheers

Link to comment
Share on other sites

  • Recently Browsing   0 members

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