Multi-Dimension Arrays In Structures

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by JohnDeHope3.

I want to hold a map in a structure, so I need a 2-dimension array like this...

Structure Terrain
Name.s
Walkable.b
CharacterSymbol.s
EndStructure

Structure Map
Name.s
Cells.Terrain[10,10]
EndStructure

This would give my map a 10x10 array of terrain cells. But it seems I cannot have a static, multidimensioned array in a structure.

My beef is that since a structure's size is fixed, and a static array's size is fixed, why can't I have a two-dimensional array of structures?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kale.

change to:

Code: Select all

Structure Terrain
Name.s
Walkable.b
CharacterSymbol.s
EndStructure

Structure Map
Name.s
Dim Cells.Terrain(10,10)
EndStructure
--Kale

New to PureBasic and falling in Love! :)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

damn, it will never work and compiler doesn't warn.. One check more to do...

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

Kale, what you wrote is just wrong.
Did you ever test this?

There is only one solution. See here:

viewtopic.php?t=4512

Timo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by JohnDeHope3.

Thanks guys, I will try the "array in a struct" with another struct to hold that struct approach.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kale.

hmmm, i didn't test it properly (i had to shoot of back to work, tut tut...). The above code compiled fine for me and i thought it was right, looking at it now though,... yeah it'll never work :)

--Kale

New to PureBasic and falling in Love! :)
Post Reply