03-18-2005, 05:58 AM
i am having some real trouble understanding how pointers need to work to create a dynamic type structure... here is my code so far
edited: asically rewrote the code from scratch, and still completely clueless as to how to do what im trying..
edited again: well, "? map->rooms->layout[600] 'prints 9 (correct)"
returns the right number, so the array IS allocated... how the fuck do i look at the LEN? and how do i save the entire "map" structure to a file?
Code:
TYPE mapheader FIELD=1
numofrooms AS UBYTE
tilesetname AS string
END TYPE
TYPE RoomHeader FIELD=1
dimensions AS SHORT
numofdoors AS UBYTE
layout as ushort ptr
END TYPE
type maptype field=1
info as mapheader
rooms as roomheader ptr
doors as integer ptr
numoftiles as short
tileset as short ptr
end type
dim map as maptype ptr
map = callocate(len(maptype))
map->info.numofrooms = 1
map->info.tilesetname = ""
map->info.tilesetname = "grass.spr"
map->rooms = callocate(map->info.numofrooms * len(roomheader))
map->rooms->dimensions = 7710
map->rooms->numofdoors = 1
thisroomx = (map->rooms->dimensions shr 8) + 1
thisroomy = (map->rooms->dimensions and 255) + 1
map->rooms->layout = callocate((thisroomx * thisroomy) * len(ushort))
map->rooms->layout[600] = 9
? map->rooms->dimensions 'prints 7710 at runtime (correct)
? map->rooms->numofdoors 'prints 1 at runtime (correct)
? thisroomx 'prints 31 at runtime (correct)
? thisroomy 'prints 31 at runtime (correct)
? len(*map) 'prints 23 at runtime (correct for an empty structure)
? len(map.info) 'print 4 at runtime (correct?)
? len(*map->rooms) 'print 7 at runtime (correct?)
? len(map->rooms->layout) 'prints 4 at runtime (can't be correct...)
? map->rooms->layout[600] 'prints 9 (correct)
sleep
end
open "totaltest.map" for binary as #1
put #1,, *map
close
deallocate map->rooms->layout
deallocate map->rooms
deallocate map
edited: asically rewrote the code from scratch, and still completely clueless as to how to do what im trying..
edited again: well, "? map->rooms->layout[600] 'prints 9 (correct)"
returns the right number, so the array IS allocated... how the fuck do i look at the LEN? and how do i save the entire "map" structure to a file?