multidimensional arrays and types

Previous topic - Next topic

Richard Rae

Is it possible to declare multidiensional arrays and use types with it


type blah

x
y
endtype

  dim array[n][n] as blah

evey time i try i get an error,am i doing something wrong?

Neurox

Yes,
It's very simp'le ;-)

----------------------------
TYPE menu
   x
   y
ENDTYPE
GLOBAL mnu[] AS menu
DIM mnu[10][4]
----------------------------

Bye bye,
Neurox
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

Richard Rae

thanks for the quick reply.most appreciated.

FutureCow

I've just tried to combine this code with the example code for the findpath command and have had the following errors


_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.2009.013 - 3D, NET
Wordcount:18 commands

compiling:
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:72:9: invalid digit "9" in octal constant
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:105:9: invalid digit "9" in octal constant
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:137:9: invalid digit "8" in octal constant
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:138:9: invalid digit "9" in octal constant
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:171:9: invalid digit "9" in octal constant
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:202:9: invalid digit "9" in octal constant
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:203:9: invalid digit "9" in octal constant
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:204:9: invalid digit "9" in octal constant
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:236:9: invalid digit "8" in octal constant
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_tempg.cpp:237:9: invalid digit "9" in octal constant
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:15: error: no matching function for call to `DIM(__GLBASIC__::FloorTileType&, DGInt&, DGInt&)'
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:694: note: candidates are: void __GLBASIC__::DIM(__GLBASIC__::DGIntArray&, DGNat, DGNat, DGNat, DGNat)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:695: note:                 void __GLBASIC__::DIM(__GLBASIC__::DGNatArray&, DGNat, DGNat, DGNat, DGNat)
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:30: error: no match for call to `(__GLBASIC__::FloorTileType) (DGInt&, DGInt&)'
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.0 sec. Time: 21:40
Build: 0 succeeded.
*** 1 FAILED ***

--------------------
Here's my code
Code (glbasic) Select

TYPE FloorTileType
XLoc // Pixel value of the middle of the tile
YLoc // Pixel value of the middle of the tile
ENDTYPE

GLOBAL NumXTiles=32
GLOBAL NumYTiles=8
GLOBAL LevelTile AS FloorTileType
DIM LevelTile[NumXTiles][NumYTiles]

DIM FloorTilesAStar[NumXTiles][NumYTiles] // 10 = no, 100=yes - used for A* algorithm

DIM AStarSolution[0]

RESTORE FloorTileXLocs
FOR x=0 TO NumXTiles-1
FOR y=0 TO NumYTiles-1

FloorTilesAStar[x][y]=10 // Assign a value to the floor tile for the a* algorythm. 10 = empty tile, 20 = full

// Read pixel coordinates for the middle of each tile
READ LevelTile[x][y].XLoc
NEXT
NEXT

FoundPath = FINDPATH(FloorTilesAStar[],AStarSolution[],0.5, 0, 7, 31, 3)
FOR i=0 TO BOUNDS(AStarSolution[],0)-1
x=AStarSolution[i][0]
y=AStarSolution[i][1]
DRAWRECT x-10,y-10,20,20,RGB (255,255,0)
NEXT

SHOWSCREEN
MOUSEWAIT



STARTDATA FloorTileXLocs:
DATA 119,139,155,174,193,211,228,247,267,286,302,322,343,360,378,396,417,434,455,473,491,510,528,549,565,586,604,622,641,659,678,694
DATA 100,118,137,159,178,198,216,237,259,279,297,315,337,355,377,398,415,434,458,474,495,515,537,554,575,595,613,633,652,677,690,713
DATA 077,098,119,138,160,184,204,224,245,267,287,310,330,353,373,396,416,439,460,479,502,524,546,566,588,609,631,652,674,697,718,737
DATA 047,074,096,118,140,169,189,212,235,256,278,302,325,345,375,394,418,441,462,484,509,533,556,579,601,627,649,672,695,718,741,760
DATA 020,043,068,093,119,140,161,191,216,240,268,295,320,342,370,395,420,443,467,491,518,542,568,595,622,646,670,697,719,745,770,789
DATA 000,013,036,065,093,118,146,172,202,225,254,283,309,335,365,390,418,446,477,500,525,556,584,612,641,667,694,720,750,778,796,798
DATA 001,001,002,029,059,089,117,150,177,211,241,270,302,331,355,390,422,452,479,511,537,572,599,633,660,694,724,755,782,797,797,797
DATA 001,001,001,001,020,048,090,119,154,190,221,253,287,318,350,390,423,454,487,520,559,588,621,657,691,723,758,788,797,797,797,797
ENDDATA

FutureCow

I couldn't figure out what was going on as everything looked right to me, and I couldn't pinpoint from the errors where it thought the 9 and 8 in an octal number were.

Thanks very much Ocean!

FutureCow

Okay, I've cut down the code and I'm still having errors (though removing the 0's got rid of the octal ones).

Errors :

_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.2009.013 - 3D, NET
Wordcount:1 commands

compiling:
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\DOCUME~1\Shane\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:15: error: no matching function for call to `DIM(__GLBASIC__::FloorTileType&, DGInt&, DGInt&)'
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:694: note: candidates are: void __GLBASIC__::DIM(__GLBASIC__::DGIntArray&, DGNat, DGNat, DGNat, DGNat)
C:/Program Files/GLBasic/Compiler/platform/Include/glb.h:695: note:                 void __GLBASIC__::DIM(__GLBASIC__::DGNatArray&, DGNat, DGNat, DGNat, DGNat)
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.0 sec. Time: 21:06
Build: 0 succeeded.
*** 1 FAILED ***

Code (Version: 6.164)
Code (glbasic) Select

TYPE FloorTileType
XLoc // Pixel value of the middle of the tile
YLoc // Pixel value of the middle of the tile
ENDTYPE

GLOBAL NumXTiles=32
GLOBAL NumYTiles=8
GLOBAL LevelTile AS FloorTileType
DIM LevelTile[NumXTiles][NumYTiles]

Kitty Hello

Code (glbasic) Select

GLOBAL LevelTile[] AS FloorTileType


LevelTile is an array!

FutureCow

*groan*
With all the excitement about the octal errors I overlooked the simple bug causing the issue.
Instead of  Global LevelTile, it should have been Global LevelTile[]

ie
Code (glbasic) Select
GLOBAL LevelTile[] AS FloorTileType



Edit : Just saw your post as I posted this reply. Thanks Gernot!!!