How Lists Work - By CodeAlpaca

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

But since I have new upgrade sprites spawning in, it doesn’t update the future ones :frowning:

1 Like