How to add multiply items to a list quickly?
BlitzMax Forums/BlitzMax Beginners Area/How to add multiply items to a list quickly?
| ||
| How do I add multiply items to a list quickly? Say I have a type called myType and a list called myList. I want to add myType hundred times to myList. How do I do this quickly? Thanks, Nicolas. |
| ||
for i=0 until 100
mylist.AddLast(mytype)
next |
| ||
| Thank you, but I don't get the result I expected. Say every instance of myType in myList contains an image and a random x and y value. If I iterate through myList in order to draw every image on it's corresponding x and y values I'm only seeing the first instance, what am I doing wrong? Thanks, Nicolas. |
| ||
| Well you need to create 100 instances and add each one to the list. What you asked, would create 1 instance, and add it to the list 100 times. do it like so...
for local i:int = 0 until 100
mylist.AddLast(new mytype)
next
|
| ||
| Thank you, you solved my problem. Nicolas |