Passing large table through


Hi. I’m generating randomized terrain using Perlin Noise and drawing to a 1024 x 512 cavas, pixel by pixel. When an attack is used which damages the terrain, or when the level is being played with during generation (such as flood_fill() algorithms and such) I need to send a msg with the pixels to edit to the canvas.script game object. Since sending lots of pixels in a table gives me an error (table too large to pass), how should I go about doing this? I’m thinking maybe use Lua modules, but I’m not super experienced in this area. Is this a good idea?

Thanks for reading. I’m new to Defold and this website, but I’ve gotta say this is one of the best places I’ve experienced for getting quality help and quick replies. I’m trying to contribute here whenever I can.



Yes, definitely keep the datastructure in a Lua module and use messages to communicate changes to the data.



Okay, thank you for the confirmation. I’ll probably need a queue in the case that multiple canvas requests are issued during a single frame.

This is a little bit off topic, but still concerns Lua module usage: when it comes to Defold, how do you recommend I manage scripts that need to run every once in a while, but don’t necessarily need their own game object? For example, I have one game object called “stage_generator.” This guy has a “stage_generator.script” attached, which generates a stage. I have a second game object called “canvas” and has a “canvas.script” attached, which responds to “stage_generator”'s request for the stage to be drawn.

Having these two “game objects” in the game world just seems kinda… awkward. When I think of a game object, I think of like a physical entity. This is also strange because every background script needs to be attached to a game object, so I’ll have a bunch of game objects just floating around, their sole purpose being to execute scripts. Should I maybe just have one game object that has a bunch of background scripts attached or something? Hopefully you understand what I’m getting at. It’s somewhat jarring to me.



While game objects do have a transform and exist in the scene they are not expensive to have lying around so there’s no inherent problem with your approach.

Yes, don’t try to think too much OOP when you are working with Defold. In your example I don’t see any point at all in having two game objects. Use one and attach both scripts.

Or maybe even better use a single script?

1 Like