Understanding Lists
Can someone explain to me how to use lists and what their purpose kinda is? Also how they get used in conjunction with creating objects/instances.
Can someone explain to me how to use lists and what their purpose kinda is? Also how they get used in conjunction with creating objects/instances.
lists is basically for storing a bunch of stuff without having to create a variable for each things ex:
//Normally without lists you would have to do each var
enemy1 = object end
enemy2 = object end
// this is heavily limited as you cant create more or less without manually changing it everytime
//however lists can solve this
enemies = []
enemies.push(object end)
//and you can do this as much as needed and you can also remove things you don't need such as dead enemys.
enemies.removeAt(list item num)
//also all lists start at 0 when counting
so if you want the first enemy you would access the first thing in the list
enemies[0].damage(3000)
//this would damage enemy1 for 3000
/there are many more uses but this is basics
also for classes you can simple do
enemies = []
enemies.push(new classname(required vars))
enemies[0].draw()
// this first init's the enemies list then adds a class replace classname with the class name and put the required setup vars
//and then you can call one of the class functions by stating you need the first thing in the list the "[0]" shows where in the list you //wanna pull from