Sign in to follow this  
jal_

(script coding) Declaring an array inside a class property?

Recommended Posts

I'm feeling a bit dumb by making this question, but I don't find what's the correct sintax to do it, if it's possible. This is all script coding, no lib issue. What I want to do is just something like: class myClass { uint[] myArray( 32 ); myClass() {} ~myClass() {} } Is it possible, and if so, what's the correct sintax?

Share this post


Link to post
Share on other sites
Would this be correct?


const int MAX_RACE_CHECKPOINTS = 32;

class cPlayerTime
{
uint[] checkPointTimes;

cPlayerTime()
{
uint[] checkPoints( MAX_RACE_CHECKPOINTS );

this.checkPointTimes = checkPoints;
}

~cPlayerTime() {}

void resetRace()
{
for( int i = 0; i < MAX_RACE_CHECKPOINTS; i++ )
this.checkPointTimes[i] = 0;
}
}

Share this post


Link to post
Share on other sites
The correct way of doing it would be:


const int MAX_RACE_CHECKPOINTS = 32;

class cPlayerTime
{
uint[] checkPointTimes;

cPlayerTime()
{
checkPointTimes.resize(MAX_RACE_CHECKPOINTS);
}

~cPlayerTime() {}

void resetRace()
{
for( int i = 0; i < MAX_RACE_CHECKPOINTS; i++ )
this.checkPointTimes[i] = 0;
}
}


When I implement static arrays, you'll be able to define the size of the array directly in the declaration of the property.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this