Jump to content

[LE] Help with global variables


Recommended Posts

Hi, I have been going crazy over this issue. I have spent the last two hours trying to make this work. The problem is that global variables are not working for me. I am new to modding by the way. Here is the issue. I got to the start of a script and put the declaration for my global variable like this:

 

GlobalVariable Property BlaGlobal Auto

 

Then, I go ahead and set the value on a function like this:

 

BlaGlobal.SetValue(1)

 

When I try to retrieve it later on like:

 

float temp = BlaGlobal.GetValue()

 

I always get the 0.00000 value. I have tried getting the reference for the BlaGlobal using:

 

debug.Notification("Global ref =" + BlaGlobal)

 

It is always none. What am I doing wrong? I have followed the documentation to the letter. I even tried starting from a clean save without a single mod on it. That did not help either. Is there some kind of initialization to global variables or something? Thanks.

 

 

 

Link to comment
Share on other sites

 

Did you assign the property to the global variable? You can't just declare it in a script.

Hi, how do I do that?

 

 

Select the script in the script window, and either hit the "edit properties" button on the right, or right-click on it and choose "edit properties" from there. It'll pull up a popup window that will let you fill in the properties with appropriate editor objects.

Link to comment
Share on other sites

The only way would be to assign the global using GetFormFromFile(), but you'll need to know the form ID of the global variable.

 

http://www.creationkit.com/index.php?title=GetFormFromFile_-_Game

 

So you'd have your script property as:

 

GlobalVariable MyGlobal = None

 

Then in the first function call of your script:

 

MyGlobal = Game.GetFormFromFile()

 

And fill in the function properly using the link above.

Link to comment
Share on other sites

So, the only way to use those global variables is to actually have them in an ESP file and then using the Game.GetFormFromFile(), and then I have a reference to that variable in which I can get its value and set it. Did I get this right?

Link to comment
Share on other sites

So, the only way to use those global variables is to actually have them in an ESP file and then using the Game.GetFormFromFile(), and then I have a reference to that variable in which I can get its value and set it. Did I get this right?

That's right mate.

 

Is there any reason you can just use a float or integer?

Link to comment
Share on other sites

Thanks a lot for the information, B1gBadDaddy. It is much appreciated. The problem is I want to carry the information between sessions. I ended up using StorageUtil which does not force me to use the ESP files.

 

Script variables are saved between sessions too.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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