Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [SOLVED] Increasing an array length

Author
Message
dandrews
2
Years of Service
Recently Online
Joined: 26th Jun 2020
Location:
Posted: 19th Jun 2022 15:02 Edited at: 19th Jun 2022 15:06
It's my understanding that this code should increase and arrays length by one

In my code when it loops back it says the index is out of bounds

The author of this post has marked a post as an answer.

Go to answer

Steve Ancell
16
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 19th Jun 2022 15:26 Edited at: 20th Jun 2022 23:01
An empty array is -1 in length, in an array that contains something the first index starts at 0 and the last index is the same number as length. I hope this helps
smerf
17
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 20th Jun 2022 06:52
there is a neat trick i like to use before i access and array and that is to check its length before i use it



Steve Ancell
16
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 20th Jun 2022 15:09 Edited at: 20th Jun 2022 15:16
This post has been marked by the post author as the answer.
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:


Or use the insert method instead, all I did was modify the function AppendMyArray for this:

Login to post a reply

Server time is: 2022-10-03 02:40:35
Your offset time is: 2022-10-03 02:40:35