Jump to content

How to add default value for Form Property?


niston

Recommended Posts

I've tried

Form Property Blah = 0x801 Auto Const

But that doesn't compile. Of course, neither does

Form Property Blah = Game.GetFormFromFile(0x801, "blah.esp") Auto Const

So the question remains: How is it done?

 

If it can't be done (something I've learned to expect from the environment), I figure I can make an int property for the form ID and load it in init. But meh...

Link to comment
Share on other sites

You cant declare a property and assign using a function at the same time.

 

Assuming you want to set a property so it is global/persistent in the script (or so other scripts can access), split them up into a declaration and then an event/function which assigns it:

Keyword Property rSKK_476NoDisable Auto 

Event Actor.OnPlayerLoadGame(Actor akSender)
   If (Game.IsPluginInstalled("SKK476OpenWorld.esp") == TRUE)
      rSKK_476NoDisable = Game.GetFormFromFile(0x00019bcb, "SKK476OpenWorld.esp") as Keyword
   Else
     rSKK_476NoDisable = None
   EndIf
EndEvent
Link to comment
Share on other sites

Ah yes, that's why I said of course it doesn't compile :smile:

 

But what I'd ultimately like to do is give one of my script's Form properties a default value. So that when edited in CK, the default value is shown.

 

You know, like

String Property Blah = "TheDefaultValue" Auto

works. But for a form instead of a string.

 

If it can't be done, I'll probably make an Int Property TheIDOfTheForm instead. But that's a lot less elegant and you'll have to fill in the formID as a number, instead of picking it like you do with a Form property.

Link to comment
Share on other sites

If you are not hard coding the form reference in hex then aiFormID must be an Int variable as there is no hex format variable:

Int Property iFormID = 2048 Auto

...

Form FormToReturn = Game.GetForm(iFormID) as Form

...

Although I have had all sorts of unpredictable issues trying to get generic untyped forms, so always explicitly type the form;

Int Property iWeaponFormID = 2048 Auto
...
Weapon FormToReturn = Game.GetForm(iWeaponFormID) as Weapon 
...
Link to comment
Share on other sites

Oh, but there is a hex format. Or rather, one can use hex notation for numbers in Papyrus script:

Int Property FormID = 0x801 Auto Const

works very well.

 

Anyhow. I feel like I made myself not clear enough. I was trying to avoid the above, specifically.

 

Let me explain w/ some pictures. What I wanted for the users of my script to get in CK is this instead of this.

 

You catch my drift? Even tho in practice I would type the property EEE:BuriedWire_FarConnector instead of Form....

 

But I take it that it's simply not possible to initialize a property default value to anything that can't be expressed w/o a function.

Link to comment
Share on other sites

Putting hex value into an Int variable, never knew that.

 

Howabout a different approach = use a form list and load whatever is at index [0] of the form list as the form to use ?

 

Then you can prime index [0] with your default form.

 

I do this a lot in my mods to give users a super flexible method to modify spawned actor types and configurations either in CK with drag and drop into the form list, or xEDIT.

Link to comment
Share on other sites

After some consideration, I think I'll just leave my EEE:BuriedWire_FarConnector property empty/none for default.

 

Doing so may not be as elegant as having the proper default value, but I can't warm up to the idea of using a formlist for this. And if the property is typed as such, only objects of the matching type may be picked in CK anyway. It's thus still better than using an Int for the FormID, where the user could point it at any senseless formID they manage to mistype (such as a weapon or whatever). Plus I can add a note in property comment that none means a default of EEE:BuriedWire_FarConnectorFloor.

 

It's a shame this can't be done properly. Kinda toy language, really.

Link to comment
Share on other sites

So here's a followup. To do what I did in the picture above:

 

1) Create and compile an empty interface class that inherits from Form, such as:

Scriptname IIsSelectableDoohicky extends Form

2) Attach the IIsSelectableDoohicky script to all the objects you would like to appear in the CK edit value dropdown list. If your object already has one or more scripts attached, attach this one as well.

 

3) Define your property as Type IIsSelectableDoohicky

IIsSelectableDoohicky Property SelectedDoohicky Auto

Done. Now, when somebody edits your script properties in CK, they will be directly presented with a dropdown box containing just valid entries (and NONE) - They won't have to select the object type first and then fill out the filter textbox to find and/or browse for applicable Forms to put into the property. It could be you doing the editing, so this can probably save you some time.

 

As a nice side effect, users won't be able to fill your property with senseless trash Forms either, perhaps preventing a headache or two on developer's part as well.

 

On the original subject of having a default value of type Form for the property, it is possible indeed - Just not at design time (aka in Creation Kit). The "trick" is to use a full property instead of an Auto property:

; this is the private member variable backing our full property
IIsSelectableDoohicky mSelectedDoohicky

; this is the full property
IIsSelectableDoohicky Property SelectedDoohicky
    IIsSelectableDoohicky Function Get()
        If (mSelectedDoohicky == none)
            ; this is the Form we want to use as default value
            mSelectedDoohicky = Game.GetFormFromFile(0x801, "plugin.esp") as IIsSelectableDoohicky
        EndIf
        Return mSelectedDoohicky
    EndFunction
    Function Set(IIsSelectableDoohicky value)
        mSelectedDoohicky = value
    EndFunction
EndProperty

The SelectedDoohicky property will have Form 0x801 (which must have the IIsSelecteableDoohicky script attached, else it won't work!) from the plugin "plugin.esp" as it's default value at runtime. Meanwhile, at design time, the default value will be shown as <Unknown>. Bummer, and not exactly what I've been originally looking for, so it's just a near-perfect solution. Still, you can either ignore the <Unknown>, or set to NONE and it'll faithfully use the default Form you have chosen inside the property getter instead.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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