I am trying to create a TYPE that has the ability to hold a list of types in it's namespace. the example i have is series of rooms and a bunch of stuff. since stuff can only be in a single room at a time, how would I associate the particualr stuff with the room. keep in mind that 'stuff' is an object of type TYPE.
stuff = a laptop and a stapler
rooms = kitchen and bedroom
this is what I have so far. Is there a better way?
stuff = a laptop and a stapler
rooms = kitchen and bedroom
this is what I have so far. Is there a better way?
Global all_things:Tlist = CreateList() For i$ = EachIn ["spoon","car","TV","telephone","Laptop"] my:stuff = New stuff my.name = i$ ListAddLast all_things,my Next Type stuff Field x,y Field name$ ' name of this thing Field room$ ' room that this thing is currently in End Type Type room Field name$ Method add_a_thing(xp,yp,name_of_thing:String) For b:stuff = EachIn all_things If b.name = name_of_thing b.room$ = name$ EndIf next End Method Method list_things() Print "The "+name+" has:" For b:stuff = EachIn all_things If b.room$ = name$ Print b.name$ endif next End Method End Type ' ----------------------------------------------------------------------- kitchen:room = New room kitchen.name = "Kitchen" kitchen.add_a_thing(100,100,"car") kitchen.add_a_thing(100,100,"spoon") kitchen.add_a_thing(100,100,"Laptop") bedroom:room = New room bedroom.name = "Bedroom" Bedroom.add_a_thing(100,100,"TV") Bedroom.add_a_thing(100,100,"telephone") Bedroom.add_a_thing(100,100,"spoon") ' spoon is same object as spoon in kitchen kitchen.list_things() Bedroom.list_things() Print " =================== " Bedroom.add_a_thing(100,100,"Laptop") ' taken from the kitchen Bedroom.add_a_thing(100,100,"foosball table") ' does not exist in list of all_things kitchen.list_things() Bedroom.list_things()