How Lists Work - By CodeAlpaca

How Lists work

By CodeAlpaca

One of Flowlabs most complex behaviors is the List. Users often find this behavior daunting to learn and ignore one of the most useful behaviors available. As one of the foremost experts in how the List behavior works, here is a detailed document with example images to help.


Before we begin, you must know how Lists work. A List is used to contain a set of values in a specific order, to help aid here is a visual example.

[CODE ALPACA,

DRAMA LLAMA,

HELLO,

WORLD]

Those are the items contained in the List, the words “CODE ALPACA” and “DRAMA LLAMA” are a single item even though it is separated by a space. In case you are confused this may help you understand it more.

Let’s only have 1 item to start. I will place a number before the word to indicate the Index (index is just the placement of an item within the list)

[(1) CODE ALPACA] This is a list containing a single item, if I was to add a value with the “Push” input (more on that later on) the list would now look like this

[(1) CODE ALPACA, (2) DRAMA LLAMA] another item has now been added to the List. This is the basic concept of how the list works, so now we will go more in-depth into how it works.

—-

Number List.

(The order in which I list the inputs are not the same as on the behavior, this is done to place similar features near each other to help make it easier to understand. I also refer to the Numbers inside of the List as “items”, that is because Number Lists and Text Lists are very similar and I wanted to reinforce the similarities between them)

|624x414.7688925855513

  • The Number List has several inputs attached to it, the first is the “Set” input. This input allows the user to Set a new List. (Note: You can only use the “Set” input with a List of the same type, ex. Number List → Number List or Text List → Text List) Setting a List works the same as if you were going to set a Number or Global.

(ex. If you had the List [1, 5, 10] you could use the “Set” input to make another List also contain the values [1, 5, 10])

  • The “All” input will output the List, similar to the “Get” input on a Number.
  • The “Push” input adds an item to the end of the List, this item is dependent on what the input was. If you had a list of [1, 2, 3, 4, 5] and inputted 4 into the “Push” input the List would now be [1, 2, 3, 4, 5, 4] *(This is similar to using the “+” input on the Text behavior)

(Note: This is what I was showing above with the example “[(1) CODE ALPACA, (2) DRAMA LLAMA]”)

  • The “Pop” input works in a similar manner to the “Push” input, but instead of adding an item to the end of the List, it removes one instead. If you had a list containing the number [1, 2, 3, 4, 5], inputting ANY number into it would remove the last item in the list, making it [1, 2, 3, 4].

(Note: The “Pop” output will output the item that is removed from the list, so in the example shown above the outputted value would be 5)

  • The “Join” input connects all the items in the list together with what ever the inputted value was. If you had a list containing the values [1, 3, 2, 4, 3] and inputted the value ”PIE” into the “Join” input, you would get an output of “1PIE3PIE2PIE4PIE3”. That may look a little confusing, but if I had used another value as the input it would look cleaner, like this “1,3,2,4,3”.

(Note: This should be pretty clear, but the outputted value is a Text value, meaning it will be purple)

  • The “One” input outputs the value at the selected index. What this means is if you input 3 to a list of [100, 150, 200, 300, 350] the output you would receive is 200. That is because it is the 3rd item in the list. If you input a value greater than the total number of items inside the list you would get the last item on the list as an output. (If you input a number less than 1 you would receive the first item in the list)

  • The “Find” input searches the list for the value that is inputted, if the item is not found you will receive an output of 0. So if you input 4 into the “Find” input of this list [100, 150, 200, 300, 350], you would receive an output of 0. If you instead inputted 150, you would get an output of 2 (This is the items place in the list)


Those are all of the features of a Number List. A Number List is no different than a Text List except for the fact that it can only accept Numbers, while a Text List can have both Numbers AND Text as input.

So now that you know how to use the #1 most useful behavior (excluding basic things like Number) you can finally give up the excuse of not using it! When I say this I’m not joking. Lists are soo powerful. And please share this with anyone who doesn’t know how to use lists, I don’t like looking at people use a ton of Routers, Filters, and Switches to solve a problem a single List could >:(

Example of how powerful Lists are

  1. When I eventually remake Alpaca Raceway using a single List I will be able to let the player create however many levels they want.
  2. With a single List, I could have several WRs for every map.
  3. I don’t want to spoil my current project, but with Lists I’m making probably the most advanced thing on Flowlab (personal opinion). I did start this project in august and forgot about it for a while because of the cotton jam, but now I’m back at it again!

If you have any other questions feel free to ask. (I do plan on making these for all of the other List behaviors)

14 Likes

Also, I start working on this on Oct 7th and literally only needed to finish a couple more lines but I forgot about it… Sorry.

6 Likes

I bookmarked this, lol.

Even after you’ve helped me with multiple examples including lists, I’m still learning how they work and this helps so much.

6 Likes

Lists are really useful, couldn’t do some of my examples without them.

5 Likes

Really awesome information here :slight_smile:

5 Likes

How to use List related Behaviors

By CodeAlpaca

Hello, now that you know what lists are you need to know how to use them. While the options that a List behavior contains are powerful, their main strength of them comes from how they can be used with the behaviors below.

  1. List Modify
  2. List Each
  3. List Count
  4. List Order

I will begin with the simplest first.


How to use List Count

This is a very simple behavior that tells you how many Items are inside the inputted List. For example, if you have a List containing [(1) Thank, (2) You, (3) For, (4) This]. If you input this the output will be the number 4. This is because there are 4 items in the List. I don’t often find myself needing this behavior and mostly use it as a way to convert the List output to a Number output.


How to use *List Each *

This one is slightly more complex, but it is still very simple. Let’s say you input the List [CodeAlpaca, JR01, Samuel (Pixel_Pizza), Grazer, DinoDev], the “Out” output will output 5 times (because there are 5 items in the List). The output will output the first item inside the List and continue to the last item inside the List

*(Note: The does NOT remove any of the items from the List)

When all the items have been outputted, the “Done” output will activate.


How to use List Order

List Order is pretty straightforward. It can do 3 things

Example List: [3 Eggs, 2 Cups of Sugar, 1 Cup of Chocolate, 12 ounces of Water]

  1. “Sort” the List
  2. “Reverse” the List
  3. “Shuffle” the List
  • Reversing the List does exactly what it sounds like. So the Example List would look like

[12 ounces of Water, 1 Cup of Chocolate, 2 Cups of Sugar, 3 Eggs]

  • Shuffle is also pretty striaght forward. It just moves around the items inside the list to random places. So the Example List might look like

[3 Eggs, 1 Cup of Chocolate, 12 ounces of Water, 2 Cups of Sugar]

  • Sort is slightly more complicated. If you have a Number List [56, 10, 33, 41, 47] you would get a list that looks like

[10, 33, 41, 47, 56]

If we used the Example List (Which is a Text List) we would get

[1 Cup of Chocolate, 12 ounces of Water, 2 Cups of Sugar, 3 Eggs]

HOWEVER, there is an option that says “Sort Text as Numbers”. What this means is that if there are Numbers at the beginning of the Text it will sort it as Numbers. So the Exmaple List would look like

[1 Cup of Chocolate, 2 Cups of Sugar, 3 Eggs, 12 ounces of Water]

*(VERY IMPORTANT Note: List Order both outputs the new list, but it also changes the List that was its original input to be the same as the output. You can prevent this from happening by clicking “Copy before modifying”.


How to use List Modify

The most complicated of the 4 behaviors, but if you learn how to use it, it’s actually quite simple.

The Example List will be [Give, Me, Expert, Guide]

*(VERY IMPORTANT Note: List Modify both outputs the new list, but it also changes the List that was its original input to be the same as the output. You can prevent this from happening by clicking “Copy before modifying”.

  • The “List” input is the list that you will be modifying. Adding a List to this input does NOT activate anything. It only sets the list that will be changed.

  • The “Index” input is which item in the list you will be modifying. Think of this as the same as the “One” input on the list. Whichever action you select (more on that later), this is where that will happen.

  • Value. This will cause the behavior to output the modified list.

Those are the inputs, now it’s time for the options that you can choose.

  1. “Insert into list”, will add the item you input into the “Value” to that spot within the List. So if you inputted “Please” with an “Index” of 1, using the Example List you would get

[Please, Give, Me, Expert, Guide]

  1. “Remove from list” does exactly what it sounds like. It removes that item. So if you inputted *ANYTHING with an “Index” of 3, using the Example List you would get

[Give, Me, Guide]

  1. “Replace item in list” switches out the item currently in that position with the input (The input given from the “Value” input). So if you inputted “CodeAlpaca” with an “Index” of 2, using the Example List you would get

[Give, CodeAlpaca, Expert, Guide]


That should be everything you need to know. If you require more information feel free to @me.

This may all seem complicated at first, but after using it for about a week or so you should be able to figure out how to make whatever you need (within reason) without too much trouble.

4 Likes

Here are some example problems for you to solve. These are relatively simple and if you come across a problem you can @me and I’ll try to explain what went wrong.

(From easiest to hardest… roughly.)

  1. A machine that will arrange numbers from highest to lowest.

  2. A machine that will remove the first item from a list once it reaches 10.

  3. A machine that will hold ONLY 5 passwords you enter into it.

  4. A simple 3-item inventory system

  5. A system that will copy block placements and be able to replicate them.

  6. A way to convert Number List to Text List (Must be able to hold several)

That last one is a bit more complicated, but it can be an incredibly useful tool to have if required.

5 Likes

Hey, so I can’t get a text to go into the Value input from List modify, Im trying to get this to be the text that replaces the other, but the text block can’t connect, I also can’t connect the outputs to the list itself, very confused, is there a way to input text value other than the text block?

1 Like

Make sure you’re using a Text List and not a Number List. Can you send a screenshot? I broke another computer charger so I won’t be able to show you a solution, but I should be able to explain it

Well, I have a set list with different values, then when I buy a upgrade, I find where that upgrade that just got purchased is, the replace it with another upgrade

So for example you want 3 upgrade options, and then you choose 1 correct? And then it is replaced with a new item?

1 Like

Well, there are 3 different upgrade types, each with 4 different options, when you level up, a block spawns 3 random types, and those sprites then generate one out of the four upgrades to show, and I want for a specific one to be replaced when clicked
What I did was find that specific upgrade, out put where it was and tried to use the list modify thing to replace it with something else, but I had line connection issues

1 Like

I think the easiest solution for you would be (this is just in my head, I don’t have a computer rn so I don’t actually have the code):

  1. Create 4 lists.

  2. 3 lists contain 4 of their respective item classes (example) [1,2,3] [101,102,103] [201,202,203] (make sure these lists are Shuffled)

  3. A fourth list contains 1 item from each list (example) [2, 103, 203]

  4. When an is chosen, remove it from the list. This should just be a simple index check.

  5. When an item is removed, you know what index it was from. So just pop the corresponding list (via a router) and add it to that fourth list with a List Modify (make sure the index is the same)

  6. This will make sure that the list will always be laid out in the same way
    (Example) [ATK+2,DEF+3,SPE+6] —> [ATK+2,DEF+1,SPE+6]

—-

Did you want it so it was random? So you could get [ATK,ATK,DEF]?

If I update one list, will it update all future ones?

1 Like

With List Modify? It depends if you have “Copy before modifying” selected

1 Like

so if I have copy before modify it updates all future lists?

1 Like

Let’s say you have list
[1,2,3,5,8]
If you put it in a List Modify to remove index 4
The output list will be [1,2,3,8], but so will the input list.

If Copy Before Modifying is selected, only the output list will change

2 Likes

I should make an updated guide, I explained lists very poorly and over complicated things in this.

2 Likes


Looking at the code above, it should work, right? So once I trigger something, The (yellow arrow) text list finds the upgrade from the upgrade holder (white arrow)and outputs its Index into list modify, (blue arrow), and then the text(Red arrow, and I forgot to connect to “get”) puts a value to replace the one from the index. And the list input from the list modify block sets which list it edits

1 Like

YESSSSS, it works!!!

1 Like