Monkey - Lists
Community Forums/Monkey Talk/Monkey - Lists
| ||
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 |
| ||
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 |
| ||
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 |
| ||
Thanks Mike. Finally have it working. Forgot the ':' |
| ||
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 |