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.

Author
Message
glint
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 22nd Jun 2004 20:54
When I create a 5 by 4 array, the array count function returns "29". What is going on? I had thought it would return a five or a twenty, but twenty-nine doesn't make sense
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 22nd Jun 2004 22:58
arrays are zero based

so the indicies go from 0 to 5 (which is count 6)
and 0 to 4 (which is count 5)


* DBP_NETLIB_v1.4 - w/VARIABLE WATCHER & CONSOLE! * Click Logo
glint
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 23rd Jun 2004 03:05
Where does the "29" come from, though? Six by four should return 24.
glint
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 23rd Jun 2004 03:06
Oops, I wrote six times four . . . I meant six times five. Still, six times five does not equal twenty-nine.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 23rd Jun 2004 04:25 Edited at: 23rd Jun 2004 04:26
0-29 is 30 items but its prolly highest in zero based index which is 29


* DBP_NETLIB_v1.4 - w/VARIABLE WATCHER & CONSOLE! * Click Logo
glint
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 23rd Jun 2004 21:37
Thanks, that makes sense.

I have another question, though. When I delete the first element of this 6 by 5 array, arraycount returns 28. That makes sense, but when I try to use the array it seems that the whole first four elements have disappeared.

Can someone explain?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 23rd Jun 2004 21:59
the each item in the first index holds 5 in the second...
lets call the x and y

array(x,y)

if you delete x 0 then you deleted 0,0/0,1/0,2/0,3/ and 0,4




* DBP_NETLIB_v1.4 - w/VARIABLE WATCHER & CONSOLE! * Click Logo
glint
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 24th Jun 2004 03:45
Thanks for helping me out - I just have one more question.

I wanted to use 2-d arrays for storing information on projectiles and AI entities. The ID of an object would be an x location on the array. All the variables for the object would be the y values corresponding to this x-value.

I set up this situation, but when I tried deleting elements they did not reorganize themselves in the right way. Values on the y axis kept getting bounced to separate x-values.

So I decided to use a one-dimensional array, just a long string of numbers where every x arrayspaces applies to a separate object.

" for a=0 to arraycount(array(0)) step x "

I have one question about this approach. Do arrays take up more memory depending on how they are arranged? Would a 1 X 1500 array bog things down more than a 50 X 30 array?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 24th Jun 2004 04:18
to be honest I don't know abot the mem usage - others here do so maybe they will happen by.

Another approach is to use a User Defined Type, then array the type

Type Projectile
ID as Integer
DataX as Float
DataY as Float
DataZ as Float
EndType

Dim Projectiles(99) as Projectile

this would yield 100 projectile types in an array 0-99. Each one would have their own copy of the Projectile definition:

Projectiles(0).ID =
Projectiles(0).DataX =
Projectiles(0).DataY =
Projectiles(0).DataZ =

Projectiles(1).ID =
Projectiles(1).DataX =
Projectiles(1).DataY =
Projectiles(1).DataZ =

...etc and so on

maybe that can be implemented for what you need here, or at some later time or project



* DBP_NETLIB_v1.4 - w/VARIABLE WATCHER & CONSOLE! * Click Logo
glint
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 25th Jun 2004 04:20
This sounds like exactly what I've been looking for - thanks!

I'm a little confused though; this is basically a one-dimensional array that references to separate lists of numbers, right?

If I were to delete Projectiles(2) from memory, would Projectiles(2).ID, Projectiles(2).DataX, Projectiles(2).DataY and Projectiles(2).DataX also be deleted?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 25th Jun 2004 04:44
when you act on Proj(2) which is the parent, then anything underneath it (all of its elements) will be affected. I am not usually in the habit of deleting and resizing arrays in dbp to be quite honest, so I don't even know if its possible with arrayed types. The reason I pointed out Types in the first place was it seemed more suited to what you were doing. Its really up to you to experiment and decide whats better for you and for optimal results.

good luck either way


* DBP_NETLIB_v1.4 - w/VARIABLE WATCHER & CONSOLE! * Click Logo
glint
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: the Synth
Posted: 25th Jun 2004 07:30
I plugged the system into an array, and the data was shifted appropriately when elements were deleted. As far as I'm concerned, that means I can go on with my project now. Thanks again!

Login to post a reply

Server time is: 2024-09-22 14:14:16
Your offset time is: 2024-09-22 14:14:16