Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Looking for a save/load function

    Functions
    4
    11
    465
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • vinicity
      vinicity F last edited by

      If you are using pianofire's persistent code, you can just do it like this:

      To load stuff in your init function:

      store = []
      if loadStore() then
          playerStore.PGold = getValue("PGold")
          playerStore.keys = getValue("keys")
          playerStore.life = getValue("life")
          playerStore.x = getValue("x")
          playerStore.y = getValue("y")
      endif
      

      Note that the loadStore() function returns false if there was no persistent data already saved, so you will then need to populate playerStore with some default values. Also note that store needs to be a global variable.

      To save stuff whenever necessary:

      setValue("PGold", playerStore.PGold, "int")
      setValue("keys", playerStore.keys, "int")
      setValue("life", playerStore.life, "int")
      setValue("x", playerStore.x, "int")
      setValue("y", playerStore.y, "int")
      saveStore()
      
      waldron 1 Reply Last reply Reply Quote 2
      • waldron
        waldron F @vinicity last edited by

        @vinicity cheers I'l have another bash at it, always overwhelming trying something new but i feel i can handle that
        as long as i can get one working then the rest will follow

        1 Reply Last reply Reply Quote 1
        • Ithendall
          Ithendall last edited by

          I do it in my car race game one value at a time, you can have a look.

          waldron 1 Reply Last reply Reply Quote 1
          • PickleCatStars
            PickleCatStars F last edited by

            Defo use pianofire’s code for this. It makes it so easy!

            1 Reply Last reply Reply Quote 2
            • waldron
              waldron F @Ithendall last edited by

              @Ithendall cheers, nice to have a game as reference plus i'v not managed to play it yet been busy in a coding frenzy haha

              1 Reply Last reply Reply Quote 1
              • Ithendall
                Ithendall last edited by

                Well, it is still in progress, not finished :)

                1 Reply Last reply Reply Quote 0
                • PickleCatStars
                  PickleCatStars F last edited by

                  For lists of stuff like that, I do (for example)

                  For x = 1 to 10 loop
                      SetValue(”myList[”+str(x)+”]”,myList[x],”int”)
                  repeat```
                  ..or something like that. See how it works?
                  waldron 1 Reply Last reply Reply Quote 1
                  • waldron
                    waldron F @PickleCatStars last edited by waldron

                    Nevermind i think i'v figured it :)

                    1 Reply Last reply Reply Quote 1
                    • PickleCatStars
                      PickleCatStars F last edited by

                      I was just giving another example for if you have an array of structs, or a highscore list or something. It wasn’t aimed at your question there. Good you got it sorted though :)

                      waldron 1 Reply Last reply Reply Quote 1
                      • waldron
                        waldron F @PickleCatStars last edited by

                        @toxibunny yeah i got that, i'm fine with this for now though thanks man

                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post