best way to represent data?

BlitzMax Forums/BlitzMax Beginners Area/best way to represent data?

slenkar(Posted 2005) [#1]
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


rdodson41(Posted 2005) [#2]
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



slenkar(Posted 2005) [#3]
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)


Diablo(Posted 2005) [#4]
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


slenkar(Posted 2005) [#5]
thanks,
whats the best way of creating a new person and putting him on the 8,3 square of the map?


Diablo(Posted 2005) [#6]
map[8, 3] = new person


rdodson41(Posted 2005) [#7]
Yeah, and to create a new person on every square do
map[10, 10] = New Person[10, 10]


slenkar(Posted 2005) [#8]
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?


taxlerendiosk(Posted 2005) [#9]
Yeah, it can only point to an instantiation of the type (or an Extended type from it).