NikaCola Posted July 20, 2018 Share Posted July 20, 2018 So...All I would like to do is raise or lower the total number of a global variable, but when I do so the variable raises by several times, usually around five(??). Here's what I've written: function raise() myglobalvariable.setvalue(myglobalvariable.getvalue() + 1) float APfloat = myglobalvariable.GetValue() as float myglobalvariableMSG.Show(APfloat) endfunctionOriginally I was calling this inside a dialogue papyrus fragment as kmyquest.raise() but even when writing it out in the fragment itself, the same problem still occurs. Like this: myglobalvariable.setvalue(myglobalvariable.getvalue() + 1)When I check the variable immediately afterwards, it's raised not by one, but by five or so (usually). What could be causing this? If it matters, the script I originally put this function in was a quest script. Any help would be really, really appreciated! <3 Link to comment Share on other sites More sharing options...
NikaCola Posted July 20, 2018 Author Share Posted July 20, 2018 Also to add, I've also tried using Mod, with the same results. For example:myglobalvariable.mod(1)And the same thing still happens! :sad: Link to comment Share on other sites More sharing options...
akiras404 Posted July 20, 2018 Share Posted July 20, 2018 I suspect the raise() has been called multiple time in parallel.Could you show me when raise() called? Link to comment Share on other sites More sharing options...
Carreau Posted July 21, 2018 Share Posted July 21, 2018 A safe way to do that is to copy the global into a local float, then increment that in your setvalue Link to comment Share on other sites More sharing options...
NikaCola Posted July 21, 2018 Author Share Posted July 21, 2018 On 7/20/2018 at 9:40 PM, akiras404 said: I suspect the raise() has been called multiple time in parallel.Could you show me when raise() called? Sorry, I'm not sure what you mean? I'm calling it only in a dialogue fragment as a kmyquest.function(), or else writing out the full line of code as above. It also appears in other dialogue fragments, but the problem happens from the very first time that fragment fires. The strange part is, I just noticed that I call the exact same line of code in a Quest Stage fragment that fires every time the PC levels up, and *there* it works perfectly, incrementing 1 at a time just as written. So I know the line of code itself has got to work. Link to comment Share on other sites More sharing options...
akiras404 Posted July 21, 2018 Share Posted July 21, 2018 (edited) Sorry for bad explanation. And on second thought, I'm not so good at quest handling... But I write down what I thought hoping it can be help.The code itself seems fine, so I thought problem belongs to its caller.If the raise() called multiple time in the same time, it may causes the problem you have.As you say it's called as dialogue fragment, problem can be where the fragment is wrote, scene structure.Then I thought a screenshot of where the fragment wrote might be help for understanding the problem. EDIT :To see if the code runs multiple times, make your myglobalvariableMSG as MessageBox.If code runs multiple times, MessageBox will appear multiple times.If it's true, to avoid (not solve) this in quick way, wait all thread for reading GlobalVariable.In this case, code will be like below.function raise() float tmpValue = myglobalvariable.GetValue() Utility.wait(1) myglobalvariable.SetValue(tmpValue + 1) float APfloat = myglobalvariable.GetValue() as float myglobalvariableMSG.Show(APfloat) endfunction Edited July 21, 2018 by akiras404 Link to comment Share on other sites More sharing options...
NikaCola Posted July 21, 2018 Author Share Posted July 21, 2018 On 7/21/2018 at 2:43 PM, akiras404 said: Sorry for bad explanation. And on second thought, I'm not so good at quest handling... But I write down what I thought hoping it can be help.The code itself seems fine, so I thought problem belongs to its caller.If the raise() called multiple time in the same time, it may causes the problem you have.As you say it's called as dialogue fragment, problem can be where the fragment is wrote, scene structure.Then I thought a screenshot of where the fragment wrote might be help for understanding the problem. EDIT :To see if the code runs multiple times, make your myglobalvariableMSG as MessageBox.If code runs multiple times, MessageBox will appear multiple times.If it's true, to avoid (not solve) this in quick way, wait all thread for reading GlobalVariable.In this case, code will be like below.function raise() float tmpValue = myglobalvariable.GetValue() Utility.wait(1) myglobalvariable.SetValue(tmpValue + 1) float APfloat = myglobalvariable.GetValue() as float myglobalvariableMSG.Show(APfloat) endfunction I figured it out! Thank you so much for your help. Apparently the issue was that I was calling that function at the BEGINNING of the dialogue phase, which had multiple lines of dialogue. Apparently the function was running for EVERY line of dialogue spoken. (why would it do that???) When I put the function at the END of the dialogue phase instead, it fires just once as intended. Argh that was going to drive me crazy! Again thank you so so much! <3 <3 Link to comment Share on other sites More sharing options...
Recommended Posts