Advertisement
XeroXipher2022

GoDot Saving System

Dec 5th, 2024
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var savefile_path = "user://player.save"
  3.  
  4. func saveGame():
  5.     var save_data = {
  6.         "Money":
  7.             Player.Money,
  8.         "Level":
  9.             Player.Level,
  10.         "Exp":
  11.             Player.XP,
  12.         "Nexp":
  13.             Player.Nexp
  14.     }
  15.  
  16.     var file = FileAccess.open(savefile_path, FileAccess.WRITE)
  17.     file.store_var(Player.Money)
  18.     file.store_var(Player.Level)
  19.     file.store_var(Player.XP)
  20.     file.store_var(Player.Nexp)
  21.     file.close()
  22.  
  23. func loadGame():
  24.     if(FileAccess.file_exists(savefile_path)):
  25.         var file = FileAccess.open(savefile_path, FileAccess.READ)
  26.         Player.Money = file.get_var(Player.Money)
  27.         Player.Level = file.get_var(Player.Levek)
  28.         Player.XP = file.get_var(Player.XP)
  29.         Player.Nexp = file.get_var(Player.Nexp)
  30.         file.close()
  31.        
  32.     else:
  33.         print("No data has been saved...")
  34.         Player.Money = 0
  35.         Player.Level = 1
  36.         Player.XP = 0
  37.         Player.Nexp = 100
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement