mustardplus

Saving/Loading Scripts - GameMaker:Studio

Mar 19th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* HI JIMMY, THIS IS FOR YOU !!!
  2. so for saving I personally have 3 save files + a game settings save file that is separate.
  3. I separated the scripts for Game Settings saving and Game Save Files saving.
  4.  
  5. here's stuff that YOU SHOULD PLEASE READ!:
  6.  
  7. you need a global varialble: global.file
  8. so yeah just: global.file = 0;
  9. this is the save file number you are using, if you will only ever have one file just leave it as 0 forever.
  10.  
  11. [ - - USE FOR SAVE FILES - - ]
  12. Save_File_Real(section, key, value);
  13.     -> Saves numbers to a file
  14. Save_File_String(section, key, value);
  15.     -> Saves strings to a file
  16. Load_File_Real(section, key, default);
  17.     -> Loads a number from a file
  18. Load_File_String(section, key, default);
  19.     -> Loads a strings from a file
  20.  
  21. EXAMPLES:
  22.     Save_File_String("CoolGuy", "Nickname", "Lord of Cool");
  23.     Save_File_Real("Tile27", "XX", 64);
  24.     Save_File_Real("Tile27", "YY", 96);
  25.     var nickname = Load_File_String("CoolGuy", "Nickname", "defaultname");
  26.  
  27.  
  28. [ - - USE FOR GAME SETTINGS - - ]
  29. Save_Game_Real(section, key, value);
  30.     -> Saves numbers to the game settings
  31. Save_Game_String(section, key, value);
  32.     -> Saves strings to the game settings
  33. Load_Game_Real(section, key, default);
  34.     -> Loads a number from the game settings
  35. Load_Game_String(section, key, default);
  36.     -> Loads a strings from the game settings
  37.  
  38. EXAMPLES:
  39.     Save_Game_String("SETTINGS", "Username", "pizzaman");
  40.     Save_Game_Real("SETTINGS", "favoritenumber", 128);
  41.  
  42. [ - - last one - -]
  43. There is actually two more scripts, "Save_Game", and "Load_Game", but mine are written specifically for OtC so you're going to have to make it up idk how you want it.
  44.  
  45. okay now to the code
  46. */
  47.  
  48. /// Save_File_Real(section, key, value);
  49. // Saves numbers to a file
  50. var sect = argument[0], key = argument[1], val = argument[2];
  51. var filename = working_directory+"\\Saves\\"+"File"+string(global.file)+".ini";
  52.  
  53. ini_open(filename);
  54. ini_write_real(sect, key, val);
  55. ini_close();
  56.  
  57.  
  58. /// Save_File_String(section, key, value);
  59. // Saves strings to a file
  60. var sect = argument[0], key = argument[1], val = argument[2];
  61. var filename = working_directory+"\\Saves\\"+"File"+string(global.file)+".ini";
  62.  
  63. ini_open(filename);
  64. ini_write_string(sect, key, val);
  65. ini_close();
  66.  
  67.  
  68. /// Load_File_Real(section, key, default);
  69. // Loads a number from a file
  70. var sect = argument[0], key = argument[1], def = argument[2];
  71. var filename = working_directory+"\\Saves\\"+"File"+string(global.file)+".ini";
  72.  
  73. ini_open(filename);
  74. var data = ini_read_real(sect, key, def);
  75. ini_close();
  76. return data;
  77.  
  78.  
  79. /// Load_File_String(section, key, default);
  80. // Loads a strings from a file
  81. var sect = argument[0], key = argument[1], def = argument[2];
  82. var filename = working_directory+"\\Saves\\"+"File"+string(global.file)+".ini";
  83.  
  84. ini_open(filename);
  85. var data = ini_read_string(sect, key, def);
  86. ini_close();
  87. return data;
  88.  
  89.  
  90. /// Save_Game_Real(section, key, value);
  91. // Saves numbers to the game settings
  92. var filename = working_directory + "GameSave.ini";
  93. var Section = argument[0];
  94. var Key = argument[1];
  95. var Value = argument[2];
  96.  
  97. ini_open(filename);
  98. ini_write_real(Section, Key, Value);
  99. ini_close();
  100.  
  101.  
  102. /// Save_Game_String(section, key, value);
  103. // Saves strings to the game settings
  104. var filename = working_directory + "GameSave.ini";
  105. var Section = argument[0];
  106. var Key = argument[1];
  107. var Value = argument[2];
  108.  
  109. ini_open(filename);
  110. ini_write_string(Section, Key, Value);
  111. ini_close();
  112.  
  113.  
  114. /// Load_Game_Real(section, key, default);
  115. // Loads a number from the game settings
  116. var filename = working_directory + "GameSave.ini";
  117. var Section = argument[0];
  118. var Key = argument[1];
  119. var Default = argument[2];
  120.  
  121. ini_open(filename);
  122. var data = ini_read_real(Section, Key, Default);
  123. ini_close();
  124. return data;
  125.  
  126. /// Load_Game_String(section, key, default);
  127. // Loads a strings from the game settings
  128. var filename = working_directory + "GameSave.ini";
  129. var Section = argument[0];
  130. var Key = argument[1];
  131. var Default = argument[2];
  132.  
  133. ini_open(filename);
  134. var data = ini_read_string(Section, Key, Default);
  135. ini_close();
  136. return data;
Add Comment
Please, Sign In to add comment