Usually these are done with platform SDKs, like SteamWorks. However, if you just want to DIY them in your own game (for example, if you are not on Steam) then you just need a Dictionary to store booleans or integers that track if an achievement has been unlocked. Here is some sample code I made up.
var achievements = { "Beat Level 1" : false, "Collected 10 Swords" : false, "Swords Collected" : 0 }
func on_level_1_complete():
achievements["Beat Level 1"] = true
func on_pickup_sword():
achievements["Swords Collected"] += 1
if achievements["Swords Collected"] >= 10:
achievements["Collected 10 Swords"] = true