Here are some tips I’ve been learning over the past while learning Lua and Defold. These are not in any specific order, just written as I remember and come across them.
-
Generally, it’s good to begin your function with the first argument being “self”. That way, in the future, you won’t have to tediously go through every call of that function to make it work. This also helps when building the function. If you need to access “self”, it’s already set up for you.
-
Tables of variables and tables of tables are very handy if organized correctly. A horrendous amount of global variables can and WILL get you into a lot of collateral damage. “self” is a great way to do this.
-
Create little comments at the start of general functions, telling yourself and possibly others reading your code what the function will do. If you take a week break from programming, you might come back scratching your head when trying to figure out what your own functions do.
-
How do you eat an elephant? One bite at a time. Basically, don’t write enormous amounts of code and expect it to work perfectly. You’ll be better off writing a fraction of that chunk, fixing problems, and moving on to the next fraction.
-
Ask for help. I’ve personally asked a great number of questions. Many of my questions had simple fixes. Also, no one was ever judgmental or unhelpful and they would even point out other things in my code which solved future problems for me.
-
I’ve solved 99% of my problems using print(). print() would help me figure out where certain values went wrong, and how functions were being used. I’ve had to do a lot of cleanup though, so make sure to weed out the print()s that aren’t necessary once you’ve fixed the problem.
I hope to add more in the future. I’ll just leave this until more come to mind or when I run across them.