Advertisement
Sidorakh

Basic Saving/Loading

Mar 2nd, 2016
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. ///scr_save(filename,remove_supplied_map,vars1,vars2..);
  2. //Up to 112 variables with scr_save_array, potentially infinite with a custom map
  3. //Use scr_save_array to create variable arrays - or just supply with a ds map
  4. //Returns - nothing
  5. var map, key = "", saveMap = ds_map_create();
  6. for (var i=2;i<argument_count;i++)
  7. {
  8. map = argument[i];
  9. key = ds_map_find_first(map);
  10. saveMap[? key] = map[? key];
  11. do
  12. {
  13. key = ds_map_find_next(map);
  14. saveMap[? key] = map[? key];
  15. }
  16. until key == ds_map_find_last(map)
  17. if argument[1]
  18. {
  19. ds_map_destroy(map);
  20. }
  21. }
  22. ds_map_secure_save(saveMap,argument0);
  23. ds_map_destroy(saveMap);
  24.  
  25.  
  26.  
  27. ///scr_save_array(key1,val1,key2,val2..);
  28. //Used if the user cannot use a custom ds_map for whatever reason
  29. //Returns - ds map
  30. var suppMap = sd_map_create();
  31. for (var i=0;i<argument_count/2;i++)
  32. {
  33. suppMap[? (argument[i*2])] = argument[(i*2) + 1];
  34. }
  35. return suppMap;
  36.  
  37.  
  38. ///scr_load(filename);
  39. //Loads the ds map crated in scr_save()
  40. //Returns - ds_map or -1
  41. if !file_exists(argument0)
  42. {
  43. return -1;
  44. }
  45. return ds_map_secure_load(argument0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement