Types : Direct Access

BlitzMax Forums/BlitzMax Beginners Area/Types : Direct Access

tonyg(Posted 2005) [#1]
What is the best way to directly access a specific type instance? (i.e. without for/eachin).
With this code...
Strict
Global my_list:TList = CreateList()
Type person
  Field name$
  Field age
End Type
For Local x = 1 To 100
   Local peeps:person = New person
   peeps.name$ = "Joe Bloggs"
   peeps.age = rnd(1,100)
   ListAddLast (my_list,peeps)
Next
Local hero:person = New person
hero.name$ = "My Hero"
hero.age = 9999
ListAddLast (my_list,hero)
For Local y = 1 To 72
  Local peeps:person = New person
  peeps.name$ = "Joe Bloggs"
  peeps.age = rnd(1,100)
   ListAddLast (my_list,peeps)
Next
For Local z:person = EachIn my_list
  Print "Name :" + z.name$ + " Age : " + z.age
Next

how would I directly access 'My Hero' and change the age?
If you would have coded it differently then please let me know how with, if possible, a small example.
Many thanks


Perturbatio(Posted 2005) [#2]
hero.age = 200


You can only directly access a type instance if you have a handle to it.
So either you need to point something to each one or you need to loop through the list until you find the one you want.


tonyg(Posted 2005) [#3]
Perturbatio, very much appreciated. Thank you so much.