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() Question - DBP

Author
Message
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 25th Feb 2006 17:19
Im trying to find a way to get the amount of index's in each level of an array, I searched around and found Array Count(). It sounded like what I needed but it's giving strange effects:

Example of what I wanted to do:

DIM Test(2,3,4)

This creates an array with 2 main index's, each with three sub index's, each sub index having 4 sub-sub index's. I'm trying to calculate how many index's there are for the middle term (3).

Doing something like this works:



But only for an array with one index level. I tried doing this:



... to attempt to return the amount of index's in the second level of index's (which would be 3) And got 11 instead of the desired 3.

Then I tried:



...with no luck, still returning 11.

So basically how would I find the amount of index's in the second level of the Test Array (which would be 3)?

Im sure this is right under my nose sorry if it's been answered before I did some searched and found nothing,

Thanks,
- RUC'

Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 25th Feb 2006 18:11
Array Count gets the size of the array subtracted by 1. So 2x3 is actually 3x4. That equals 12 then subtract that bu 1 equals 11. Thats how array count works and thats why your always getting 11.

But I'm not sure how to fix your problem but thats why its happening but shouldn't you know what is the indexs are already.

NARUTO IS THE NINJA.....not really
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 25th Feb 2006 18:47 Edited at: 25th Feb 2006 18:57
Ah I see. As to the knowing the indexs already yes I do know them in the beginning but the user has the ability to change them, Im working on a vehicle plugin and each vehicle is given properties, the properties are then stored in a multidminsional array (The first level is the object number, the second level is an entry number (dont ask) and the third index is the entry's properties. I know I should be using types but this system is working exactly how I want it too. What I need to do is figure out how many entries there are for each vehicle, and how many vehicles there are total. I could create another array containing this information but if I can use a command to find how many there are I'd prefer it.

<edit>

Explaining a little more on the system:

To add an entry the programmer calls the AddEntry function. An entry is basically a door to the vehicle; where the user can get into the vehicle. So the user could create, for example for a car, two entries. One for the driver seat and one for the passenger. The programmer specified the object the entry's should be added to, an entry ID number for later use, and some other properties. These are stored like so:

Vehicle(Parent, Entry, 10)

Parent is the parent object (so if object 2 was the car, the parent would be 2.). Entry is the entry id, this allows for multiple entries to be created per car, and also allows for multiple entries with the same number to be used without affecting each other. The third index holds about 10 slots for information about the entry (who can enter, any animations to be played, how close the user has to be to the entry point to enter, etc.)

Another function allows the user to find the Dynamic's (a Dynamic is a user-controlled object that can/will at some point occupy an entry to control the vehicle) Parent. The Dynamic's Parent is simply what objec tthe Dynamic is being controlled by. So, if the Dynamic is in a vehicle the Dynamic Parent returned is the Object Number of the vehicle the user is in. If the user isn't inside a vehicle, the Dynamic's object number is returned. This is useful for switching between controlling the dynamic and the car.

What I need to do for this function is use a For/Next loop to check each vehicle's Entry Slot to see if the Dynamic is occupying it. If so I can return the Vehicle Number the Dynamic is occupying.

The problem lies here, I need to know how many Vehicles and Entries have been created, so I can modify the For/Next loop to repeat that many times.

Any help appretiated,
- RUC'

Login to post a reply

Server time is: 2024-11-27 03:47:10
Your offset time is: 2024-11-27 03:47:10