Kirby Playable Help

Post here for help and support regarding LunaLua and SMBX2's libraries and features.

Moderator: Userbase Moderators

Throw Kirby
Spiny
Spiny
Posts: 28
Joined: Sun Oct 14, 2018 2:54 pm
Flair: Nice to YEET you!
Contact:

Kirby Playable Help

Postby Throw Kirby » Mon May 11, 2020 10:55 am

I'm trying to make it so that my Kirby playable spits out a star when not full Do you think this code will work?

Code: Select all

function Inhale
    if keycode == KEY_RUN and SldInit = false
        if Full == true
            starID = NPC.spawn(108, player.x, player.y, player.section)
            Full = false
            starID.speedX = 15 * direction;
            starID(0xF0, FIELD_DFLOAT, 4)
        else
	(Inhale code, IDK)
    end
end

MrDoubleA
Edward
Edward
Posts: 394
Joined: Mon Aug 20, 2018 7:02 am
Flair: How much munchers?

Re: Kirby Playable Help

Postby MrDoubleA » Wed May 20, 2020 9:44 am

This is not valid lua code. I’d personally recommend watching Enjl’s lunalua tutorials before taking on the task of making a custom playable.

Cedur
Link
Link
Posts: 7073
Joined: Tue Jun 28, 2016 10:14 am
Flair: I'm gone, for chess and minesweeper
Pronouns: he/him

Re: Kirby Playable Help

Postby Cedur » Wed May 20, 2020 10:08 am

The first thing I see (without having any scripting knowledge myself) is the missing parentheses after "function Inhale"

Emral
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 9891
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Phoenix

Re: Kirby Playable Help

Postby Emral » Wed May 20, 2020 11:22 am

My lua tutorials are the second place to look. They assume general knowledge of syntax, to some extent. Using them as a smbx-specific resource can be very valid, but I recommend using the official lua tutorial in tandem with them. Start here and use the navigational arrows. Feel free to skip pages you already are confident on: https://www.lua.org/pil/2.html

From your code above, here are some things I noticed:
- As Cedur said, functions are denoted with parentheses. The parentheses are necessary, because parameters are defined in them. As in, custom variables that are passed to the function.
- In the line below, you are missing a "then". Some languages use {} to denote scope, lua uses "do", "then" (based on which one makes more sense when reading the code like if it was english) and "end" (for the ending)
- In the same line, you use == once and = another time. Pay attention to those two. They're easy to mix up, but what might help is that = is assignment and == is comparison, so because = is short you can read it as "set" and == is long so you can think of something like "are you sure, that...?"
Think of this line saying "if you are sure that keycode is KEY_RUN and SldInit is false then" and then the mistake should make more sense
- in the SAME line you use 2 uninitialized variables: SldInit and keycode. keycode is a parameter passed to the predefined function onKeyDown. It doesn't exist outside of onKeyDown. SldInit doesn't exist by default. You can define it outside of functions (above the code you posted) by writing "local SldInit = false"
- Repeating error of uninitialized variable and missing then in the line below
- If you don't need starID outside of the if statement, make sure to declare the variable as local. Local means that once the next "end" is reached, the variable stops existing. It's useful to avoid the variables leaking into other bits of code.
- StarID is a misnomer. It's an NPC, not an ID. "star" or "starNPC" would be more fitting names.
- direction is undefined, a few lines lower. Do you mean player.direction or starID.direction?
- The line starID(0xF0, FIELD_DFLOAT, 4) is wrong in two ways. Firstly, starID is not a function so you cannot call it. Secondly, we have a field for it.
-- You are likely trying to use starID:mem(...). That would be valid.
-- However, 0xF0 is already exposed as a field. Just put starID.ai1 = 4.
That's about it. I hope they make sense and you have an idea on how to resolve them. And yeah, as MrDoubleA said, making a playable is complicated. It's not too bad in terms of technical knowledge, but it's just a large quantity of code, since you need to do a lot of state management for the player. Good luck!


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 5 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari