Types Again!!!

Blitz3D Forums/Blitz3D Beginners Area/Types Again!!!

Gauge(Posted 2003) [#1]
Okay what would be the line to run a for next loop if your using these types/fields? Notice the dim statement too...

Dim All.Areas(2)

Type Area
Field Areaname$
Field ar.room
End type

Type Room
Field Roomname$
End type


I Need to run a loop that checks each room of that area ...
something like For a.room=Each all (x)\area\room?
somebody help me out here please *sigh*


Curtastic(Posted 2003) [#2]
is it documented that
for variable=each [you can only put a typename here]


and is it documented that
for [no matter what you put here it will go through all the instances] = each typename


becuase everyone seems the have the same problems when learning types (I did also) and dont know these 2 rules


Curtastic(Posted 2003) [#3]
assuming you wont be mixing them with insert you can do

Type Area
Field Areaname$
Field ar.room;points to first room in area
Field rooms
End type

r=all(x)\ar
for i=1 to all(x)\rooms
[do stuff with r]
r=after r
next



when you make a new room of area a
if a\ar=null then
 a\ar=r
else
 insert r after a\ar
endif
a\rooms=a\rooms+1



Gauge(Posted 2003) [#4]
uh oh...you lost me


Gauge(Posted 2003) [#5]
Um, lemme retry this question...um..... Okay say i do this:
Graphics 400,300,16,3
Dim all.area(2)

Type area
Field Areaname$
Field ar.room
End Type

Type room
Field roomname$
Field roomnumber$
End Type
all.area (0)=New area
all (0)\areaname$="Town"
all.area (1)=New Area
all (1)\Areaname$="Sewers"


For a.area=Each area
Print a\areaname$
Next

WaitKey()


Whats the command to add a room into that area(type)...something like? all (x)\room=new Room?? And then what would be the syntax to cycle thru with each if possible?


Gauge(Posted 2003) [#6]
Okay lets try this...heres what i got! I only know how to loop thru all the skills, I need to know how to loop thru the players individual skills.

Graphics 400,300,16,3

Type Player
Field Playername$
Field psk.skill
End Type

Type skill
Field skillname$
End Type

p.player=New Player
p\playername$="John"
p\psk.skill=New skill
p\psk\skillname$="Jump"
p\psk.skill=New skill
p\psk\skillname$="Hello"

p.player=New Player
p\playername$="Joe"
p\psk.skill=New skill
p\psk\skillname$="Punch"
p\psk.skill=New skill
p\psk\skillname$="Duck"

Print "Players: "
For a.player=Each player
Print a\playername$
Next

Print " "
Print "Skills:"
For j.skill=Each skill
Print j\skillname$
Next

For a.player=Each player
For j.skill=Each p.psk.skills;this doesn't work
Print p\psk\skillname$
Next
Next



Now how can I print out each players individual skills???


Curtastic(Posted 2003) [#7]
as I said before
for variable=each [YOU CAN ONLY PUT A TYPE NAME HERE]

is there a type called "p.psk.skills"? no. you cannot even make one called that
the types in the program are "player" and "skill" so thats all you can put after "each"

the simplest way is
Graphics 400,300,16,3

Type Player
Field Playername$
End Type

Type skill
Field skillname$
Field player.player
End Type

p.player=New Player
p\playername$="John"
s.skill=New skill
s\skillname$="Jump"
s\player=p
s.skill=New skill
s\skillname$="Hello"
s\player=p

p.player=New Player
p\playername$="Joe"
s.skill=New skill
s\skillname$="Punch"
s\player=p
s.skill=New skill
s\skillname$="Duck"
s\player=p

Print "Players: "
For a.player=Each player
Print a\playername$
Next

Print " "
Print "Skills:"
For j.skill=Each skill
Print j\skillname$
Next

For a.player=Each player
Print a\playername+":"
For j.skill=Each skill
If j\player=a Then Print j\skillname$
Next
Next


I hope that helps