Need help with lua? - LunaLua General Help

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

Moderator: Userbase Moderators

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: Need help with lua? - LunaLua General Help

Postby ShadowXeldron » Sat Sep 26, 2020 3:46 pm

Hoeloe wrote:
Sat Sep 26, 2020 2:54 pm
Dragon0307 wrote:
Sat Sep 26, 2020 2:20 pm
I tried to load a font from this page, specificaly the Superstar Saga one and then I got an error.
Image

I am using this code to load it:

Code: Select all

textplus.loadFont("Fonts/superstarsaga-b.ini")
I also tried placing it in the root directory and ommiting the "Fonts/" and it still didn't load. What am I doing wrong?

You need to use Misc.resolveFile on the path.
Dragon0307 wrote:
Sat Sep 26, 2020 2:20 pm
Also, to solve Baemajinn's question while I'm at it:
This is not an answer to that question. Those are just the constants for the score popup effect.

The real answer is to use Misc.score(newScore), as documented here: https://docs.codehaus.moe/#/reference/misc
Okay, now I have loaded the font through Misc.resolveFile and no more errors! The font hasn't loaded though. Is there anywhere in particular I need to put the textplus.loadFont? Currently, it's right below the Misc.resolve file, as seen here:

Code: Select all

Misc.resolveFile("Fonts/superstarsaga-b.ini")
textplus.loadFont("Fonts/superstarsaga-b.ini")

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby Hoeloe » Sat Sep 26, 2020 11:07 pm

Yeah that's not how that works. Misc.resolveFile returns a string. You're doing exactly the same thing you were doing before, because you don't use the result of Misc.resolveFile anywhere. You need to put that function call instead of the file path when you try to load the font.

You also need to store the font you load in a variable.

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: Need help with lua? - LunaLua General Help

Postby ShadowXeldron » Sun Sep 27, 2020 4:23 am

Hoeloe wrote:
Sat Sep 26, 2020 11:07 pm
Yeah that's not how that works. Misc.resolveFile returns a string. You're doing exactly the same thing you were doing before, because you don't use the result of Misc.resolveFile anywhere. You need to put that function call instead of the file path when you try to load the font.

You also need to store the font you load in a variable.
Aaaaaaah, this really should be in the doccumentation. I assume it is loaded like this?

Code: Select all

fontB = Misc.resolveFile("superstarsaga-b.ini")
But when I load it like this:

Code: Select all

textplus.loadFont(fontB)
I get an error. Probably because I'm still doing the same thing. That said, putting fontB ointo the tab console spits up the file path, as seen here:

Image

I really don't get what I have to do. Would it be possible to provide the correct snippet of code for this?

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Sun Sep 27, 2020 4:28 am

It's not in the lunalua documentation because knowledge about variables is properly explained across tutorials for lua itself, and programming languages as a whole.
The documentation properly describes that loadFont returns a font object...

Code: Select all

local myFont = textplus.loadFont(Misc.resolveFile("path_to_font.ini"))
... and that the textplus's parse function lets you supply a font as an argument, and that the textplus's print shortcut also accepts all the parse parameters.

Code: Select all

textplus.print{
            font = myFont,
            text = "Hello",
            x = 460,
            y = 40,
            maxWidth = 230,
            priority = 2,
            color = Color.red,
            xscale = 2,
            yscale = 2,
        }

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: Need help with lua? - LunaLua General Help

Postby ShadowXeldron » Sun Sep 27, 2020 5:17 am

Enjl wrote:
Sun Sep 27, 2020 4:28 am
It's not in the lunalua documentation because knowledge about variables is properly explained across tutorials for lua itself, and programming languages as a whole.
The documentation properly describes that loadFont returns a font object...

Code: Select all

local myFont = textplus.loadFont(Misc.resolveFile("path_to_font.ini"))
... and that the textplus's parse function lets you supply a font as an argument, and that the textplus's print shortcut also accepts all the parse parameters.

Code: Select all

textplus.print{
            font = myFont,
            text = "Hello",
            x = 460,
            y = 40,
            maxWidth = 230,
            priority = 2,
            color = Color.red,
            xscale = 2,
            yscale = 2,
        }
Oh, okay. Should I come back after learning a bit more about the language itself then?

Goldenemerl64
Fighter Fly
Fighter Fly
Posts: 38
Joined: Tue Jul 07, 2020 3:50 pm

Re: Need help with lua? - LunaLua General Help

Postby Goldenemerl64 » Sun Sep 27, 2020 12:33 pm

What does it mean by updating an older SMBX2b4 install? and how does it work?

baenyth
Koopa
Koopa
Posts: 16
Joined: Mon Sep 07, 2020 6:34 pm
Pronouns: she/her

Re: Need help with lua? - LunaLua General Help

Postby baenyth » Thu Oct 01, 2020 9:27 pm

I tried the Misc.score(newScore) function, but for whatever reason, it didn't work. I used the function in onTick() and a coroutine if that has any effects.
I tried Score with a capital S, but that caused errors.

DigitalDetective47
Bot
Bot
Posts: 56
Joined: Fri Mar 27, 2020 10:12 pm
Pronouns: they/them
Contact:

Help with Achievements

Postby DigitalDetective47 » Thu Oct 01, 2020 10:29 pm

I'm trying to script an achievement, but whenever I run the script, I get an error message. Here is my code:

Code: Select all

function onEvent(FindCave)
	local cave = Achievements(2)
	if not cave.getCondition(1).value then
		cave:progressCondition(0)
		cave:progressCondition(1)
	end
	Misc.dialog(cave:getCondition(0).value)
end
ach-2.ini contains this:

Code: Select all

name="Goomba Plumber"
desc="Find all secret caves in World 1"
condition-0=3
condition-0-desc="Find secret caves"
condition-1=true
condition-2=true
condition-3=true
and my errorlog is this:
Image
What am I doing wrong here?

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Fri Oct 02, 2020 1:07 am

getCondition is also a method, meaning it needs a colon.

DigitalDetective47
Bot
Bot
Posts: 56
Joined: Fri Mar 27, 2020 10:12 pm
Pronouns: they/them
Contact:

Re: Need help with lua? - LunaLua General Help

Postby DigitalDetective47 » Fri Oct 02, 2020 1:58 pm

Enjl wrote:
Fri Oct 02, 2020 1:07 am
getCondition is also a method, meaning it needs a colon.
Thanks for the help! I had a few other fixes, but I needed this to find those issues.

Goldenemerl64
Fighter Fly
Fighter Fly
Posts: 38
Joined: Tue Jul 07, 2020 3:50 pm

Re: Need help with lua? - LunaLua General Help

Postby Goldenemerl64 » Sun Oct 25, 2020 2:35 pm

How do you Trigger Auto scroll on event using the Collectible Trigger?

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: Need help with lua? - LunaLua General Help

Postby ShadowXeldron » Sat Nov 21, 2020 1:46 pm

How do you spawn an item in the player's hand?

Daring Tombstone
Blooper
Blooper
Posts: 160
Joined: Mon Aug 28, 2017 10:57 pm
Flair: What? Not 1000 posts? That means I suck right?

Re: Need help with lua? - LunaLua General Help

Postby Daring Tombstone » Wed Feb 03, 2021 4:38 pm

Image

Shouldn't this be working? It doesn't do anything. I've used rng before so I'm baffled why this isn't doing anything.

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Wed Feb 03, 2021 5:05 pm

You're redefining rng by naming your function rng. Also you can just kinda use rng using the RNG namespace without loading it.

Daring Tombstone
Blooper
Blooper
Posts: 160
Joined: Mon Aug 28, 2017 10:57 pm
Flair: What? Not 1000 posts? That means I suck right?

Re: Need help with lua? - LunaLua General Help

Postby Daring Tombstone » Wed Feb 03, 2021 6:30 pm

I must have been half asleep or something cuz I didn't even notice I named the function rng also. Me being oblivious sorry. Thanks.

Marioman2007
2025 Egg Hunter
2025 Egg Hunter
Posts: 544
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: Need help with lua? - LunaLua General Help

Postby Marioman2007 » Wed Feb 10, 2021 3:01 am

Is there any way to load a specific image for a specific chracter, I tried searching for it in the documentation but couldn't find it.

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Wed Feb 10, 2021 3:29 am

marioman2007 wrote:
Wed Feb 10, 2021 3:01 am
Is there any way to load a specific image for a specific chracter, I tried searching for it in the documentation but couldn't find it.
It's not on the documentation because it's not a thing. What you can do is load an image and internally structure your code so that it's interpreted as something only visible to a certain character, like indexing a table by character ID and putting objects into that element of the table, like so:
local t = {
[CHARACTER_MARIO] = { obj1 = Graphics.loadImage ... },
[CHARACTER_WARIO] = ...
}

t[player.character]returns the object at that index.

Marioman2007
2025 Egg Hunter
2025 Egg Hunter
Posts: 544
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: Need help with lua? - LunaLua General Help

Postby Marioman2007 » Wed Feb 10, 2021 4:13 am

The Code:
Spoiler: show

Code: Select all

local t = {
[CHARACTER_MARIO] = { obj1 = Graphics.loadImage(Misc.resolveFile("modernhud-2.png")) },
}

function onDraw()
    Graphics.draw{
        type = RTYPE_IMAGE,
        image = obj1,
        x = 500,
        y = 100,
        priority = 0,
    }
end

Error:
Spoiler: show
Image Image

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

Re: Need help with lua? - LunaLua General Help

Postby Emral » Wed Feb 10, 2021 4:37 am

obj1 is part of the t table. You must access it through the table. See my previous post for reference.

Marioman2007
2025 Egg Hunter
2025 Egg Hunter
Posts: 544
Joined: Tue Aug 25, 2020 3:19 am
Flair: Dr. Bones
Pronouns: He/Him

Re: Need help with lua? - LunaLua General Help

Postby Marioman2007 » Wed Feb 10, 2021 4:41 am

Enjl wrote:
Wed Feb 10, 2021 4:37 am
obj1 is part of the t table. You must access it through the table. See my previous post for reference.
I do not understand, any examples?


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari