Jump to content
  • Advertisement
Sign in to follow this  
jal_

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

This topic is 3638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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 = 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 = 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!