Page 15 of 32
Re: Need help with lua? - LunaLua General Help
Posted: Sat Sep 26, 2020 3:46 pm
by ShadowXeldron
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.
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")
Re: Need help with lua? - LunaLua General Help
Posted: Sat Sep 26, 2020 11:07 pm
by Hoeloe
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.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Sep 27, 2020 4:23 am
by ShadowXeldron
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:
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:
I really don't get what I have to do. Would it be possible to provide the correct snippet of code for this?
Re: Need help with lua? - LunaLua General Help
Posted: Sun Sep 27, 2020 4:28 am
by Emral
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,
}
Re: Need help with lua? - LunaLua General Help
Posted: Sun Sep 27, 2020 5:17 am
by ShadowXeldron
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?
Re: Need help with lua? - LunaLua General Help
Posted: Sun Sep 27, 2020 12:33 pm
by Goldenemerl64
What does it mean by updating an older SMBX2b4 install? and how does it work?
Re: Need help with lua? - LunaLua General Help
Posted: Thu Oct 01, 2020 9:27 pm
by baenyth
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.
Help with Achievements
Posted: Thu Oct 01, 2020 10:29 pm
by DigitalDetective47
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:

What am I doing wrong here?
Re: Need help with lua? - LunaLua General Help
Posted: Fri Oct 02, 2020 1:07 am
by Emral
getCondition is also a method, meaning it needs a colon.
Re: Need help with lua? - LunaLua General Help
Posted: Fri Oct 02, 2020 1:58 pm
by DigitalDetective47
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.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Oct 25, 2020 2:35 pm
by Goldenemerl64
How do you Trigger Auto scroll on event using the Collectible Trigger?
Re: Need help with lua? - LunaLua General Help
Posted: Sat Nov 21, 2020 1:46 pm
by ShadowXeldron
How do you spawn an item in the player's hand?
Re: Need help with lua? - LunaLua General Help
Posted: Wed Feb 03, 2021 4:38 pm
by Daring Tombstone
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.
Re: Need help with lua? - LunaLua General Help
Posted: Wed Feb 03, 2021 5:05 pm
by Emral
You're redefining rng by naming your function rng. Also you can just kinda use rng using the RNG namespace without loading it.
Re: Need help with lua? - LunaLua General Help
Posted: Wed Feb 03, 2021 6:30 pm
by Daring Tombstone
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.
Re: Need help with lua? - LunaLua General Help
Posted: Wed Feb 10, 2021 3:01 am
by Marioman2007
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.
Re: Need help with lua? - LunaLua General Help
Posted: Wed Feb 10, 2021 3:29 am
by Emral
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.
Re: Need help with lua? - LunaLua General Help
Posted: Wed Feb 10, 2021 4:13 am
by Marioman2007
The Code:
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:
Re: Need help with lua? - LunaLua General Help
Posted: Wed Feb 10, 2021 4:37 am
by Emral
obj1 is part of the t table. You must access it through the table. See my previous post for reference.
Re: Need help with lua? - LunaLua General Help
Posted: Wed Feb 10, 2021 4:41 am
by Marioman2007
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?