Author Topic: For loop wierdness  (Read 3879 times)

0 Members and 1 Guest are viewing this topic.

Offline Cloudee1

For loop wierdness
« 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.


Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline troflip

Re: For loop wierdness
« Reply #1 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.
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Cloudee1

Re: For loop wierdness
« Reply #2 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.
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline troflip

Re: For loop wierdness
« Reply #3 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?
Check out my website: http://icefallgames.com
Groundhog Day Competition

Offline Cloudee1

Re: For loop wierdness
« Reply #4 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
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline OmerMor

Re: For loop wierdness
« Reply #5 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.


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.129 seconds with 23 queries.