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.

AppGameKit Classic Chat / [SOLVED] Array, Insert After

Author
Message
Nieb
10
Years of Service
User Offline
Joined: 13th May 2014
Location: Lurking
Posted: 27th Feb 2023 13:37 Edited at: 27th Feb 2023 13:39
Can we make it so Thing.insert(me, index) is smart enough to add a new index if index is length+1?

For example, so we don't have to do this:


Heck, we could go a step further and have it extend the array as far as needed for the insert.
Example:

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

Go to answer

Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 27th Feb 2023 17:18
AGK already does that.
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 27th Feb 2023 17:21 Edited at: 27th Feb 2023 17:21
If you have 10 things in an array the length will show as 9 with 0 being the first. An empty array has a length of -1 (minus one)
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 27th Feb 2023 17:44 Edited at: 27th Feb 2023 17:56
Quote: "AGK already does that."

i think you missed the point. when using the index parameter:

...will crash while i believe Nieb would like AppGameKit to automatically check if the current length of the array can accomodate the specified insert location. if not, automatically resize so that it can.

@nieb, i can see the value in what you're looking for. any feature request you might post would fit nicely in future array-related updates. in the meantime, we can write our own work-around realitvely easily, at least
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 27th Feb 2023 18:59
This post has been marked by the post author as the answer.
You could just say Thing.length = 9

Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 27th Feb 2023 21:42
@Virtual Nomad:
I had a feeling I was missing something, I didn't fully understand the question.
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 27th Feb 2023 21:44
I personally prefer to use Thing.length = 5 rather than Thing AS INTEGER[5] That's probably why I didn't fully understand.

Login to post a reply

Server time is: 2024-11-23 08:18:54
Your offset time is: 2024-11-23 08:18:54