Advertisement

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

Started by October 09, 2008 04:06 AM
2 comments, last by jal_ 16 years, 1 month ago
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?
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;    }}
Advertisement
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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Ah, thanks!

This topic is closed to new replies.

Advertisement