How can I make a For Each loop?

I have a text list with a varying number of items in it.

I want to

  1. count how many items there are (Text List Count works for this)
  2. Send each item in the list to a separate text block.

For example, I have the list “Apples are great, Oranges are ok, Pears are bad”
and I want to end up with three different separate text blocks: “Apples are great”, “Oranges are ok”, and “Pears are bad”.

I tried to send the text list count out to a filter, and then use pass-fail to loop back and activate ALL again if the count was still larger than 0 and pop the next item, until it had sent out all items, but this somehow creates an infinite loop even though it should stop when it hits zero.

I’ve tried a bunch of different things but there’s always some issue, some output that isn’t possible with that block or something else…there must be some standard way people set up this sort of thing in FlowLab?


I’d set up a “For” loop bundle, the one I made looks like this
Count is how many times you want the loop to iterate; for your case it would be the length of the list from “List Count.”
In activates the loop.

Out outputs the which iteration of the loop it is on, ex; 1,2,3,4,5,6… For your purpose this could go into the “one” input on the list. It would output each item in the list.

Done outputs when the loop is done iterating

inside, the main code is just the repeater behavior. Every time the repeater outputs, it increases a number by one. The zero at the top left just resets the counter every time you start the whole function.

Here is an example code. I’m not sure why you want each item to go to a different list, but to do that you would need to use switches of some sort. Using a router to turn the switches on and off would probably work best. The downside of this is the game will be limited to how many text behaviors you manually put in.

Anyway, the “for loop” would work with however many items you have. Let me know if you have any other questions!

1 Like

I’m still working on this dialogue tree bundle thing, and I have a list of options for a certain prompt, which should each be a label for a different button. For example “Are you hungry?” needs to spawn three buttons, “Yes”, “No”, and “Maybe” and I currently have all those collected in a list of these answer options.

Thank you for your answer, this helps get me a bit further forward again! This is all a bit on the edge of my coding abilities, but I think I’m actually getting somewhere step by step.

1 Like

Not too far from what I was working on!

1 Like