Both of these snippets do the same thing. Always keep in mind that when it is empty the length is -1, when there is one item the length is 0 so the highest address will also be zero.
Just simply add to the length and insert the item into what ever the length is but use that as the address.
You could do this:
global myArray as integer[]
AppendMyArray(1)
AppendMyArray(2)
AppendMyArray(3)
AppendMyArray(4)
AppendMyArray(5)
do
ShowSpriteIDs()
Sync()
loop
function AppendMyArray(spriteID as integer)
myArray.length = myArray.length + 1
myArray[myArray.length] = spriteID
endfunction
function ShowSpriteIDs()
print("ArrayLength: " + str(myArray.length))
for i = 0 to myArray.length
print("Array Address " + str(i) + ": SpriteID = : " + str(myArray[i]))
next i
endfunction
Or use the insert method instead, all I did was modify the function AppendMyArray for this:
global myArray as integer[]
AppendMyArray(1)
AppendMyArray(2)
AppendMyArray(3)
AppendMyArray(4)
AppendMyArray(5)
do
ShowSpriteIDs()
Sync()
loop
function AppendMyArray(spriteID as integer)
myArray.insert(spriteID)
endfunction
function ShowSpriteIDs()
print("ArrayLength: " + str(myArray.length))
for i = 0 to myArray.length
print("Array Address " + str(i) + ": SpriteID = : " + str(myArray[i]))
next i
endfunction