Create Blank Array

Hello,

Attached is an image of a basic app I am creating.
I would like to create a blank array with an index count that is constantly changing. But for this example lets say a value of "5"
Then when a button is pressed change index "3" to a value of "99"

However I get an error that reads:
Replace list item: Attempt to replace item number 3 of a list of length 0: []
Note: You will not see another error reported for 5 seconds.

Where am I going wrong?

Array

First thing, I hope that by setting global Array1_Length = 5, you are not assuming that it would magically set the length of the list Array1 to 5. It's just some other global variable.
Second, you have to first assign a value to the nth index before replacing it.

yes you are right @Kaustubh_Rakhade

blocks

Hey Parva,

What if the "Array1_Length" is constantly increasing? Is there a way to make the list long enough given the "Array1_Length"?
Or would it be easier to just make a blank array with an excessive index count of 30 lines to accommodate the increasing array.

With the following blocks, you start your empty array.
Capture
You can use loop and insert item to increase the length of your array as you wish.

1 Like

Or you can just replace the whole variable's value.

Be aware that AI2 lists are not arrays, but are linked lists.
Proof:

For sparse keys like your sample, consider using a dictionary instead of a list.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.