Achievements in lua

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

Moderator: Userbase Moderators

arthur4272
Koopa
Koopa
Posts: 19
Joined: Sat Feb 19, 2022 2:51 am
Pronouns: he/him

Achievements in lua

Postby arthur4272 » Sat Sep 13, 2025 3:50 pm

I'm trying to make achievements that count the number of stars in the episode, but I'm stuck on the part of apply the code in lua, even with the documentation tutorial I still not understand how to do it (I'm still a beginner in lua), the numbers I want to put in progression in relation to the stars are "1, 30, 60, 90, 120, 241, 242" please can someone help me?

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

Re: Achievements in lua

Postby deice » Sat Sep 13, 2025 3:59 pm

something like this in your episode's global luna.lua file should work (modify the section with the comment to fetch the achievement you need):

Code: Select all

local previousStars = mem(0x00B251E0, FIELD_WORD)
local currentStars = mem(0x00B251E0, FIELD_WORD)

local starCountTable = {
    1, 30, 60, 90, 120, 241, 242
}

function onTickEnd()
    currentStars = mem(0x00B251E0, FIELD_WORD)

    if(currentStars > previousStars) then
        for _, v in ipairs(starCountTable) do
            if(currentStars == v) then
                -- test the current star count here and call collect()
                break
            end
        end
    end

    previousStars = currentStars
end
this is the most barebones version that handles all the logic by itself
if you have achievement conditions set up, it can be streamlined, but you'd need to elaborate on your episode's achievement structure to get any help with that

arthur4272
Koopa
Koopa
Posts: 19
Joined: Sat Feb 19, 2022 2:51 am
Pronouns: he/him

Re: Achievements in lua

Postby arthur4272 » Sat Sep 13, 2025 4:05 pm

my achievements archives about stars is more like
"name = "First Star!"
desc = "Collect 1 Star"
collected-desc = "You collect the first star in the game"
condition-1 = 1
condition-1-desc = "Stars collected"

nothing big stuff, just collecting all the stars in the game

Added in 2 hours 17 minutes 1 second:
I think I get it, I not set the conditions in lua, I'm lost at this too

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

Re: Achievements in lua

Postby deice » Sat Sep 13, 2025 9:12 pm

with conditions, you should be able to ditch the loop entirely and just add progress to all the achievements whenever you collect a star

arthur4272
Koopa
Koopa
Posts: 19
Joined: Sat Feb 19, 2022 2:51 am
Pronouns: he/him

Re: Achievements in lua

Postby arthur4272 » Sat Sep 13, 2025 9:25 pm

local allAchievements = Achievements.get()
Achievements.get(1):progressCondition(1) -- progression: first Star!
if ach_save.secretCount >= 1 and Achievements.get(1).collected == false then
Achievements.get(1):collect() -- Achievement: first Star!
end

like this?


Return to “LunaLua Help”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari