How can I implement an array of constants like this one in Javascritpt:
this.GAMESTATE ={TEST1:0,TEST2:1,TEST3:2,TITLE:3,DEMO:4,START:5,
PLAYING:6,EXPLODING:7,ENDLEVEL:8,GAMEOVER:9
};
And and Array of objects like this on in Javascript;
this.stars = [
new this.star(), new this.star(), new this.star(), new this.star(), new this.star(), new this.star()
];
DIMDATA array$[],"Value 1","Value 2",...
Or something more large, but works equal:
array$[0]="Value 1"
array$[1]="Value 2"
...
...
...
array$[8]="Game Over"
Quote from: aroldo on 2011-Sep-11
And and Array of objects like this on in Javascript;
this.stars = [
new this.star(), new this.star(), new this.star(), new this.star(), new this.star(), new this.star()
];
For this you should use:
//the star "class"
TYPE TStar
//Attributes and Functions
ENDTYPE
LOCAL stars[] AS TStar //declare the star array
//push 100 stars into the array
FOR i=0 TO 99
LOCAL star AS TStar //temp star
//set the position of the star or so...
DIMPUSH stars[], star //put the temp star into the array
NEXT
Someone give backslider some chocolate now!!!
It would be nice to have some sort of enumerted array support in GLBasic.
Something like:
DIMENUM arr[], FIRST, SECOND, THIRD
arr[FIRST] = 42
//..is the same as...
arr[0] = 42
Currently, this can be done with constants/globals but it gets really messy very quickly due to global nature of those values and lots of space needed for pointless definitions:
CONSTANT FIRST = 0
CONSTANT SECOND = 1
CONSTANT THIRD = 2
//.... few years in the future ...
CONSTANT BILLIONTH = lulz
re backsliders code, just for the record the
LOCAL star AS TStar would be declared 100 times in the loop
Quote
//the star "class"
TYPE TStar
//Attributes and Functions
ENDTYPE
LOCAL stars[] AS TStar //declare the star array
//push 100 stars into the array
LOCAL star AS TStar //temp star moved out of the loop
FOR i=0 TO 99
//set the position of the star or so...
DIMPUSH stars[], star //put the temp star into the array
NEXT
Quote from: doimus on 2011-Sep-12
It would be nice to have some sort of enumerted array support in GLBasic.
Something like:
DIMENUM arr[], FIRST, SECOND, THIRD
arr[FIRST] = 42
Or something like this, as used in Visual Basic:
ENUM Fruits
Apple = 1,
Orange,
Banana
ENDENUM
DIM fr AS Fruits
fr = Orange
This could create CONSTANTs instructions with the values. When you don't assign a value to the constant, takes the previous value +1.
Thanks Guys, :nw:
TYPE name worked fine!