how to get started with lua coding?

Post here for help and support regarding LunaLua and SMBX2's libraries and features.
User avatar
mario610
Spiny
Spiny
Posts: 41
Joined: Tue Jan 07, 2014 3:44 pm

how to get started with lua coding?

Postby mario610 » Wed Jun 24, 2020 8:53 pm

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

User avatar
CJ_RLushi
Hoopster
Hoopster
Posts: 151
Joined: Wed Dec 25, 2019 11:39 pm
Flair: Intention is what matters

Re: how to get started with lua coding?

Postby CJ_RLushi » Wed Jun 24, 2020 9:31 pm

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
My episode lol:
Image

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8878
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: how to get started with lua coding?

Postby Enjl » Thu Jun 25, 2020 1:33 am

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.
Ideas are useless if you can't make them real.
Image

All my assets from packs and episodes are free to use for non-Novaverse levels and projects, as long as proper credit is given.


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest