Types, How to

Blitz3D Forums/Blitz3D Beginners Area/Types, How to

Gauge(Posted 2003) [#1]
How to do search thru the following p\sk.skills? Using this code, and without making a linked list, is it possible?

Type player
Field name$
Field sk.skill
End Type

Type skill
Field name$
Field comline$
End Type

p.player=New Player
p\name$="George"
p\sk.skill=New skill
p\sk\name$="disarm"
p\sk\comline$="You disarm your friend!"
p\sk.skill=New skill
p\sk\name$="bash"
p\sk\comline$="You bash soandso!"

p.player=New Player
p\name$="Henry"
p\sk.skill=New skill
p\sk\name$="fireball"
p\sk\comline$="You cast a fireball !!!"
p\sk.skill=New Skill
p\sk\name$="Chain"
p\sk\comline$="You chain stuff!!"

For p.player=Each player
Print p\name$
Next

For s.skill=Each skill
Print s\name$
Next
Print
Print

For p.player=Each player
Print p\name$
For sk.skill=Each p\sk.skill ;How to search thru this players skills?
Print p\sk\comline$
Next
Next

waitkey()



SJT(Posted 2003) [#2]
One way is to make the .skill type contain the player name, you don't need to include one type inside the other this way;

Type skill
Field playername$
Field name$
Field comline$
End Type


Then you can just search for the players name. However you have to make sure the names are all different. The other way would be to allocate an ID for each player, Then provided you know the player you can look up his id and search for his skills.

Type player
Field name$
Field id
End Type

Type skill
Field id
Field name$
Field comline$
End Type


You have some overhead looking through the complete skills list but unless it is very big you should not notice.

SJT


Curtastic(Posted 2003) [#3]
instead of ID, you can have owner.player
IDs usually arent needed in the programs that I see that have them


Nibble(Posted 2003) [#4]
Also,

Type player
  Field firstSkill.skill
  Field numSkills
End Type

...

temp.skill = new skill
Insert temp after p\firstSkill
p\numSkills = p\numSkills + 1

...

s.skill = p\firstSkill
For i = 1 to p\numSkills
  Print s\name$
  s = After s
Next


...should work.

It's possible that you're going to be dealing with a specific set of skills that only have one integer value (ie 25 intelligence, 18 dexterity, 15 strength). In this case, you might want to simply use an array:

[box]
Type player
Field skills[2]
; 0 = int
; 1 = dex
; 2 = str
End Type
[/box]

If the skills are more complex but you're still dealing with a specific set, you can use an array of skills (ie Field skills.skill[2]).


FlameDuck(Posted 2003) [#5]
How to do search thru the following p\sk.skills? Using this code, and without making a linked list, is it possible?
Types are already linked lists...


QuietBloke(Posted 2003) [#6]
why dont you want to use a linked list for the skills ?