best way to represent data?
BlitzMax Forums/BlitzMax Beginners Area/best way to represent data?| 
 | ||
| What would be the best way of representing this data: a 2d map with 10 x 10 squares in each square a person on each person a sword and a bag in each bag a healing potion thanks | 
| 
 | ||
| Something like this maybe? 
Global map:Person[10, 10]
Type Person
    Field s:Sword
    Field b:Bag
EndType
Type Sword
    Field dmg:Int
EndType
Type Bag
    Field items:Potion[]
EndType
Type Potion
    Field healpoints:Int
EndType
 | 
| 
 | ||
| thanks how would I access say, a sword or a potion to read its fields (I never got the hang of types in types before) | 
| 
 | ||
| map[x, y].s.dmg ' < Will give you the damage of the sword at x & y map[x, y].b.items[n].healpoints ' < will give you the hp recovered from that potion (n - potion number) but you will have to create them first: map.b.potion = new int[n] gluck | 
| 
 | ||
| thanks, whats the best way of creating a new person and putting him on the 8,3 square of the map? | 
| 
 | ||
| map[8, 3] = new person | 
| 
 | ||
| Yeah, and to create a new person on every square do map[10, 10] = New Person[10, 10] | 
| 
 | ||
| let me just make sure I understand whats going on MAP is a global array map:person[10,10] is confusing, what relation is the type 'person' to the array 'map'- is it an array of type pointers? same with type person field s:sword is 's' a pointer to the type sword? | 
| 
 | ||
| Yeah, it can only point to an instantiation of the type (or an Extended type from it). |