saveload.dd 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #
  2. # save/load program in avdl
  3. #
  4. # it demonstrates how to save and load data
  5. # locally
  6. #
  7. #
  8. # this class contains all data to be saved/loaded.
  9. #
  10. (class TestSaveClass 0
  11. (group
  12. (def int integerToSave)
  13. )
  14. )
  15. #
  16. # default world
  17. #
  18. (class SaveLoadWorld dd_world
  19. (group
  20. (function create (group))
  21. (function clean (group))
  22. )
  23. )
  24. #
  25. # attempt to load the data, if it fails, save data instead
  26. #
  27. (class_function SaveLoadWorld create (group)
  28. (group
  29. # class to hold the data we want to either save or load
  30. (def TestSaveClass myClass)
  31. # success load
  32. (if (== (avdl_data_load myClass TestSaveClass "mysavefile") 0)
  33. (group
  34. (def int myInt)
  35. (= myInt myClass.integerToSave)
  36. (echo "loaded the integer: " myInt)
  37. )
  38. # fail load - save the value instead
  39. (group
  40. (= myClass.integerToSave -123456)
  41. (if (< (avdl_data_save myClass TestSaveClass "mysavefile") 0)
  42. (group
  43. (echo "error saving")
  44. )
  45. (group
  46. (echo "failed to load, so saved the integer -123456")
  47. )
  48. )
  49. )
  50. ) # save/load attempt
  51. )
  52. ) # create
  53. (class_function SaveLoadWorld clean (group) (group))
  54. #
  55. # init function
  56. #
  57. (function dd_gameInit (group)
  58. (group
  59. (dd_setGameTitle "Save Load - avdl")
  60. (dd_world_set_default SaveLoadWorld)
  61. )
  62. )