Achievement Help

Need help with any SMBX game-related issues? Ask your questions here.
Mal8rk
Snifit
Snifit
Posts: 200
Joined: Mon Oct 25, 2021 11:04 pm
Flair: English Speaking Spanish Speaker
Pronouns: He/Him
Contact:

Achievement Help

Postby Mal8rk » Wed Dec 28, 2022 6:45 pm

Hey everyone

So I've been trying to make achievements for my game, but I've had a couple of questions related to them:

1: How do you make achievements that keep track of things you do in this game? Like an achievement you get by collecting a certain number of star coins, or an achievement where you have to beat all the levels in an episode. Do you need to make a variable that keeps track of those things?

2: When you make an achievement with a condition of collecting a certain ammount of things, like this one:
Image
Do you have to make a variable that keeps track of the things the achievement tells you to get so that the bar can start incrementing?

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

Re: Achievement Help

Postby Emral » Wed Dec 28, 2022 8:07 pm

You should keep track of things the player has done if the achievement sums a collection of "unique" events, a set of events that can only be triggered once by each item in the list. Think of how you don't want the star coin counter to increment when collecting one for the second time.
If you were dealing with something more loose like "collect 9999 coins", you don't have to keep track of that, because it doesn't matter which coin it is, and could simply increment the achievement's counter.

Star coins are already tracked by basegame in the SaveData._basegame.starcoinCounter variable, so you can use that for star coins.

When it comes to levels, the way I usually do it is by checking the winType and making a lookup table to see what levels already had what types of exits collected, to prevent duplicates. Like this:

Code: Select all

SaveData.completion = SaveData.completion or {}
SaveData.completionCount = SaveData.completionCount or 0

function onExit()
	-- Initialize the savedata variable if this is the first time we get an exit in this level
	if SaveData.completion[Level.filename()] == nil then
		SaveData.completion[Level.filename()] = {}
	end
	
	-- Check if we already got this exit
	if SaveData.completion[Level.filename()][Level.winState()] then
		return
	end
	
	-- Track the new exit, increment the counter
	SaveData.completion[Level.fileName()][Level.winState()] = true
	SaveData.completionCount = SaveData.completionCount + 1
	Misc.saveGame()
end
If you have these counter variables you can then simply set the achievement's value to that of the counter to keep it up-to-date.

Mal8rk
Snifit
Snifit
Posts: 200
Joined: Mon Oct 25, 2021 11:04 pm
Flair: English Speaking Spanish Speaker
Pronouns: He/Him
Contact:

Re: Achievement Help

Postby Mal8rk » Mon Jan 02, 2023 6:38 pm

Okay I see, so I don't have to make any sort of variable that keeps track of star coins. I just need to set the achievement value to any number and it will go up depending on how many star coins I got, since the basegame already keeps track of the star coins. Is that how you do it?

And also for the counter variables, does the achievement value go up if you finish a level by something like an offscreen exit, or does it have to be an actual exit for it to go up?

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

Re: Achievement Help

Postby Emral » Mon Jan 02, 2023 7:19 pm

Mal8rk wrote:
Mon Jan 02, 2023 6:38 pm
Okay I see, so I don't have to make any sort of variable that keeps track of star coins. I just need to set the achievement value to any number and it will go up depending on how many star coins I got, since the basegame already keeps track of the star coins. Is that how you do it?
If you set it to "any number", it will go to the value of that number you set it to.
You want to set it to the value of the star coin variable specifically, to make it "go up depending on how many star coins you have".
That's how you do it.
I'm sure that's what you meant to begin with, but just in case there was a misunderstanding rather than just slightly-off wording, I wanted to reiterate.
Mal8rk wrote:
Mon Jan 02, 2023 6:38 pm
And also for the counter variables, does the achievement value go up if you finish a level by something like an offscreen exit, or does it have to be an actual exit for it to go up?
You define in code when an achievement value goes up, so from the outset "exit has to be an actual exit" is in your control. By extension, you need to find a gameplay condition under which to run the code that makes the value go up. The code I posted earlier does that with exits in mind that grant you a victory condition (but has no failsafe for warp/offscreen exits, which do not set the win type).
You might have to modify the code to support offscreen exits, perhaps do a bit of trickery and set the exit value before actually walking offscreen, in situations that you know that exit will certainly be the one the player obtains.


Return to “Help and Support”

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari