iqoniq Posted October 25, 2022 Share Posted October 25, 2022 I'm working on a quest script that needs to check 3 values and if 3 match then it goes to State3, 2 goes to State2, and if none match it goes to the end stage. The code I've currently got is Function FireItUp() Int slot_a = UtilityRandomInt(1, 10) Int slot_b = UtilityRandomInt(1, 10) Int slot_c = UtilityRandomInt(1, 10) xslot_a.SetValue(slot_a) ; Globals declared earlier xslot_b.SetValue(slot_b) xslot_c.SetValue(slot_c) GotoState("Do Checking") EndFunction State DoChecking Event OnBeginState(string asOldState) Int slot_a = xslot_a.GetValue() As Int Int slot_b = xslot_b.Getvalue() As Int Int slot_c = xslot_c.GetValue() As Int If slot_a == slot_b && slot_c == slot_a ; All 3 match GotoState("State3") ElseIf slot_b == slot_a && slot_c != slot_a ; Only 2 Match GotoState("State2") Else ; No Match (Self As Quest).SetStage(30) EndIf EndEvent EndStateThe code does see the 3 match as it will fire a Debug.Notification, but it also sees the double match and goes to the State2, and will also fire stage 30. I managed to avoid the final stage firing by setting the final stage as it's own IF statement and setting a toggle variable, but it doesn't seem ideal.Can anyone figure out where I'm going wrong or what I'm misunderstanding?Thanks in advance. Link to comment Share on other sites More sharing options...
DieFeM Posted October 25, 2022 Share Posted October 25, 2022 It seems very strange to me that you get all 3 results in the same call, so I guess that you have some recursion problem, but only with that part of the code it's going to be all guesses.It would help to know where from FireItUp() is being called (maybe an event is being fired many times), if there could be many instances of the same script (many references using it). Things like that are probably the cause of the problem, not the conditional block itself, which looks fine. Link to comment Share on other sites More sharing options...
iqoniq Posted October 25, 2022 Author Share Posted October 25, 2022 It seems very strange to me that you get all 3 results in the same call, so I guess that you have some recursion problem, but only with that part of the code it's going to be all guesses.It would help to know where from FireItUp() is being called (maybe an event is being fired many times), if there could be many instances of the same script (many references using it). Things like that are probably the cause of the problem, not the conditional block itself, which looks fine. The whole script is around 600 lines lol. FireItUp() is being called from a quest stage fragment kmyQuest.FireItUp() set to the script which is the only script on the quest. The quest is triggered by a button which is just a standard setstage command on a script there. I did (after my initial post) change the start of the If statement and ElseIf to... If slot_a == slot_b && slot_a == slot_c wintoggle = 1 ... ElseIf slot_a == slot_b && slot_a != slot_c wintoggle = 1 ... EndIf If wintoggle == 1 (Self As Quest).SetStage(30) EndIfIn case there was something with the variables that was causing the anomaly, and this created an interesting result. It seemed to detect the 3 matching the first time it happened, and then it was only detecting a 3 match as a double after that. Losses were bombing out as usual. Link to comment Share on other sites More sharing options...
DieFeM Posted October 25, 2022 Share Posted October 25, 2022 Just in case, to discard, it might be a silly question but, do you start from a clean game on each test? because making papyrus debugging on a saved game can give "funny" results.In some cases, the engine might keep old script instances of the same code running from the saved game, that might be creating recursion. Link to comment Share on other sites More sharing options...
iqoniq Posted October 25, 2022 Author Share Posted October 25, 2022 Just in case, to discard, it might be a silly question but, do you start from a clean game on each test? because making papyrus debugging on a saved game can give "funny" results.In some cases, the engine might keep old script instances of the same code running from the saved game, that might be creating recursion.I have a save that is clean and devoid of mods (with the exception of Start Me Up so I can skip the vault), and then it just loads with my normal load out so it's pretty much clean each time, and I don't need to "play through" this mod so I'm not dropping saves with it at all (even if it can be a nightmare trying to get it to spawn 3 random numbers the same). I've redone the script States as Functions triggered by stages (thankfully not much in the way of a recode), and changed the check to a double only. If this is triggered it goes to a stage/function for a further check of slot_a against slot_c. This seems to be going to the correct stages and functions reliably. It also seems slightly snappier as well so that's good I suppose. Thanks for your help, even if we didn't get to the bottom of it, unless someone else lets me know what's happened :) Link to comment Share on other sites More sharing options...
DieFeM Posted October 26, 2022 Share Posted October 26, 2022 (edited) I'm glad you've got it working. Go guess what's wrong with using states. At the end of the day, if you don't really need them, better not overcomplicate it.I only use states when I want to use an event differently depending on a certain action, for example mount/dismount from a vehicle.If I'm riding a vehicle, I want OnActivate to call dismount, but if I want to ride the vehicle then the same OnActivate should call SnapInToInteraction, so you need different states, to declare different OnActivate event handlers.But i don't think your script needs such functionality, so using functions seems like a proper approach, even better than states. PS: You can use conditionals in the same event to produce the same effect, tho. So, I don't really think states are really necessary under any circumstances, but I guess using them can make the code more readable, and maybe they have some advantage under the hood. Edited October 26, 2022 by DieFeM Link to comment Share on other sites More sharing options...
84Cronos Posted October 26, 2022 Share Posted October 26, 2022 I'm working on a quest script that needs to check 3 values and if 3 match then it goes to State3, 2 goes to State2, and if none match it goes to the end stage. The code I've currently got is Function FireItUp() Int slot_a = UtilityRandomInt(1, 10) Int slot_b = UtilityRandomInt(1, 10) Int slot_c = UtilityRandomInt(1, 10) xslot_a.SetValue(slot_a) ; Globals declared earlier xslot_b.SetValue(slot_b) xslot_c.SetValue(slot_c) GotoState("Do Checking") EndFunction State DoChecking Event OnBeginState(string asOldState) Int slot_a = xslot_a.GetValue() As Int Int slot_b = xslot_b.Getvalue() As Int Int slot_c = xslot_c.GetValue() As Int If slot_a == slot_b && slot_c == slot_a ; All 3 match GotoState("State3") ElseIf slot_b == slot_a && slot_c != slot_a ; Only 2 Match GotoState("State2") Else ; No Match (Self As Quest).SetStage(30) EndIf EndEvent EndStateThe code does see the 3 match as it will fire a Debug.Notification, but it also sees the double match and goes to the State2, and will also fire stage 30. I managed to avoid the final stage firing by setting the final stage as it's own IF statement and setting a toggle variable, but it doesn't seem ideal. Can anyone figure out where I'm going wrong or what I'm misunderstanding? Thanks in advance. Out of curiosity: Are you not checking for b==c in the ElseIf or am I blind or missing something? Because it appears that this case isn't being accounted for. Maybe it's not needed semanticly for your quest, but I can't tell from looking at this abstract code. Link to comment Share on other sites More sharing options...
iqoniq Posted October 30, 2022 Author Share Posted October 30, 2022 Out of curiosity: Are you not checking for b==c in the ElseIf or am I blind or missing something? Because it appears that this case isn't being accounted for. Maybe it's not needed semanticly for your quest, but I can't tell from looking at this abstract code. It's not being accounted for on purpose. It should only fire when the first two, or all three values match. The actual quest is just related to a kind of slot machine, and the section excerpted checks the win line, hence ignoring whether a == c or b==c alone (although that may come at a later date, but I know it works :laugh: ). Link to comment Share on other sites More sharing options...
Recommended Posts