Log In  

I'm working on a Minecraft (2d) clone. I have world generation pretty much complete, but I need to have a way to store said generation. I know that using printh() lets you write to files, but I want to read the contents from an external file like new_world.dat or something similar.

P#121961 2022-12-07 01:31 ( Edited 2022-12-07 01:31)

You can use serial streams:

pico8 -run cart.p8 -i path/to/data

pico8 -run cart.p8 < path/to/data

see https://www.lexaloffle.com/dl/docs/pico-8_manual.html#SERIAL

P#121963 2022-12-07 02:04

pi-geoncraft?

P#121966 2022-12-07 04:17

@merwok, this is something I do not understand, not even with the help provided. I suspect I am not alone.

Could you please show simple working P8 sourcecode example of this ? I think this would be instrumental to most.

Thanks !

P#121969 2022-12-07 07:05

MrAwesome, merwok pointer is good for local development but going to force users drag&dropping files to run game.

To save game data, you may use cstore() or reload() - see manual - to distribute data packaged with the game.

P#121970 2022-12-07 07:37

Create this cart in PICO-8 and save it as mycart.p8:

cls()
repeat
 size = serial(0x804,0x4300,0x1000)
 for i=0,size do
  print(chr(peek(0x4300+i)).."\0")
 end
until(size == 0)

In a text editor, create a file named limerick.txt:

the limerick packs laughs
    anatomical
into space that is quite
    economical.
  but the good ones i've seen
  so seldom are clean
and the clean ones so seldom
    are comical.

Start PICO-8 from the host operating system's command line, running mycart.p8 and pouring in limerick.txt as standard input:

pico8 < limerick.txt -run mycart.p8

As mentioned, this only works from the developer kit, and is not available in an exported cart or a cart uploaded to the BBS.

P#121971 2022-12-07 07:43 ( Edited 2022-12-07 07:45)

I rewrote the wiki page on serial(). Someone check my work, I made a couple of guesses.

P#121972 2022-12-07 08:52

@dddaaannn that looks like it'll work, but quick question, does the term 'exported cart' include ones that are exported as an application or just the web files?

P#122014 2022-12-08 04:03

It includes exported binaries as well as exported web. The file and stream access is not really intended for games, they’re more for tools. Drag and drop works in exported versions, with size limits, though that’s only an input, not an output.

In general, PICO-8 games aren’t able to persist large quantities of data to disk as part of gameplay. I only described the serial() example to elaborate merwok’s mention. If you’re willing to limit your game to being playable only in the “dev kit” PICO-8 app, you might be able to use some of these features.

P#122017 2022-12-08 04:32

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 12:16:15 | 0.022s | Q:24