Log In  

It'd be awesome to be able to save/load state in your game like old console games.

Maybe a small per/game buffer we can read from/write to.
Or a virtual memory card type device we can access.

P#12074 2015-07-31 00:22 ( Edited 2016-02-11 09:05)

ohh, maybe I can use the cstore somehow to write a save game to the cart! anyone tried this?

P#12075 2015-07-31 03:36 ( Edited 2015-07-31 07:36)

I'm not sure how I'd write a value (like a lua number) to memory and then read it back in a useful way.

for example, how would you go about saving the player's x,y coordinates to memory, storing it to the cart and then read it back and get numbers.

P#12076 2015-07-31 03:58 ( Edited 2015-07-31 07:58)

Saving is on the cards for 0.1.2:

64 bytes from 0x5fc0 will be persistent and automatically saved and restored per cartridge. They can be accessed using PEEK and POKE. e.g.

function save_score(score)
  poke(0x5fc0, flr(score/256))
  poke(0x5fc0, score % 256)
end
function load_score()
  return peek(0x5fc0)*256 + peek(0x5fc1)
end

So it will be possible to cram in enough data for a simple rpg at the most, but not for something like storing a sim city game state.

It would be possible for the cartridge to modify and save itself using cstore() + save(), but this is only supported on some pico-8 platforms where the editing tools are present. It's normally used for things like saving data generated by custom tools. Carts published as pngs to the web or on future platforms won't necessarily support it, for example.

P#12077 2015-07-31 04:55 ( Edited 2015-07-31 08:56)

Thanks for the info zep! 64 bytes sounds like quite the challenge! =)

P#12080 2015-07-31 08:16 ( Edited 2015-07-31 12:16)

oh sweet! I was just planning on coding in passwords :P still might because that's kind of cute

P#12086 2015-07-31 10:50 ( Edited 2015-07-31 14:50)

Welp if all you need is to save the highest level the player's beaten you can still have a looooot of levels.

P#12430 2015-08-07 19:06 ( Edited 2015-08-07 23:06)
3

Cart #18763 | 2016-02-11 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3

Update: v1.0.1 of the demo includes an load_score function that displays raw values of 0x5fc0 and c1.
Also increased the increment from 1 to 10.
v1.0.0 of demo


Cart #18761 | 2016-02-11 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
3


I noticed the load_score function (thanks zep for example code) gives an entirely different value vs just peeking 0x5fc0. Do I need to do something else to the returned score before I can use it?

print(peek(0x5fc0))
-- yields 82

-- using the load function i get 20992

Did some experimenting and suspect it's to avoid overflowing when you hit 256? Do I need to do some bitshifting?

P#18762 2016-02-11 04:05 ( Edited 2016-02-11 10:12)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 11:06:12 | 0.012s | Q:26