How To

How to save multiple values

0

TrashCan Games 2021-01-04 08:22

I want to know how to save and load multiple values but I don’t know how


was8bit 2021-01-04 11:25 (Edited)

First, decide if you want one byte values (0-255) or 2byte values (-32768 to 32767)
THEN...

TO LOAD 1byte
Var1=PEEK($E000)
Var2=PEEK($E000+1)
Var3=PEEK($E000+2)

TO LOAD 2byte
Var1=PEEKW($E000)
Var2=PEEKW($E000+2)
Var3=PEEKW($E000+4)

TO SAVE 1byte
POKE $E000,var1
POKE $E000+1,var2
POKE $E000+2,var3

TO SAVE 2byte
POKEW $E000,var1
POKEW $E000+2,var2
POKEW $E000+4,var3


was8bit 2021-01-04 11:27 (Edited)

You can mix up the different sizes, but always remember that 1byte increments by 1 and 2byte increments by 2


was8bit 2021-01-04 11:30 (Edited)

Also, anytime you change the code, it will clear all PERSIST memory..

Also, player can always use the built in option to clear PERSIST memory.

And, when using a program as a tool, it cannot access the game's PERSIST memory

And finally, you cannot transfer PERSIST memory to someone else (no transfering game saves)


nathanielbabiak 2021-01-04 11:52 (Edited)

To transfer persistent memory to someone else, you could add an option in the game's pause menu to save-to-disk with SAVE 4,"PERSIST",$E000,4096 and an option to load-from-disk with LOAD 4,$E000. The user would need to know that the persistent memory is stored in disk.nx too.


was8bit 2021-01-04 12:38

That is true ;)


TrashCan Games 2021-01-04 12:46

Thanks


was8bit 2021-01-04 14:09

Glad to help :)


was8bit 2021-01-04 14:18 (Edited)

Now, lets say you want to create and save a playable randomized layout... well, how do you know if this is the first run or a replay, as you only want to create the layout once, and then thereafter save any changes ...

You reserve the first byte of PERSIST memory to track this... if PEEK($E000)=0, then you create your layout, and be sure to set POKE $E000,1 to let your code know that you have created your layout...

BTW, IF you use BG0 and BG1 to store your game state, you can save both backgrounds entirly into PERSIST...

COPY $9000,$2000 to $E000 to save both backgrounds into PERSIST

COPY $E000,$2000 to $9000 to restore saved backgrounds from PERSIST back into background memory

... this will use up ALL persist memory though....


Log in to reply.