Possible bug in foreach loop [not a bug, sorry]

All closed bug reports are moved here.

Post » Thu Mar 30, 2017 10:29 am

I'm looping over an array, adding + 2 to a global counter. As i'm doing it, i'm appending the counter to some text for debugging.

For some reason, it starts off fine going from 0 to 2, but then it suddenly only increments + 1 instead of + 2. Is there a bug in the foreach loops code or am I doing something wrong here?

I'm making a highscore board and looping over the array of data with 0/1 being name/score, 2/3 (the next name/score).

Image

You can see there the clear + 2, but it only adds 2 once, then adds 1 from then on.
Last edited by liamdawe on Thu Mar 30, 2017 10:50 am, edited 2 times in total.
B
4
S
2
G
5
Posts: 346
Reputation: 2,417

Post » Thu Mar 30, 2017 10:42 am

You dont add 2.

You add 2 to a value that is increasing by 1, hence the result is increasing by 1.

1 + 2 = 3
2 + 2 = 4
3 + 2 = 5
4 + 2 = 6

You see ?

Sprite.IID is the index that an instance of 'Sprite' has in a certain picklist.
Looping trough the picklist returns sprite.IID values from zero to to the total amount of objects in the picklist, increasing by 1.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Mar 30, 2017 10:49 am

Hah, well that will teach me for naming things in such a similar way won't it...

Many thanks for the help, much appreciated.
B
4
S
2
G
5
Posts: 346
Reputation: 2,417


Return to Closed Bugs

Who is online

Users browsing this forum: No registered users and 1 guest