I thought globals were "persistent"

Post » Mon Feb 04, 2013 2:32 am

Quick explanation. In my fetch quests the total amount of [object] the player needs to collect is determined like so:

Spoiler

TargetCount = Utility.RandomInt(MinSkins, MaxSkins)HISJLE01QTotal.value = http://forums.bethsoft.com/topic/1441075-i-thought-globals-were-persistent/TargetCountfloat CurrentCount = Game.GetPlayer().GetItemCount(TargetSkins)HISJLE01QCount.Value = CurrentCountUpdateCurrentInstanceGlobal(HISJLE01QCount)UpdateCurrentInstanceGlobal(HISJLE01QTotal)

The way I've set up my export fetch quests are like this. When the player activates a static note, a message is displayed showing what the player needs to get and how many of for that contract. This is radiant and randomly generated. Through clever use of starting the quest but not actually starting the quest (starting, setting up the logic, but pausing on an empty stage so the quest isn't in your journal yet), this works like so : http://static.skyrim.nexusmods.com/mods/images/18866-1-1359741789.jpg

The player can only have 1 actual active export running at a time, so when they select a note it will always display what that contract requires, it just won't allow a new quest to "run" whilst another is running.

I forgot that all my export quests use the same global variables in their script; HISJLE01QCount (player object count) and HISJLE01QTotal (Total objects to get). As you can see from the above script, which runs when the quest starts to determine the counts, the global variable is actually set. Like, "Hey global, you're this number, deal with it!". However, if I have 2 notes on the wall for 2 different quests, each quest runs it's initial logic fine and displays a separate Total Amount to Get when activated.... If you understand what I mean, I don't get how that's possible...

Properties I get can be different values for each iteration of a reference, but I thought globals were static and persistent.

How can 1 global variable be 2 different values?????? Seriously, proper confused me it has lol.
User avatar
Claire Vaux
 
Posts: 3485
Joined: Sun Aug 06, 2006 6:56 am

Post » Mon Feb 04, 2013 5:29 am

Not sure what the issue is without seeing more of the code, but you could check to see if the UpdateCurrentInstanceGlobal call is successful (it returns true if successful or false it if failed).
User avatar
Alisia Lisha
 
Posts: 3480
Joined: Tue Dec 05, 2006 8:52 pm

Post » Mon Feb 04, 2013 5:41 am

Here is my full script. This determines how many objects to get, what object to get, what the player's count is in real-time with the help of an AddInventoryFilter/OnItemAdded/OnItemRemoved player alias script, and everything else with cleaning it all up.

Note that I have now switched to an new static property name, HISJLEQCount etc, instead of HISJLE01QCount etc. And have set the property to point to unique globals for each quest. I just didn't want anything problematic to show up later down the road...

Spoiler

Scriptname HISJLEQuestScript extends Quest Conditional Quest Property HISJLEQuest  AutoQuest Property myQuest  AutoReferenceAlias Property SamplePelt  Auto  ReferenceAlias Property SamplePeltSpawnPoint  Auto Int Property MaxSkins  Auto  Int Property MinSkins  Auto  Int Property MaxSkins2  Auto  Int Property MinSkins2  Auto  Int Property TargetSkinsIndex  Auto  ConditionalInt Property StageToSet01 autoMiscObject Property Pelt1  AutoMiscObject Property Pelt2  AutoMiscObject Property Pelt3  Auto  MiscObject TargetSkins = None GlobalVariable Property HISJLEQActual  Auto  GlobalVariable Property HISJLEQCount  AutoGlobalVariable Property HISJLEQTotal  Autoint TargetCount = -1Function Startup()TargetCount = Utility.RandomInt(MinSkins, MaxSkins)HISJLEQTotal.value = http://forums.bethsoft.com/topic/1441075-i-thought-globals-were-persistent/TargetCountfloat CurrentCount = Game.GetPlayer().GetItemCount(TargetSkins)HISJLEQCount.Value = CurrentCountUpdateCurrentInstanceGlobal(HISJLEQCount)UpdateCurrentInstanceGlobal(HISJLEQTotal)TargetSkinsIndex = Utility.RandomInt(1, 3)if     (TargetSkinsIndex == 1)TargetSkins = Pelt1TargetCount = Utility.RandomInt(MinSkins2, MaxSkins2)HISJLEQTotal.value = TargetCountUpdateCurrentInstanceGlobal(HISJLEQTotal)elseif (TargetSkinsIndex == 2)TargetSkins = Pelt2elseif (TargetSkinsIndex == 3)TargetSkins = Pelt3elseTargetSkinsIndex = 1TargetSkins = Pelt2endifif (TargetCount <= 0)TargetCount = 6endif       HISJLEQActual.SetValue(TargetSkinsIndex)ObjectReference pelt = SamplePeltSpawnPoint.GetReference().PlaceAtMe(TargetSkins)SamplePelt.ForceRefTo(pelt)      SetStage(9)endFunctionFunction StageSet()   if HISJLEQActual.GetValueInt() == 1       SetStage(11)   elseif HISJLEQActual.GetValueInt() == 2       SetStage(12)   elseif HISJLEQActual.GetValueInt() == 3       SetStage(13)endifEndFunctionFunction Pelt1Counted()       HISJLEQTotal.value = TargetCount       float CurrentCount = Game.GetPlayer().GetItemCount(Pelt1)       HISJLEQCount.Value = CurrentCountUpdateCurrentInstanceGlobal(HISJLEQCount)UpdateCurrentInstanceGlobal(HISJLEQTotal)if CurrentCount>= TargetCountHISJLEQuest.SetObjectiveCompleted(10,1)HISJLEQuest.SetObjectiveDisplayed(15,true,true)elseif CurrentCount < TargetCountHISJLEQuest.SetObjectiveCompleted(10,0)HISJLEQuest.SetObjectiveDisplayed(15,0)HISJLEQuest.SetObjectiveDisplayed(10,true,true) endifendFunction Function Pelt2Counted()       HISJLEQTotal.value = http://forums.bethsoft.com/topic/1441075-i-thought-globals-were-persistent/TargetCount       float CurrentCount = Game.GetPlayer().GetItemCount(Pelt2)       HISJLEQCount.Value = CurrentCountUpdateCurrentInstanceGlobal(HISJLEQCount)UpdateCurrentInstanceGlobal(HISJLEQTotal)if CurrentCount>= TargetCountHISJLEQuest.SetObjectiveCompleted(10,1)HISJLEQuest.SetObjectiveDisplayed(15,true,true)elseif CurrentCount < TargetCountHISJLEQuest.SetObjectiveCompleted(10,0)HISJLEQuest.SetObjectiveDisplayed(15,0)HISJLEQuest.SetObjectiveDisplayed(10,true,true) endifendFunction  Function Pelt3Counted()       HISJLEQTotal.value = http://forums.bethsoft.com/topic/1441075-i-thought-globals-were-persistent/TargetCount       float CurrentCount = Game.GetPlayer().GetItemCount(Pelt3)       HISJLEQCount.Value = CurrentCountUpdateCurrentInstanceGlobal(HISJLEQCount)UpdateCurrentInstanceGlobal(HISJLEQTotal)if CurrentCount>= TargetCountHISJLEQuest.SetObjectiveCompleted(10,1)HISJLEQuest.SetObjectiveDisplayed(15,true,true)elseif CurrentCount < TargetCountHISJLEQuest.SetObjectiveCompleted(10,0)HISJLEQuest.SetObjectiveDisplayed(15,0)HISJLEQuest.SetObjectiveDisplayed(10,true,true) endifendFunction Function Cleanup()       ObjectReference pelt = SamplePelt.GetReference()pelt.Disable()pelt.Delete()SamplePelt.Clear()       myQuest.SetStage(StageToSet01)EndFunction
User avatar
Lillian Cawfield
 
Posts: 3387
Joined: Thu Nov 30, 2006 6:22 pm


Return to V - Skyrim