I'm new to Lua, so I'm confused

Hello @Abdou23!

I can understand your confusion, The snippet of code you posted is probably the most complicated there is in the tutorials. There’s a bit of physics and math going on that might overwhelm a new user of Defold. There is a physics engine (Box2D) in Defold and you can let the physics engine resolve all collisions by setting the type of collision objects to Dynamic instead of Kinematic. If you use Dynamic objects you can only control them by applying forces to them while a Kinematic object can be moved around simply by programmatically changing it’s position. The platformer example uses Kinematic objects since you get absolute control over position and movement, which makes sense in a platformer. If you were to create a game similar to Angry Birds then you’d probably opt for Dynamic objects instead and let the physics system resolve collisions.

When it comes to auto-complete the editor should be able to provide you with auto complete for the built in Defold modules such as go, gui, vmath etc. You can also enable a kind of fuzzy auto complete in the key bindings of the editor that allows you to auto complete based on words that exist in open script files.

You will find that message passing takes a while to get used to if you come from classic OOP programming, but once you do you will be able to write very nice decoupled and reusable scripts and components that communicate via message passing. You should however take note of the fact that message passing is not to be confused with function calls.. And there is nothing stopping you from using Lua modules to share code between scripts. And you can also add a layer of OOP on top of it all using any of the popular OOP modules for Lua (although I would mostly recommend against it).

Finally, I can recommend that you take a look at Programming in Lua, available as a book or online. Remember that Defold uses Lua 5.1 and not the more recent 5.2 or 5.3.

And please don’t hesitate to ask your questions here! We’re here to help!

4 Likes