Adding a Power Star for Each Star Coin

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

Moderator: Userbase Moderators

Muffler
Cheep-Cheep
Cheep-Cheep
Posts: 10
Joined: Wed Jan 20, 2021 12:42 pm
Pronouns: he/him

Adding a Power Star for Each Star Coin

Postby Muffler » Fri Dec 13, 2024 6:30 am

I’m working on an SMBX2 episode and could use some help with scripting. In my episode, I’m using the starItemCounters.lua script to track the number of star coins collected in each level. I couldn't find a way to block a level behind a star coin requirement, so I thought: what if I added a power star every time a star coin is collected? That way power stars would act as a total star coins counter and I could use the editor's built-in power star requirement barrier to block certain levels. Problem is, I have no idea how to do that. I tried messing around with scripts but im not familiar with lua language and nothing i tried to do worked. Can anyone help me?

deice
Rocky Wrench
Rocky Wrench
Posts: 603
Joined: Fri Jul 23, 2021 7:35 am

Re: Adding a Power Star for Each Star Coin

Postby deice » Sat Dec 14, 2024 9:39 am

while this might work, i have to recommend against as it would mandate putting each star coin in its own section due to the way vanilla smbx keeps track of collected stars.

instead, you'd be better off creating an individual layer for each distinct star coin requirement and putting each corresponding warp into it (for example, every warp that leads to a level that needs 30 star coins would be in the layer "starCoin30"), having each layer be hidden by default

then, putting something like this in your hub's luna.lua file should do the trick (assuming no star coins can be collected inside the hub itself):

Code: Select all

local layerPrefix = "starCoin" -- change this according to the common prefix of your layer names

function onStart()
    for _, v in ipairs(Layer.find(layerPrefix)) do
        local reqCoins = tonumber(string.sub(v.name, string.len(layerPrefix) + 1))
        if(SaveData._basegame.starcoinCounter and SaveData._basegame.starcoinCounter >= reqCoins) then
            v:show(true)
        end
    end
end

Muffler
Cheep-Cheep
Cheep-Cheep
Posts: 10
Joined: Wed Jan 20, 2021 12:42 pm
Pronouns: he/him

Re: Adding a Power Star for Each Star Coin

Postby Muffler » Sat Dec 14, 2024 11:05 am

Wow that's pretty clever! I'll try doing this and see if it works, thank you so much!! :D


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari