BASIC

Author Topic: Array of constants and objects  (Read 2744 times)

Offline aroldo

  • Mr. Polyvector
  • ***
  • Posts: 143
    • View Profile
    • APD Consulting, Inc.
Array of constants and objects
« on: 2011-Sep-11 »
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()
      ];
[a http://apd-games.com/][img http://apd-games.com/images/APDGames135.png][/a]
MacBook Pro OS X El Capitan
XCode Version 7
iPhone 6 running  iOS 9
iPad Mini running  iOS 7.1
Galaxy S5
Dell Latitude Windows 8 Enterprise
Palm Pre, Palm Pre2

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Re: Array of constants and objects
« Reply #1 on: 2011-Sep-12 »
DIMDATA array$[],"Value 1","Value 2",...
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3366
  • Integrated Brain
    • View Profile
Re: Array of constants and objects
« Reply #2 on: 2011-Sep-12 »
Or something more large, but works equal:

array$[0]="Value 1"
array$[1]="Value 2"
...
...
...
array$[8]="Game Over"


Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Array of constants and objects
« Reply #3 on: 2011-Sep-12 »
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:
Code: GLBasic [Select]
//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
 

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
Re: Array of constants and objects
« Reply #4 on: 2011-Sep-12 »
Someone give backslider some chocolate now!!!

Offline doimus

  • Dr. Type
  • ****
  • Posts: 284
    • View Profile
Re: Array of constants and objects
« Reply #5 on: 2011-Sep-12 »
It would be nice to have some sort of enumerted array support in GLBasic.

Something like:
Code: GLBasic [Select]
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:

Code: GLBasic [Select]
CONSTANT FIRST = 0
CONSTANT SECOND = 1
CONSTANT THIRD = 2
//.... few years in the future ...
CONSTANT BILLIONTH =  lulz

Offline okee

  • Dr. Type
  • ****
  • Posts: 324
    • View Profile
Re: Array of constants and objects
« Reply #6 on: 2011-Sep-12 »
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
« Last Edit: 2011-Sep-12 by okee »
Android: Samsung Galaxy S2 -  ZTE Blade (Orange San Francisco) - Ainol Novo 7 Aurora 2
IOS: 2 x Ipod Touch (1G)

Offline hardyx

  • Community Developer
  • Dr. Type
  • ******
  • Posts: 491
    • View Profile
Re: Array of constants and objects
« Reply #7 on: 2011-Sep-14 »
It would be nice to have some sort of enumerted array support in GLBasic.

Something like:
Code: GLBasic [Select]
DIMENUM arr[], FIRST, SECOND, THIRD

arr[FIRST] = 42
 

Or something like this, as used in Visual Basic:

Code: GLBasic [Select]
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.
« Last Edit: 2011-Sep-14 by hardyx »

Offline aroldo

  • Mr. Polyvector
  • ***
  • Posts: 143
    • View Profile
    • APD Consulting, Inc.
Re: Array of constants and objects
« Reply #8 on: 2011-Sep-15 »
Thanks Guys, :nw:

TYPE name worked fine!
[a http://apd-games.com/][img http://apd-games.com/images/APDGames135.png][/a]
MacBook Pro OS X El Capitan
XCode Version 7
iPhone 6 running  iOS 9
iPad Mini running  iOS 7.1
Galaxy S5
Dell Latitude Windows 8 Enterprise
Palm Pre, Palm Pre2