Achievements Functions
Functions to make softcoded Achievements.
getAchievementScore
getAchievementScore(name:String):Float
Returns the score for Achievements with counters (like "Roadkill Enthusiast").
Returns -1 and throws an error if the Achievement couldn't be found.
- name - Achievement internal name.
Examples:
- getAchievementScore('roadkill_enthusiast') - Will Return the current score of "Roadkill Enthusiast".
setAchievementScore
setAchievementScore(name:String, ?value:Float = 0, ?saveIfNotUnlocked:Bool = true):Float
Sets the score for Achievements with counters (like "Roadkill Enthusiast") and returns its new value.
Returns -1 and throws an error if the Achievement couldn't be found.
- name - Achievement internal name.
- value - Value to set the score to.
- saveIfNotUnlocked - Optimization, in case you constantly change the score, set to false.
Examples:
- setAchievementScore('my_achievement_name', 25) - Will set the current score of "my_achievement_name" to 25 and save, even if doesn't unlock the achievement.
- setAchievementScore('my_achievement_name', 3, false) - Will set the current score of "my_achievement_name" to 3 and save only if it unlocks the achievement
addAchievementScore
addAchievementScore(name:String, ?value:Float = 1, ?saveIfNotUnlocked:Bool = true):Float
Adds score for Achievements with counters (like "Roadkill Enthusiast") and returns its new value.
Returns -1 and throws an error if the Achievement couldn't be found.
- name - Achievement internal name.
- value - Value to add to the score.
- saveIfNotUnlocked - Optimization, in case you constantly change the score, set to false.
Examples:
- addAchievementScore('my_achievement_name') - Adds +1 to the score of "my_achievement_name" and save, even if doesn't unlock the achievement.
- addAchievementScore('my_achievement_name', 1, false) - Add +1 to the score of "my_achievement_name" and save only if it unlocks the achievement.
unlockAchievement
unlockAchievement(name:String):String
Unlocks a named achievement and returns its name, returns null if already unlocked.
Throws an error if achievement doesn't exist and returns null.
- name - Achievement internal name.
Examples:
- unlockAchievement('my_achievement_name') - Unlocks "my_achievement_name".
isAchievementUnlocked
isAchievementUnlocked(name:String):Dynamic
Checks if achievement is unlocked and returns true/false for it.
Returns null and throws an error if achievement doesn't exist.
- name - Achievement internal name.
achievementExists
achievementExists(name:String):Bool
Checks if achievement exists returns true/false for it.
- name - Achievement internal name.