Page 25 of 32
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jun 20, 2022 4:33 pm
by Hoeloe
TRUE. I did make the docs after reading this post because I thought they might help, and forgot to link them once I was done haha.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Jun 20, 2022 5:33 pm
by deice
Hoeloe wrote:
I did make the docs after reading this post
damn, you guys should post questions here more often

(kidding of course, the docs are actually pretty good atm)
Re: Need help with lua? - LunaLua General Help
Posted: Sat Jul 02, 2022 8:48 pm
by Daring Tombstone
I haven't been here in a while but I'm looking for a way to stop Link from being able to bounce on spikes. Not great at lua but thought there must be a way better than mine which was putting collider boxes a touch above spikes to harm the player.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jul 03, 2022 9:36 am
by deice
Daring Tombstone wrote: ↑Sat Jul 02, 2022 8:48 pm
I haven't been here in a while but I'm looking for a way to stop Link from being able to bounce on spikes. Not great at lua but thought there must be a way better than mine which was putting collider boxes a touch above spikes to harm the player.
technically you don't need any custom lua for that. there's already block 672 which is a solid hurt block that link cannot bounce off.
i guess a slightly cleaner solution if you absolutely need to use the vanilla spikes would be to make a custom block that mimics them? i don't know of a documented memory offset that lets you control link's down stab (and even if there was it would probably make you unable to down stab npcs as well, and i assume you don't want that)
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jul 03, 2022 11:45 am
by Daring Tombstone
Never thought about using the hurt block. I could try that instead of some lua solution. Thanks.
Re: Need help with lua? - LunaLua General Help
Posted: Sat Jul 23, 2022 11:51 am
by LunarCatUSA
Any way I could make an NPC chase the player?
Just along the ground, not in the sky as if it were a parakoopa, I mean.
Added in 2 hours 19 minutes 5 seconds:
In this case, I have a JSON field for all NPCs:
Code: Select all
{
"control": "checkbox",
"name": "chasesMe",
"title": "Chase Player?",
"tooltip": "Do you chase the player?",
"value-default": false
}
So now, the game is intended to override the NPCs current speed and direction with this:
Code: Select all
function onStart()
Hostiles = NPC.get()
end
function onTick()
-- Chase Player --
for k,v in ipairs(Hostiles) do
if v.data._settings._global.chasesMe then
local cx = v.x + 0.5 * v.width
local p = player
local d = -vector(v.x - p.x + p.width):normalize() * 0.1
local speed = NPC.config[v.id].speed
v.speedX = v.speedX + d.x * NPC.config[v.id].speed
v.speedX = math.clamp(v.speedX, -4, 4)
end
end
end
Re: Need help with lua? - LunaLua General Help
Posted: Sun Jul 24, 2022 2:11 am
by LunarCatUSA
Okay, so I just updated it so that the NPC follows the player.
Code: Select all
function onTick()
Hostiles = NPC.get()
-- Chase Player --
for k,v in ipairs(Hostiles) do
if v.data._settings._global.chasesMe then
Text.print(Distance, 70, 70)
Text.print(v.direction, 70, 90)
closeplayer = Player.getNearest(v.x,v.y)
Distance = closeplayer.x - v.x
if Distance < 0 then
v.direction = -1
end
if Distance >= 0 then
v.direction = 1
end
end
end
end
Problem is, they'll change direction initially, but if you go past them, they don't change direction. I'm not sure, but they seem to remain going in one direction regardless.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Aug 09, 2022 7:09 am
by BrokenAce
I'm having two problems setting up my custom HUD.
1. I can't remove the weird 2-pixel spacing between numbers
2. For some reason, the coin counter uses vanilla graphics for its numbers despite the fact I have replaced the hardcoded number graphics with SMB3 style ones in my episode folder
Basically, right now it looks like this:

but I want it to look like this:
Hoping this won't be too difficult to fix.
Re: Need help with lua? - LunaLua General Help
Posted: Tue Aug 09, 2022 8:03 am
by Marioman2007
BrokenAce wrote: ↑Tue Aug 09, 2022 7:09 am
2. For some reason, the coin counter uses vanilla graphics for its numbers despite the fact I have replaced the hardcoded number graphics with SMB3 style ones in my episode folder
Create folder called "textplus" and then another folder inside it "font"
then copy 1.png from "SMBX2 > data > scripts > textplus > font" and then you can edit it
Re: Need help with lua? - LunaLua General Help
Posted: Tue Aug 09, 2022 11:32 am
by BrokenAce
Marioman2007 wrote: ↑Tue Aug 09, 2022 8:03 am
BrokenAce wrote: ↑Tue Aug 09, 2022 7:09 am
2. For some reason, the coin counter uses vanilla graphics for its numbers despite the fact I have replaced the hardcoded number graphics with SMB3 style ones in my episode folder
Create folder called "textplus" and then another folder inside it "font"
then copy 1.png from "SMBX2 > data > scripts > textplus > font" and then you can edit it
Thanks, this does the trick perfectly for the coins. Now, if only I could also remove the spacing in the lives/stars counters or replace those with textplus font1 as well. Afaik, there is nothing in huboberride.lua that determines which counters are displayed as textplus, so this is probably not going to be easy to solve.
Re: Need help with lua? - LunaLua General Help
Posted: Fri Aug 19, 2022 11:42 pm
by LunarCatUSA
I'm trying to make a layer disappear but it's not working.
Code: Select all
for k,w in ipairs(Layer.get("WallsafeLock")) do
w:hide(false)
end
What am I doing wrong? The event that would normally hide the layer occurs just fine so something's wrong with the layer visibility command I guess.
Re: Need help with lua? - LunaLua General Help
Posted: Sat Aug 20, 2022 12:01 am
by Emral
https://docs.codehaus.moe/#/reference/layer
Layer.get(name) returns the layer with that name, not a list of layers. Store it into a local variable and call :hide() on that local variable. No need for a for loop.
Re: Need help with lua? - LunaLua General Help
Posted: Sat Aug 20, 2022 6:28 am
by BrokenAce
A quick question - is it possible to modify the game's slippery/ice physics? I'd like to change the acceleration/deceleration properties of slippery blocks to better fit Enjl's playerphysicspatch.lua, if possible.
Re: Need help with lua? - LunaLua General Help
Posted: Sun Aug 21, 2022 10:30 pm
by LunarCatUSA
Question,
Is there a way to call a random variable everytime a new episode is started?
This is to give a certain item a randomized location and give the game some replay value.
Like this,
Upon starting a game in the episode, var will randomly equal 1, 2, or 3.
if var = 1:
Item goes to level 1 as opposed to level 2 or level 3
if var = 2:
item goes to level 2 as opposed to level 1 or level 3
if var = 3:
item goes to level 3 as opposed to level 1 or level 2
Re: Need help with lua? - LunaLua General Help
Posted: Mon Aug 22, 2022 1:07 am
by Marioman2007
LunarCatUSA wrote: ↑Sun Aug 21, 2022 10:30 pm
Question,
Is there a way to call a random variable everytime a new episode is started?
This is to give a certain item a randomized location and give the game some replay value.
Like this,
Upon starting a game in the episode, var will randomly equal 1, 2, or 3.
if var = 1:
Item goes to level 1 as opposed to level 2 or level 3
if var = 2:
item goes to level 2 as opposed to level 1 or level 3
if var = 3:
item goes to level 3 as opposed to level 1 or level 2
https://docs.codehaus.moe/#/reference/rng
Re: Need help with lua? - LunaLua General Help
Posted: Mon Aug 22, 2022 9:43 am
by LunarCatUSA
Oh, I know how to use a random variable, calling it when the episode first starts is the thing, like maybe when the overworld loads for the first time and then done.
Although, I guess I can also load a random global variable to save on the intro level. Maybe that'll be easier.
Re: Need help with lua? - LunaLua General Help
Posted: Mon Aug 22, 2022 12:30 pm
by deice
LunarCatUSA wrote: ↑Mon Aug 22, 2022 9:43 am
Oh, I know how to use a random variable, calling it when the episode first starts is the thing, like maybe when the overworld loads for the first time and then done.
Although, I guess I can also load a random global variable to save on the intro level. Maybe that'll be easier.
if you do use an overworld, putting this in your map.lua should do the trick:
Code: Select all
function onStart()
if(SaveData.randomGlobalVar == nil) then
SaveData.randomGlobalVar = RNG.randomInt(1, 3)
end
end
then, you can spawn items accordingly by checking in each level's luna.lua:
Code: Select all
function onStart()
local seekValue = 1 -- value corresponding to this level
if(SaveData.randomGlobalVar == seekValue) then
-- do stuff here
end
end
Re: Need help with lua? - LunaLua General Help
Posted: Tue Aug 23, 2022 1:10 pm
by LunarCatUSA
Is there a way to trigger an event upon warping through a specific door?
Or at least manually trigger a warp upon an event occurring?
Re: Need help with lua? - LunaLua General Help
Posted: Wed Aug 24, 2022 4:35 pm
by LunarCatUSA
Okay, here's another question.
I put various image files into another folder within my episode folder to make a less crowded library. The thing is,
Item = Graphics.loadImage(Misc.resolveFile("MyItem.png")) returns an error message. Isn't the resolve supposed to load this folder on its own?
Is there something I should add the Graphics.loadImage command?
Re: Need help with lua? - LunaLua General Help
Posted: Wed Aug 24, 2022 4:43 pm
by deice
LunarCatUSA wrote: ↑Wed Aug 24, 2022 4:35 pm
Okay, here's another question.
I put various image files into another folder within my episode folder to make a less crowded library. The thing is,
Item = Graphics.loadImage(Misc.resolveFile("MyItem.png")) returns an error message. Isn't the resolve supposed to load this folder on its own?
Is there something I should add the Graphics.loadImage command?
it's always best to read
the fine print. resolveFile won't look absolutely everywhere, and has a strictly defined search pattern. if the file is in an arbitrary folder, you have to also include the folder name:
Code: Select all
Graphics.loadImage(Misc.resolveFile("Folder/MyItem.png"))
however, if the lua file itself is right in your episode folder too (as opposed to a level's custom folder), the resolveFile() call is superfluous and can be removed:
Code: Select all
Graphics.loadImage("Folder/MyItem.png")