Monkey - Lists

Community Forums/Monkey Talk/Monkey - Lists

Uncle(Posted 2011) [#1]
Hi,

Im playing with the demo, and have got a bit stuck with lists. How can I create a list of objects instances?

Cheers,


Unc


MikeHart(Posted 2011) [#2]
Field yourlist := New List <yourclass>

there are also list types for strings and int's.

Make sure you have your name casing right. Monkey is case sensitive.

The syntax error messages don't tell you what the exact problem is.

Last edited 2011

Last edited 2011


MikeHart(Posted 2011) [#3]
In my app class, I have a field definition like this:

 Field starList:=New List<mySpriteClass>


To add an object, do it like this:


starList.AddLast(spr)


Last edited 2011


Uncle(Posted 2011) [#4]
Thanks Mike. Finally have it working. Forgot the ':'


gameproducer(Posted 2011) [#5]
Tim (Indiepath) hinted that:
Local dudes:List<Dude>           'create a new list, which takes Dude objects
dudes.AddLast (New Dude("Jim"))  'add a new Dude to the list.

For Local dude:= EachIn dudes    'You must put Local/Global before variable declarations now, but you can declare type implicitly with the := operator
  Print dude.name
Next