So i was building a {DO WHILE > FOR > FOR} loop to search a two dimensional array using a seperate counter variable for each FOR loop that corresponds to the index of the array value I would then do a compare with. The WHILE was controled with a bool. Standard enough stuff.
When the conditions for 'hooray I've found it' were met, I was expecting to be able to use the counter variable values at that point to reference the array.
However, I proved (by assigning the values of the counter variables to seperate, additional variables at the point before exiting the loop) that the counter variables get changed to the max value you set for the counter when you exit the loop. This is done without any documented indication.
This breaks about 40 yrs of how-loops-treat-counters history. What the fuck?
You should never use those variable outside of the loop anyway ?? I dunno about 40 years of loop history but you should use them right inside the loop when you found smt.
AwardTerritoryOnBunkerBuild
Events
Unit - Any Unit Enters TTY_00_00
Unit - Any Unit Enters TTY_00_01
Unit - Any Unit Enters TTY_00_02
Unit - Any Unit Enters TTY_00_03
......
Unit - Any Unit Enters TTY_09_07
Unit - Any Unit Enters TTY_09_08
Unit - Any Unit Enters TTY_09_09
Local Variables
BOOL_RegionIdentified = false <Boolean>
INT_SearchTerritoryIndexX = 0 <Integer>
INT_SearchTerritoryIndexY = 0 <Integer>
------- Second set of indices needed cos Blizztard's FOR loops mess with counter variables when the loop exits; their values aren't preserved so they need copying before exxiting the loop
INT_IdentifiedTerritoryIndexX = 0 <Integer>
INT_IdentifiedTerritoryIndexY = 0 <Integer>
Conditions
(Unit type of (Triggering unit)) == GoCraft Bunker
Actions
General - While (Conditions) are true, do (Actions)
Conditions
BOOL_RegionIdentified == false
Actions
General - For each integer INT_SearchTerritoryIndexX from 0 to 9 with increment 1, do (Actions)
Actions
General - For each integer INT_SearchTerritoryIndexY from 0 to 9 with increment 1, do (Actions)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
REGION[]_Territories[INT_SearchTerritoryIndexX][INT_SearchTerritoryIndexY] == (Triggering region)
Then
Variable - Set INT_IdentifiedTerritoryIndexX = INT_SearchTerritoryIndexX
Variable - Set INT_IdentifiedTerritoryIndexY = INT_SearchTerritoryIndexY
Variable - Set BOOL_RegionIdentified = true
Else
This might help explain, I was talking to a mate about it:
19:22 - DJ Splendid: can you think of any language anywhere that resets a counter when a loop exits?
19:22 - DJ Splendid: NO! they leaqve the variable alone so you can use it!
im not sure, but i know that this "for each int" loops get fucked up during compiling getting incredibly complicated. you yould try to use 3 while loops instead and increase the variable manually.
PS: for each int loops should NEVER be used in gui cause they fuck up that badly during compiling. i think i will only use while loops and pick each integer loops from now.
Actually, is it me or does your while loop makes no sense?
a) if your 2 for loops never find a match, your while loop will run forever!
b) if your 2 for loops do find a match, your while loop will only loop once.
So you do not need that while loop at all. And of course the for loops do not perserve the counter. There's no break. Assigning a boolean to true does not break the for loops. So it'll always count to the max.
@DJSplendid: Go
You should never use those variable outside of the loop anyway ?? I dunno about 40 years of loop history but you should use them right inside the loop when you found smt.
@DJSplendid: Go
post the code pls.
AwardTerritoryOnBunkerBuild
Events
Unit - Any Unit Enters TTY_00_00
Unit - Any Unit Enters TTY_00_01
Unit - Any Unit Enters TTY_00_02
Unit - Any Unit Enters TTY_00_03
......
Unit - Any Unit Enters TTY_09_07
Unit - Any Unit Enters TTY_09_08
Unit - Any Unit Enters TTY_09_09
Local Variables
BOOL_RegionIdentified = false <Boolean>
INT_SearchTerritoryIndexX = 0 <Integer>
INT_SearchTerritoryIndexY = 0 <Integer>
------- Second set of indices needed cos Blizztard's FOR loops mess with counter variables when the loop exits; their values aren't preserved so they need copying before exxiting the loop
INT_IdentifiedTerritoryIndexX = 0 <Integer>
INT_IdentifiedTerritoryIndexY = 0 <Integer>
Conditions
(Unit type of (Triggering unit)) == GoCraft Bunker
Actions
General - While (Conditions) are true, do (Actions)
Conditions
BOOL_RegionIdentified == false
Actions
General - For each integer INT_SearchTerritoryIndexX from 0 to 9 with increment 1, do (Actions)
Actions
General - For each integer INT_SearchTerritoryIndexY from 0 to 9 with increment 1, do (Actions)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
REGION[]_Territories[INT_SearchTerritoryIndexX][INT_SearchTerritoryIndexY] == (Triggering region)
Then
Variable - Set INT_IdentifiedTerritoryIndexX = INT_SearchTerritoryIndexX
Variable - Set INT_IdentifiedTerritoryIndexY = INT_SearchTerritoryIndexY
Variable - Set BOOL_RegionIdentified = true
Else
----------------------------
-----------------------------
This might help explain, I was talking to a mate about it:
19:22 - DJ Splendid: can you think of any language anywhere that resets a counter when a loop exits?
19:22 - DJ Splendid: NO! they leaqve the variable alone so you can use it!
@DJSplendid: Go
im not sure, but i know that this "for each int" loops get fucked up during compiling getting incredibly complicated. you yould try to use 3 while loops instead and increase the variable manually.
PS: for each int loops should NEVER be used in gui cause they fuck up that badly during compiling. i think i will only use while loops and pick each integer loops from now.
Whoa, they do?
Thanks for the heads up, Mille25, if they start misbehaving I'll replace the logic using WHILEs.
Actually, is it me or does your while loop makes no sense?
a) if your 2 for loops never find a match, your while loop will run forever! b) if your 2 for loops do find a match, your while loop will only loop once.
So you do not need that while loop at all. And of course the for loops do not perserve the counter. There's no break. Assigning a boolean to true does not break the for loops. So it'll always count to the max.
It's you ;)