I might disagree, Amethyst. It doesn't take up another thread, but it will stack to the same thread if the register interval is too short for the system/engine to complete before the next one is fired. I don't know if caching and stacking are the same thing, but it sounds like it. I couldn't find the phrase "rule of one" (outside of Star Wars references) in any quick searches (google or ck wiki), so I'm not sure what you're trying to explain there - I'm under the impression it meant that in-game, only one form could have a certain ID#, overriding other plugins or masters that have the same... I've never heard it applied to scripting.
I discovered the stacking effect, as pertaining to variables and movement, months ago and posted it here - http://www.gamesas.com/topic/1370110-impact-of-system-stress-scripting-errors-on-game-performance/ (though not the OP, a couple down), and on my ship mod's comment section. Originally, my boat script RELIED on stacking.. but I quickly found it to be unreliable depending on system performance. Some systems would studder while others worked, and others yet would CTD.
During this testing, http://www.gamesas.com/topic/1386736-performance-timing-testing-using-scripted-movement/, I have a platform that moves by Player moving forward or backward to control the speed (conditional checks in a repeating quest). The platform is steered to Player's current heading. Now if the reg interval was too fast, the platform's controls would lag and eventually become erratic (stack-dumps).
EG: I would press forward to get the platform moving. I would then cause it to turn left then right then left, over about 3 seconds. If the script was stacking, that smooth lrl movement wouldn't occur for a few seconds - but it did eventually, and how I told it to. If the script was NOT stacking, then the lrl movements actually cut each other off (if close enough together). I already knew that translateTo cancels a transTo already in progress and seemlessly picks up the next one... which my script STILL relies on for smooth real-time movement.
As for the examples you give above, theoretically both scripts should return two after running... Since the interval and waits are so slow, this doesn't show stacking. I just did the following test to see if this is the case. This script, most of which was cut/paste from your post, was attached to a metalLever01 placed in whiterunExterior16.
Spoiler scriptName aatest extends objectReferenceint someValue = http://forums.bethsoft.com/topic/1389486-understandingusing-while-loopsarrays-to-do-what-i-want-to-do/0event onActivate(objectReference triggerRef) SomeValue = 1 Utility.Wait(1) If Somevalue == 1 SomeValue = 2 EndIf Utility.Wait(1) debug.notification(someValue) startReg()endEventfunction startReg() SomeValue = 3 RegisterForSingleUpdate(1)endFunctionEvent OnUpdate() If Somevalue == 3 SomeValue = 4 EndIf Utility.Wait(1) debug.notification(someValue)EndEvent
Notice I changed the variables' values slightly (for better tracking), and removed the if-endif checks for (someCondition). It returned 2 and 4, as expected (where your example would return 2 and 2). But when I added more code to force the update event to repeat, and to simulate external influence with a custom function, it starts to do weird things.
Spoiler event onActivate(objectReference triggerRef) SomeValue = http://forums.bethsoft.com/topic/1389486-understandingusing-while-loopsarrays-to-do-what-i-want-to-do/1 Utility.Wait(1) If Somevalue == 1 SomeValue = 2 EndIf Utility.Wait(1) debug.notification(someValue) startReg() Utility.Wait(2) someValue = 5 startReg() Utility.Wait(2) someValue = 6 startReg() Utility.Wait(2) someValue = 7 startReg() Utility.Wait(2) someValue = 8 startReg()endEventfunction startReg() SomeValue = 3 RegisterForSingleUpdate(1)endFunctionEvent OnUpdate() If Somevalue == 3 SomeValue = 4 EndIf Utility.Wait(1) debug.notification(someValue)EndEvent
It returned 2,3,3,4. Theoretically, it should have returned 2,4,4,4,4,4 correct? Why were ANY 3s shown, much less two of them?? And why were two notifs not even shown (and presumably not run)? The timing is enough that the update events don't overlap (the regSing cancelling each other theory wouldn't apply). In my experience, running custom functions from the onActivate loop is buggy and sometimes won't fire, or the timing will be WAY off (ie: a bug in Papyrus somewhere)... I have no idea how this could happen otherwise.
To further test the onActivate-bug theory, I made the following changes.
Spoiler event onActivate(objectReference triggerRef) SomeValue = http://forums.bethsoft.com/topic/1389486-understandingusing-while-loopsarrays-to-do-what-i-want-to-do/1 Utility.Wait(1) If Somevalue == 1 SomeValue = 2 EndIf Utility.Wait(1) debug.notification(someValue) RegisterForSingleUpdate(1)endEventfunction startReg() SomeValue = 3 If Somevalue == 3 SomeValue = 4 EndIf Utility.Wait(1) debug.notification(someValue)endFunctionEvent OnUpdate() startReg() Utility.Wait(2) someValue = 5 startReg() Utility.Wait(2) someValue = 6 startReg() Utility.Wait(2) someValue = 7 startReg() Utility.Wait(2) someValue = 8 startReg() debug.notification("done")EndEvent
This returned 2,4,(hesitation) 4,4,done.. but shouldn't it return 2,4,4,4,4,4,done? What the hell is going on here? I thought functions have to complete before the rest of the code continues... even if that isn't the case, the waits are long enough so that the notif in the function should still fire correctly.
None of this illustrates the 'stacking effect' though. In order to actually see those effects, the interval must be tiny enough to overload the individual system... which is difficult to quanitfy using notifs. I'll see if I can devise a test using notifs that can show stacking and post separately if I figure something out.
The above tests only serve to show that seemingly buggy behavior happens for no apparent reason... and I now need to find out how and why; am I missing something here? If I can't figure this out quickly (or someone can explain what's going on) - it may destroy my will to mod Skyrim... which is already severely waning for reasons I don't want to go into here.