just a simple list with objects ? how
Monkey Forums/Monkey Programming/just a simple list with objects ? how
| ||
H! everyone, I downloaded the demo, but that gives me not enough help to make a simple list with objects. So now I have the full version with forum support ;) What I want to do is make a Field something:List<Object> or something:Stack<Object> yust something that hold my created objects. inside a other class. This don't work: Strict Import mojo Class A Field assets:Stack<B> ' a list with B objects Method add2BList : Void() Self.assets.Push(New B()) End End Class B Extends A Field name:String End Function Main:Void() Local helloA:A helloA = New A() helloA.add2BList() End Complie HTML5 > TypeError: Cannot call method 'bbm_Push' of null I think that New B() return null, and that's why I get that error. What is the best way to create a [holder] with objects inside a other class ? Thanks, GCMartijn |
| ||
In Class A addMethod New() assets = New Stack<B> End |
| ||
The error suggests that the assets object while defined as a stack of B's hasn't been set to one. |
| ||
thanks raz, I see it now. Or I could do this Field assets:Stack<B> = New Stack<B> Is there a simple explanation what to use Stack/List or something else to hold objects ? I think i'm going to use List<B> and use AddLast, but I don't know why haha |
| ||
Yeah you can do that too :) Lists are fine, but it depends on your target and how you intend to use them. I can't speak for everyone else, but when developing for Xbox via XNA, you have to initialize all objects to start with (for example, I have 1000 particle objects) and activate/deactivate them as required. XNA really does not like the creation of objects during play (e.g. dog = New Dog(100,200)) |
| ||
XNA really does not like the creation of objects during play (e.g. dog = New Dog(100,200)) I'm sure Android is even worse. :) I recommend you take a look at Diddy's ArrayList class. There's a wiki page on how to use it. http://code.google.com/p/diddy/wiki/ArrayList |
| ||
I will have a look at that thanks. |