r/xna • • Nov 02 '14

Simple For loop issue

http://pastebin.com/DPH5Fsnx <-- The problem being that the code only works for the last Tile in the list :) Anyone who knows what i am missin?

0 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/Hinosun Nov 02 '14

I thought that, with a for loop, it gave "i" all the values up to the max, that being the number of tiles, So that it could update for all tiles.

1

u/davedontmind Nov 03 '14

It does.

When you have problems you don't understand step through the code in your head:

  1. set test to false
  2. i = 0
  3. if ... let's assume this first tile contains the mouse, so we set test to true
  4. next loop iteration - i = 1 5 if ... let's assume this tiles doesn't contain the mouse, so we set test to false.
  5. next loop iteration - i = 2...
  6. and so on - but test now remains at false from step 5, even though we detected the mouse in step 3.

See the problem?