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.

DarkBASIC Professional Discussion / Expand/shrink array without loosing content

Author
Message
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 14th Jun 2012 12:28
Can I expand an array or shrink it without loosing any of its content (except from when I shrink it to less, just keep the remaining of the array content)

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 14th Jun 2012 13:14
Nevermind I iterate through the original array, store it in a temporary array and load it back in to the new resized array. I use Array index valid if the new array is larger than the original.

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Jun 2012 13:39
The answer to your original question is yes, you can increase the array without losing the current data.

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th Jun 2012 14:22
This is a similar question...

I need to make an array, and store 13 limb positions in it. But then I need to make a new object with 13 more limb positions, and then add those to the array. There is no size limit to this array. So I need an array like this...

Dim Limb(Infinity,13)

The reason for infinity is because it is speed limited, and in 100 years I still want the program to work. So the Objects keep multiplying until the FPS drops to about 20.

I have always put DIMs at the beginning of my program as they allocate space, so what's the best way to do that?

Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 14th Jun 2012 14:43 Edited at: 14th Jun 2012 14:43
Quote: "Can I expand an array"

ARRAY INSERT AT BOTTOM or redim it

Quote: "or shrink it without loosing any of its content"

redim it using DIM command or ARRAY DELETE ELEMENT

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th Jun 2012 15:12
How do you jump around these arrays by index? All I can see is step forward, and step back 1.

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Jun 2012 17:33
Quote: "I have always put DIMs at the beginning of my program as they allocate space, so what's the best way to do that?"


Every time you DIM the array, or ADD TO QUEUE, ARRAY INSERT etc..., it creates new space, moves everything into the new space, then deletes the old.

On this basis, you should add new elements in chunks. Depending on how many you are likely to add and how quickly, this will vary. I have arrays where I add 100 elements at a time, I have a variable which stores the highest used element at any given time. Some people save this value in element 0, and start the actual data at element 1

Quote: "How do you jump around these arrays by index?"


myCurrentLimb = MyArray(15).limbNumber

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th Jun 2012 18:30 Edited at: 14th Jun 2012 19:06
This is the problem that I have, I can't read that, because it's all over the place...

myCurrentLimb = MyArray(15).limbNumber

Is that index 15?

So

MyObject(15).Limbnumber(x)
MyObject(15).Limbnumber(y)
MyObject(15).Limbnumber(z)

or

MyObject(15,1).Limbnumber
MyObject(15,2).Limbnumber
MyObject(15,3).Limbnumber

Where do I get the X/Y/Z from?

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Jun 2012 19:06 Edited at: 14th Jun 2012 19:07
Written without syntax checking, but should be correct...



Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th Jun 2012 19:10 Edited at: 14th Jun 2012 20:28
My previous example was not very good...

This would be the standard DIM..


....ArrayName,Object,Limb,X/Y/Z,Scale,Energy
DIM Particle(Infinity,13,5)

So I get this, which doesn't look right...




... and where scale, and energy go I have no idea.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Jun 2012 20:27
A bit of confusion there between Object and Objects perhaps?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 14th Jun 2012 20:29 Edited at: 14th Jun 2012 20:40
Quote: "A bit of confusion there between Object and Objects perhaps? "


Yeah that's true. I hate types, they make me feel ill. I have to learn them for my project though. My last attempt, I had to go to bed. I've put this off for about a year now, so it's time to try again.

So I'm not sure about using a comma ,

And I suppose that this is scale, and energy...
Object(Object,Limb).scale = rnd(100)
Object(Object,Limb).energy = rnd(100)

Login to post a reply

Server time is: 2026-07-08 01:52:42
Your offset time is: 2026-07-08 01:52:42