Community

SCI Programming => SCI Syntax Help => Topic started by: Cloudee1 on January 28, 2016, 03:34:27 PM

Title: For loop wierdness
Post by: Cloudee1 on January 28, 2016, 03:34:27 PM
Just came across something really strange. I have a test room, and when I go into I have a for loop set up which is supposed to give me all of the inventory items.

Code: [Select]
  (for (= i 0) (<= i TOTAL_ITEMS) (++i)
    (send gEgo:get(i))
  )

Now this only gets me the first 13 items though. However, if I break this up into two for loops

Code: [Select]
  (for (= i 0) (<= i 10) (++i)
    (send gEgo:get(i))
  )
  (for (= i 11) (<= i TOTAL_ITEMS) (++i)
    (send gEgo:get(i))
  )

Then I get all 18 of the inventory items when I enter the room.
Title: Re: For loop wierdness
Post by: troflip on January 28, 2016, 04:15:48 PM
I tried doing the same thing, but with a DebugPrint that prints out the number (instead of getting an inventory item) and there was nothing wrong with the loop.
Title: Re: For loop wierdness
Post by: Cloudee1 on January 28, 2016, 05:26:23 PM
That's why I say, it is just weird.

For half a second, I thought maybe there were just too many parameters being sent in the get, but that can't be it, because it should just be 1 number getting sent each iteration... I am at a loss. Not that it matters in this scenario because as soon as I noticed it and broke it apart, I got everything.

Really just something that I thought I would point out. Someday someone may complain about a simple for loop failing and I'll be like yeah, I saw that too.
Title: Re: For loop wierdness
Post by: troflip on January 28, 2016, 05:37:14 PM
That's why I say, it is just weird.

For half a second, I thought maybe there were just too many parameters being sent in the get, but that can't be it, because it should just be 1 number getting sent each iteration... I am at a loss. Not that it matters in this scenario because as soon as I noticed it and broke it apart, I got everything.

Really just something that I thought I would point out. Someday someone may complain about a simple for loop failing and I'll be like yeah, I saw that too.

But it shouldn't fail. There's nothing about that that should fail. If there is a real bug here, we must find it. Can you attach a script resource that fails, or attach the disassembly or something?
Title: Re: For loop wierdness
Post by: Cloudee1 on January 28, 2016, 07:36:39 PM
Well now, that is just stupid.

Got home from work and copied everything over to the laptop. Now the initial for loop works flawlessly.

wierd.

Pulling up an older version of the game, last worked on with companion .3, opening now with .6 the for loop fails.... Updated the game.sh file which is where TOTAL_ITEMS is defined and compiled and it works fine... was it just a stupid oversight on my part.

Hmm, I don't know, but you're right, it works fine lol  :P
Title: Re: For loop wierdness
Post by: OmerMor on January 29, 2016, 12:11:37 PM
Your loop seems wrong or confusing.
if you have TOTAL_ITEMS items, then you should iterate from 0 to TOTAL_ITEMS-1 ( by using '<' operator instead of '<=').
Unless TOTAL_ITEMS really means MAX_ITEM_INDEX, in which case you should probably rename it.