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 count?

Author
Message
Mistrel
Retired Moderator
19
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 11th Oct 2006 18:25
"array count(array())" and "array count(x)" seem to do the same thing. The documentation uses "ARRAY COUNT(Array Name(0))".

Is it necessary to use "x" in "array count(x)" at all?

http://3dfolio.com
Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 11th Oct 2006 18:48 Edited at: 11th Oct 2006 18:49
No. Just do "array count(array())"

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 11th Oct 2006 20:10
...and remember it's not actually the count. It's the highest element number, but arrays start at 0. So if array count() is 10, you have 11 elements.



Mistrel
Retired Moderator
19
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 11th Oct 2006 22:54
Why would this be useful to call on anything larger than a one-dimensional array?

http://3dfolio.com
Profit
18
Years of Service
User Offline
Joined: 19th Feb 2006
Location: United States
Posted: 12th Oct 2006 00:08 Edited at: 12th Oct 2006 00:10
take this code for example



p.s. I'm not 100% sure that works, but I am 100% sure an elder could tell you this.

common people are walking in line.

Mitsu Fly Ride.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Oct 2006 22:02
No, that doesn't work, and it's not useful for multi-dimensional arrays. If it's needed and you can justify it, I could put something like this into a plugin.

Profit
18
Years of Service
User Offline
Joined: 19th Feb 2006
Location: United States
Posted: 12th Oct 2006 23:39
Sorry about that (I'm not a dbpro user).

common people are walking in line.

Mitsu Fly Ride.
Mr X
19
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 13th Oct 2006 20:35 Edited at: 13th Oct 2006 20:36
Quote: "Sorry about that (I'm not a dbpro user)."


Don't be, you tried to help.
Mistrel
Retired Moderator
19
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 13th Oct 2006 23:52
Quote: "No, that doesn't work, and it's not useful for multi-dimensional arrays. If it's needed and you can justify it, I could put something like this into a plugin."


I have some code here that works without it but it's more complicated than I would like. Every time I add new elements to a string array I have to +1 to another integer array so that I know how many strings there are for when I spit them out.

I wouldn't mind having a function to find the the number of elements in a multi-dimensional array. But I can't justify why I couldn't live without it other than, "it would be really nice".

http://3dfolio.com
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Oct 2006 17:58
Well, it's fairly easy to do I guess and the array plugin needs to be updated for new ideas I've had (Ooh, suspense!), so I'll add this in too. Keep an eye on the utility plugin pack, as I'll be adding it there.

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 15th Oct 2006 02:15
You can use a simple for/next loop to look for the last element that has information.

Mistrel
Retired Moderator
19
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 15th Oct 2006 02:59 Edited at: 15th Oct 2006 02:59
Quote: "Well, it's fairly easy to do I guess and the array plugin needs to be updated for new ideas I've had (Ooh, suspense!), so I'll add this in too. Keep an eye on the utility plugin pack, as I'll be adding it there."


Better support for dynamic multi-dimensional arrays would be great, IanM.

http://3dfolio.com
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Oct 2006 12:25
Ok, just let me know what you mean by 'Better support for ...' and I'll consider it.

Mistrel
Retired Moderator
19
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 15th Oct 2006 19:15 Edited at: 15th Oct 2006 19:21
I just found this and it would appear to be a very useful solution for a problem I've been having with array sizes:
http://forum.thegamecreators.com/?m=forum_view&t=38435&b=1

I can use global variables to keep track of how many elements are in each dimension of the aray and use var=var+1/-1, dim array(var1,var2), to resize them as needed.

A simpler method of changing the dimensions of multi-dimensional arrays by 1 without re-diming them would be nice, like a command to add to/remove from stack/queue for arrays larger than one dimension.

http://3dfolio.com
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Oct 2006 23:15
Well, the new ARRAY COUNT function I've written would help.

This would add an extra row and column to an existing array:


It's a bit verbose, so I'm open to any suggestions.

Login to post a reply

Server time is: 2024-11-27 05:35:37
Your offset time is: 2024-11-27 05:35:37