I’m trying to use a lua module for procedural tilemap generation. I’m using parts of the random walker code that Britzl made.
The problem is I can’t figure out how to access the tilemap from the lua module.
I have a collection with a GO, a tilemap and a script. I create the collection from a collection proxy.
The defold script can access the tilemap by url ("#city"). But the lua module can’t.
Trying to do tilemap.get_bounds("#city") gives me an error: attempt to call field 'get_bounds' (a nil value)
The same call works fine from the defold script.
How do I get the url or id to use from the lua module?
That’s what I am doing, and it throws the error.
I think the problem may be that the GO with the tilemap is created with collection proxy. From reading the Defold docs I’m starting to think that I should use the instance Id associated with the GO created by the proxy. But I can’t figure out how to get the Id.
No. The error means that the field get_bounds in the tilemap table is nil. That means that the runtime cannot find a function called tilemap.get_bounds().
Maybe you have overwritten or shadowed the tilemap global variable?
My spawn collection is the collection name? I thought the collections didn’t exist in runtime. Or is it the proxy?
I think I tried doing that already but I will check again.
No. Tables are associative arrays. There is no inheritance like with js objects. Tables can be used to store any value, including tables and functions. Functions stored in a table are like any other function. There is no automatic “self” or “this” like object methods. If you need that you have to pass it explicitly (there is the “:” syntactic sugar though).
Lua tables, functions as first class citizens and coroutines are the things that makes Lua absolutely awesome. It makes the language very powerful and certain things become very easy to implement.