How to make multiple classes in a list to do a function?
I do not know how to do this. I know how to set it up It's something like
init = function()
bananas = []
end
update = function()
if keyboard.press.SPACE then
bananas.push( new banana(tree_x, tree_y))
end
end
Are you trying to have all the classes in a list execute a function? If so, you can do it like this:
for x in bananas
x.grow()
end
you have to use this code structure
for obj in list
obj.method()
end
or
list.forEach( function( obj ) obj.method() end )
The condition for success of this code is that all objects in the list have the method you want to call.
It is best if the list includes objects that are created from one class.
Thanks, I got stuck because it kept saying that "grow" was not a function, I was confused so I checked the function and it said
groww = function()
//code
end
Also @apinguen, you can use 3 backticks to represent code, ( what's a backtick, this " ` ")
its like
backtick backtick backtick
code
backtick backtick backtick