Jump to content

Setting global variables via scripting


TheMrDomino

Recommended Posts

I have a feeling this is something very obvious, but I've been staring at it for so long I can't see the solution

 

This is the relevant snippet of the script that I'm working with:

Message Property menuChance  Auto
Message Property menuEnabled  Auto  
Message Property menuDEnabled  Auto  
Message Property menuDChance  Auto  
GlobalVariable Property kchance  Auto  
GlobalVariable Property enabled  Auto  
GlobalVariable Property enabledPermanent  Auto  

;activate when book is opened
Event OnRead()

;wait for 1.3 seconds before showing menu while book opening animation plays
WaitMenuMode(1.3)

;initialize data-holding values.  First line brings up the enabled menu
int enabled = menuEnabled.Show()
int choice = 0
int chance = 0

;if the user clicks enabled set the set the relevant variable to 1, display the chance menu, 
;calculate the chance based on input, and use the value to set the global variable chance
if enabled == 1
	enabled.SetValueInt(1)
	enabledPermanent.SetValueInt(1)
	choice = menuChance.Show()
	chance  = (choice + 1) * 10
	kchance.SetValue(chance)

 

The issue lies with the enabledPermanent.SetValueInt(1) line. Quite simply, it doesn't change the variable at all.

 

I've gone through everything I can think of. The enabledPermanent property is tied to a new global variable (short type) I created that is NOT set to constant: in-game I can use the set command to manually change the value, verifying the change with getglobalvalue. I've tried using just SetValue instead of SetValueInt. Nowhere else in the script is enabledPermanent set to any other value. This the only script that ever attempts to set this specific custom variable, in the only other script that uses it the value is retrieved, never modified. I've recompiled the script, and there are no errors, compilation succeeds. What makes it doubly strange is the line above it works just fine, changing the global variable it's attached to just fine.

 

The only thing I could think that's causing the issue is the fact that I'm trying to modify a newly created global variable, as all the other globals that are modified in the script are existing vanilla globals. Is there a trick to creating a new global variable beyond going to the globals section and adding a new entry? As I mentioned, I can check and set the value of the new global in the console in-game, which leads me to believe I've added it correctly. Which just leaves me back at square one.

Edited by TheMrDomino
Link to comment
Share on other sites

The property is set in the CK, yes.

 

I've been using the same save for all my testing, but it's had previous versions of the mod saved with it. I'll make a clean save and see if that makes a difference.

 

edit: Creating a clean save did the trick. How odd it behaves that way, but I'm glad a solution was found. Thank you!

Edited by TheMrDomino
Link to comment
Share on other sites

  • Recently Browsing   0 members

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