I'm currently working on my custom editor to edit tiles in one of my game, using reload and cstore functions from another cart. But there's something I don't know how to do. I want it to detect if the other cart is present when I launch the editor cart, and output an error message if it isn't. Can someone help me?
Thanks in advance
Thought I would give you an example of this.
This works but it's clumsy. Two separate carts, run in the same directory.
CALL THIS CART NUMBER ONE
-- share data engine one function _init() cls() cartdata("shared") end function _update() if btnp()>0 then a=rnd() ?a.." sent to engine two" dset(0,a) end end
CALL THIS CART NUMBER 2
-- share data engine two cartdata("shared") ?dget(0) flip() run()
I don't think you can share data between two carts where they both run online simultaneously - however the demo carts above will work in LOCAL mode.
The reload function seems to return the number of bytes fetched when called so if it fails it returns 0 (I say "seems to" because I can't see this mentioned in the manual). I think you could do something like:
local did_load=reload(0x2000,0x2000,0x1000,'my_levels.p8') if did_load==0 then print"error: levels didn't load" end
BTW, from the manual:
Flip the back buffer to screen and wait for next frame. This call is not needed when there is a _DRAW() or _UPDATE() callback defined, as the flip is performed automatically.
Hi @bilodau and @drakeblue.
I have the
flip() in there cause the runtime of the 2nd engine that uses the
run() command just about locks out the keyboard. Without it sometimes even the ESC key won't exit it.
cstore() will also not let you read in two separate carts unless you also use the
run() command there.
Actually, @drakeblue, that is correct. Unfortunately you have this 1-second timeout animation that occurs every time you try to read that data loaded and saved with reload() and cstore().
Yeah - it means you can't really use
reload during gameplay, but at startup or between levels or similar it's not so bad and IIRC calling reload several times in a row doesn't cause PICO-8 to wait longer. I've found it's fine while still writing my games.
I'm wondering if I've misunderstood what @bilodau is wanting to do so I'll explain what I meant a bit more:
During development, I've been using
reload to pull in data from a levels.p8 cart at startup that I write to from a separate editor cart using
cstore (and several sprite sheets, music etc. from other carts too). For my use case, I wasn't bothered about checking for it working since it's all on my local machine, but when I saw this post it made me do some testing and notice that
reload returned the number of bytes I was pulling from the cart - or zero if it failed because I'd removed the levels.p8 cart file (and
reload didn't load any bytes).
You could write what I had above more concisely like this btw:
if reload(0x2000,0x2000,0x1000,'my_levels.p8')==0 then print"error: levels didn't load" end
The limitation with this is that it only works with the "offline" version of PICO-8 e.g. while you're still coding your game or if you've bundled multi-carts into an html output or similar (in which case it should always find the cart and never error, making it a bit redundant).
In my game, eventually I'll compress the whole of the cart to squeeze more data in and not need the separate files. This is specifically so the game will still work on the BBS, but I think I'll leave the
reload command there because that way I (or someone else with the editor) could make custom levels that will load when a levels.p8 cart is present in the game directory on their PC and they run PICO-8 locally. Now I think about it, it might be nice to react to a "custom level" game and not wipe the
cartdata save for a standard game or at least say "custom game" when the game runs or something like that, but I'm kinda near the token limit (I'm always near the token limit)...
If I've understood it, @dw817's code is another way of sharing data between carts using only the
cartdata command, which I'm guessing will even work for carts on the BBS(?). It wouldn't work for me as
cartdata only allows 256 bytes of data to be saved and my levels are already bigger than that, but if that's enough space for you it would be kinda neat to allow your editor and game to work together through the BBS. Note: the
cartdata output only exists on the client machine in the browser cache or in a folder on your PC.
As an aside, while you can only call
cartdata one per run on PICO-8, you don't have to call it with the same identifier string every time so there's nothing stopping you from e.g. having the player choose a save slot at the beginning of your game, then calling
cartdata to load/save from that slot ("mygame_1", "my game_2" or similar). The bit I didn't like about this is that it's tricky to display any info about each save slot since you can't read from more than one per run. By passing arguments from the
run() command called in the program and re-running the start of my cart over and over I had something working for this, but I gave up because I didn't have a game to use save slots with yet and it was already taking up quite a lot of tokens (and time). No doubt someone brighter than me has worked out how to do this and more already though.
I don't want to use cartdata for this. Yes @drakeblue, I want the new data to be written to the other cart. I'm making some sort of development tool for the other cart in fact
[Please log in to post a comment]