[SOLVED] Tiny problem with a loop

SpookyBurger

  • Posts: 82
Hi, sorry if this question seems a little basic I'm not the best coder and this is my first loop attempt. 

I'm trying to do with it is to check every item in the "Story Variable Required" list and compare that item against the current "Story Event Tracker" number. I'm trying to find out if . . .

1) Item in List = Story Event tracker:  Then that's the Item Index I want for all my other functions
2) Item in List > Story Event Tracker:  Then I'll use the previous item index in the list by "-1 Item Tracker"
3) Item in List < Story Event Tracker:  I want to keep going through the list so "+1 Item tracker"


I'm using the "Item List Index Tracker" so what when I find a value I'll pass that number over to my function that prints delicious readable text.  Any help on how to fix this code or how to properly explain my "code" in the future would be appreciated.

« Last Edit: May 05, 2013, 01:58:27 pm by SpookyBurger »
Please try out my latest build of Patient 9 here.   http://www.stencyl.com/game/play/23179

captaincomic

  • *
  • Posts: 6108
I would recommend using a "repeat _ times" loop instead. With the "repeat until _" loop you have to be very careful to make sure that the condition actually becomes true, or you end up with an infinite loop that breaks the game.

Repeat "number of items in Story Variable Required" times, and the compare the item at "current loop count" with your "Store Event Tracker" to find which item is equal.

Photon

  • Posts: 2693
I would recommend using a "repeat _ times" loop instead. With the "repeat until _" loop you have to be very careful to make sure that the condition actually becomes true, or you end up with an infinite loop that breaks the game.

Repeat "number of items in Story Variable Required" times, and the compare the item at "current loop count" with your "Store Event Tracker" to find which item is equal.
Wait! Because your list indexing starts at zero, don't you need to look at the item at ["current loop count" - 1]?
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

captaincomic

  • *
  • Posts: 6108
"current loop count" also starts at 0. If you have a list with 3 elements, "current loop count" will go from 0 to 1 to 2.

SpookyBurger

  • Posts: 82
Thanks for the help guys!  I got it working just fine.  Here's what the function looks like after the modification.
Please try out my latest build of Patient 9 here.   http://www.stencyl.com/game/play/23179