I have a class called Board which holds some metadata and a two-dimensional array to hold Tile objects. Let’s say that a Tile object holds a table of values, one of which is t.
As I iterate through my table, should not
board.array[i][j] = Tile.init() where the init sets t to 0.
board.array[i][j].t = 12
be a valid assignment? I seem to get all of the array locations pointing to the last Tile I assigned. How do I properly write this so that each array[i][j] gets a unique Tile object? What is the secret syntax here?
Andrew it right. To create an instance of Tile you must do Tile(). The function Tile:init() is not defined to be called dirctly by you. It is called by Tile().
@JakAttak. Thanks for trying, but I tried every possibility of self vs Tile and . vs : and passing self.
Most were not grammatical and threw a parsing error. All the rest refused to pass any values. I finally just made it a plain global function and passed my object as the args. It works, although not as elegant as I would like. I don’t care for too many globals running around.
Edit: Looking at CargoBot, I think I see how it’s done… Going to try again.
@Syntonica not quite sure what you ask for. If you want to pass the class method spin to self.action just do: self.action = Tile.spin and then you run it with self:action() or self.action(self). Might not be your question, though.
@syntonica good to know i could help you. But be careful: i started programming in Codea 1.1/2 year ago, and that was a one way trip… You might never want to go back!
If they’d put closures in Java, I could live with it. I’m tired of writing wrappers for functions when I’d rather just pass the function (actions :-@).