Hola team.
So I have a basic setup involving a few actives that are created/destroyed/updated dynamically, as follows:
Player Clicks Unit
-> Run loop UpdateInfoTray
(amongst other loops, but this is the one that's being odd, and it's executed last and doesn't involve any other moving parts previously scoped/referenced)
On Loop UpdateInfoTray:
-> Set InfoTray.Active AltVal OnScreen to 1 (Brings it onto the screen as opposed to hiding it offscreen - no problems here)
-> Set InfoTray.Active AltVal AnimationSize to 0 (Resets, ready to receive new value, is having slight issues)
-> Start Loop "SpecialTray Clear" 1 time
-> Start Loop "SpecialTray CastUpdate" X times
-> Start Loop "SpecialTray SelfUpdate" X times
-> Start Loop "SpecialTray EffectUpdate" X times (X in all these loops references a different object's alt val that's keeping track of total number of each category)
-> Run Loop ForEach SpecialTrayButton.Active "MaxID"
-----------
On Loop "SpecialTray Clear"
-> Destroy SpecialTrayButton.Active
On Loop "SpecialTray (Cast/Self/Effect)Update" (they all work the same)
-> Create SpecialTrayButton.Active
-> Set SpecialTrayButton.Active AltVal ID to (Loop Index)
-> Set SpecialTrayButton.Active AltVal Index to (value from a different object gotten via index reference, basically the button's "type"
-> Set SpecialTrayButton.Active AltVal Category to 1/2/3 (Depending on Cast/Self/Effect loop running)
ForEach SpecialTrayButton.Active "MaxID"
+ SpecialTrayButton.Active AltVal ID is GREATER THAN InfoTray.Active AltVal AnimationSize
-> Set InfoTray.Active AltVal Animation Size to SpecialTrayButton.Active AltVal ID
SO.
As I follow this through, there are two things that aren't happening that should be, and I think it's down to weird scoping ala Vol's recent (and excellent) article.
What should be happening is, if a Unit has NO Button Actives created, there should be no ID greater than 0, thus the animation value on the Tray object should remain 0. However, I suspect that scoping weirdness is keeping Buttons alive during this loop process, because the first time clicking from a Unit that has say 3, to a unit with 0, the Animation Value remains the same. If I click it again, this time with the Button actives destroyed already ie not in the same loop set, it remains at 0.
Second issue, is that during the ForEach loop, the ID picked up for the Animation Value on the tray is not always the highest ID on the button Actives. Specifically, it will pick the Highest ID from the objects in the SELF loops, ignoring any button active ID's from the CAST loops. Can't figure out why this is, and I'm guessing it has something to do with scoping again - but it doesn't seem the be the same 'legacy actives' issue from above. The reason I think that is because going from a Unit with say 6 SELF buttons to 3 works fine - If the old buttons were still in scope at this stage, surely the animation value would stay at the highest ID, which would still be 6.
So. Plan of attack? What's the glaringly simple thing I'm missing here? Appreciate the time spent reading.