nested type list

Started by monkeybot, November 12, 2012, 12:09:47 PM

Previous topic - Next topic

monkeybot

Is it possible to have a type list within another type?

kevin


monkeybot

#2
Quote from: monkeybot on November 12, 2012, 12:09:47 PM
Is it possible to have a type list within another type?
i mean a linked list,so i can add items within the type

e,g, windows in a building

building is type
windows are a linked list within the building type that can be created or deleted....

PlayBASIC Code: [Select]
explicit on
type tWindow
x,y
endtype

;dim window as tWindow list

type tbuilding
status
x,y,xs,ys
window as tWindow list
EndType

dim building as tBuilding list
;waitkey

building=new tbuilding
building.status=1
building.window=new tWindow
building.window=1
; building.window=new tWindow
; building.window=2
; building.window=new tWindow
; building.window=3
;
building=new tbuilding
building.status=2
building=new tbuilding
building.status=3
;building.window=new tWindow
; building.window=1



for each building()
print building.status
; for each window()
; print "x "+str$(building.window)
; next
; for q=building.window to 1 step -1
; print " x"
; next
next

sync
waitkey




kevin


You create the array in a function and return and handle, this allows you to nest array within array within within array etc etc .. It just puts the onus on the user to clean up after themselves.

ie.

Inventory

Array In Array

baggey

#4
Hi Monkey Bot  ;)

Not sure wether you intended to have your code displayed in Black!?

But

if you type

pbcode enclosed in [...]

your code STUFF here........

/pbcode enclosed in [...]


ie, [/pbcode]



It will be displayed like so  ;D


PlayBASIC Code: [Select]
explicit on
type tWindow
x,y
endtype

;dim window as tWindow list

type tbuilding
status
x,y,xs,ys
window as tWindow list
EndType

dim building as tBuilding list
;waitkey

building=new tbuilding
building.status=1
building.window=new tWindow
building.window=1
; building.window=new tWindow
; building.window=2
; building.window=new tWindow
; building.window=3
;
building=new tbuilding
building.status=2
building=new tbuilding
building.status=3
;building.window=new tWindow
; building.window=1




Hope you dont mind the suggestion. Just trying to be helpful  ;D

Kind regards baggey
Jesus was only famous because of his dad

monkeybot

#5
Thanks Baggey.
I used the forum button,forgot all about the new spiffy way of doing it.

Kev.
I worked out the array within the type approach ,it just means that its not extensible,i assume you can't redim the array within a type.
cheers

kevin


QuoteI worked out the array within the type approach ,it just means that its not extensible,i assume you can't redim the array within a type.

yes you can..  perhaps you should take a much closer look at the links above.. 

monkeybot