Log In  

Hi,

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

bilodau

P#127003 2023-03-12 00:04

Hi @bilodau:

I'm wondering if you can't use cartdata() and use the same name for its identification so that it would be shared in both carts.

Then you could set the flag in one that can be read by the other.

P#127006 2023-03-12 00:22

Hi @bilodau:

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.

P#127007 2023-03-12 01:18 ( Edited 2023-03-12 01:34)

I think I have a another idea.

Since the map is what's getting copied, I will place a special tile on the map and make it check for this one. If it can't find this tile, then it will trigger an error.

P.S. What does flip() do?

P#127029 2023-03-12 13:52 ( Edited 2023-03-12 13:57)

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()
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.

P#127170 2023-03-15 13:10 ( Edited 2023-03-15 13:14)

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.

I think reload() and cstore() will also not let you read in two separate carts unless you also use the run() command there.

P#127178 2023-03-15 15:37

@dw817 cartdata is the command that only works once per run - reload and cstore work as often as they're called (I just happen to be doing stuff with these commands today).

P#127187 2023-03-15 19:24 ( Edited 2023-03-15 19:24)

@drakeblue what does the reload function return?

P#127188 2023-03-15 19:49

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().

P#127202 2023-03-16 02:36

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.

P#127231 2023-03-16 17:28

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

P#127241 2023-03-16 19:14

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 19:30:33 | 0.049s | Q:24