Jump to content

How do I set Global Variables from script?


Halstrom

Recommended Posts

1. Check the Global variable form itself doesn't have the CONSTANT checkbox checked

 

2. If it doesn't, when you define it as a property for the script do not include CONST

 

GlobalVariable Property pSKK_Debug Auto Const Mandatory ; read only

GlobalVariable Property pSKK_Debug Auto Mandatory ; read/write

Link to comment
Share on other sites

1. Check the Global variable form itself doesn't have the CONSTANT checkbox checked

 

2. If it doesn't, when you define it as a property for the script do not include CONST

 

GlobalVariable Property pSKK_Debug Auto Const Mandatory ; read only

GlobalVariable Property pSKK_Debug Auto Mandatory ; read/write

Cool, thanks, I thought it would be something simple like that :)

Link to comment
Share on other sites

The const flag on GlobalVariables actually has nothing to do with the script-side flag.

 

The flag for GlobalVariables sets its value to be constant, so any changes to them can't be saved. I'm not sure if its purpose is memory optimization or just locking the value to its default. It's possible to create an override for the globalvariable to disable the const flag, but I'm not sure if there are any long-term negative effects since we don't know how they're handled by the game engine.

 

The const flag in scripts is mostly for memory optimization, and will prevent changes to the variable or forms used as properties. If the GlobalVariable property will only be used for its default form and you're not planning to set it to a different GlobalVariable in the script, use const in its definition. It won't prevent you from changing the globalvariable's value in the script.

Link to comment
Share on other sites

So here is the thing, I just this minute set the const checkbox on a GlobalVariable Form and Const in the properties and:

 

[02/20/2018 - 12:28:50AM] error: Cannot set the value of a constant GlobalVariable

Link to comment
Share on other sites

Yep, that's what the globalvariable form's const flag does. The script-side flag is unrelated to this - it just marks the property/variable as a constant so that its contents (the globalvariable form the property points to) can't be changed dynamically (or swapped out for another globalvariable) .

 

It's possible to create an override of the globalvariable's form in a separate plugin and clear the const flag on the override to allow editing it - but, as mentioned, no clue if there are any negative effects to doing this.

Edited by isathar
Link to comment
Share on other sites

You'll need to call the GlobalVariable function GetValue() for that.

 

fBatteryLevel = gBatteryLevel.GetValue() should work.

 

If you plan to edit the GlobalVariable's value, use SetValue(YourNewBatteryLevel).

 

A description of the functions you can use on GlobalVariables can be found here.

 

 

SKK50: I'm not sure what you mean. As I mentioned, the two flags are unrelated, so it's not about elegance but functionality.

Here's a description of the GlobalVariable form's const flag, and here's the same for Papyrus - explained in a much better way than I can pull off.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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