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 DBPro Corner / Array Compress Function

Author
Message
Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 30th Oct 2012 23:47
So, I've been trying to work on this function to compress this array I've designed into the smallest space possible.
So, for example:

Array
1=[Nothing]
2=[Nothing]
3=[Nothing]
4=Banana
5=[Nothing]
6=[Nothing]
7=Apple

Would become
1=Banana
2=Apple

Thus saving space and allowing me to remove items from any point along the array as long as I run compression afterwards.

Running it with strings, I thought this would work:



It should work for any length of pack$(). However, when placing a string in the 10th position, it doesn't move up the queue. Before this, my problem was it was copying endlessly. Any ideas as to a solution?

Oh, to avoid confusion, "t" is only to rerun the algorithm a set number of times.
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 31st Oct 2012 00:05
I find when removing elements from an array it is best to traverse the array in reverse.

ie:



Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 31st Oct 2012 22:22
Thanks man.
Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 6th Nov 2012 23:08
Hey, can someone show me how to do this without deleting array items? Because it's kind of important. I'm also trying to figure out how to remove redundant entries, and all in all it's giving me quite the headache. I'm planning on using this stuff for file control, you see. Having issues. Any help?
nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 7th Nov 2012 12:00
Quote: "Hey, can someone show me how to do this without deleting array items?"

I don't get what you mean but if you have a blank item, you cannot remove it without deleting it. This will displace all items following it:

DIM myARR(3)
myARR(0) = 5
myARR(1) = 0
myARR(2) = 0
myARR(3) = 3

In memory:
5|0|0|5|

After "Compress" thing:
5|5|

Quote: "I'm planning on using this stuff for file control, you see"

If you're referencing file names, then the best thing to do is simply delete the array-index containing the file that was deleted. Shifting will happen automatically.

RP Functions Library v1.0

Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 8th Nov 2012 00:39
Well, the redundant strings was for file control, not wanting to reuse names. For other reasons, though, notably inventory, I don't want to keep resizing an array, I want to just but something at the very end and have it slide up. That is,

Item1
(space)
(space)
Item2

Becomes

Item1
Item2
(space)
(space)

I do use the other way as well, but I'm thinking for my inventory system it would be better to just clear something than to delete and then recreate the array each time something happens to each item.
nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 8th Nov 2012 10:24
Kay, this is something I just boiled up. It's prolly the easiest way to shift in DBP. Hope there's no bugs as I haven't tested it much. Seems to work though.



RP Functions Library v1.0

My signature has not been erased by a mod.
Mr909
11
Years of Service
User Offline
Joined: 2nd Jun 2012
Location:
Posted: 8th Nov 2012 21:57
Thanks nonZero!
nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 9th Nov 2012 11:43
You're welcome.

RP Functions Library v1.0

My signature has not been erased by a mod.

Login to post a reply

Server time is: 2024-05-03 00:14:56
Your offset time is: 2024-05-03 00:14:56