Page 1 of 1

how to get started with lua coding?

Posted: Wed Jun 24, 2020 8:53 pm
by mario610
does SMBX have an editor where I can mess with code and try to make stuff, or do I have to download something else. I wanted to try making a mount that's like the bird from DKC2 that carried you and shot eggs

Re: how to get started with lua coding?

Posted: Wed Jun 24, 2020 9:31 pm
by Lusho
You need to use a text editing program for code, SMBX doesn't naturalyl come with one, I could recommend atom and notepad++ (lightweight) or visual studio code (complete)

To create scripts there's the luna.lua files which you can generate from the editor, you open them with the programs I mentioned above and start coding stuff, the luna.lua files work like custom graphics, in the episode folder they are global, and in the level folder just that level

For starting to know lua, I guess you could follow basic standalone lua tutorials, and then Enjls tutorials for specific LunaLua stuff

Re: how to get started with lua coding?

Posted: Thu Jun 25, 2020 1:33 am
by Emral
When coding your own content, it's important to try to think like a computer. That means that you must take your goal (for example, "a timer that makes the player die when 0 is reached") and rephrase it into something that makes sense for a computer. You're basically turning it into simple instructions.
The simplest ways to communicate with a computer through code are conditional statements and variables.
So, for example, the goal above would also be something like: "There is a timer. It counts down. Once it has reached zero, kill the player."
These sentences are 4 statements that are translatable into code one-by-one:

Code: Select all

local timer = 500 -- There is a timer. Initialize a variable called "timer" to 500.
function onTick()
    timer = timer - 1 -- that counts down. Remove 1 from the timer every frame. 64 frames in a second. It'll reach 0 after like 5 seconds.
    if timer <= 0 then -- once it has reached zero.... (if-statements are somewhat easy to read in english. like, "if timer is less than or equal to 0 then...")
        player:kill() -- kill the player!
    end -- functions and if statements usually have their content indented. when the conditional or function ends, an end must be placed to let the program know
end
Hope this makes sense. Being able to get into this mindset requires a bit of knowledge of the systems you can use (for example, player:kill() is quite specialized). If you're unsure about how something could be done, we can always point at the resources and provide the reformatted sentence.