I am currently developing my second PICO-8 game. I'm considering adding an option to load my first game directly from the new cart, if the player wants to give it a try.
I know, from the PICO-8 User Manual (section 6.1), that "BBS carts can be loaded from other BBS carts or local carts, but not from exported carts." But how can I detect from which type of cart the code is running?
stat(102)
I know, from the PICO-8 Wiki, that I can use stat(102)
(not officially documented) to gather URL information. For BBS carts, it returns "www.lexaloffle.com". For local carts, it returns 0.
I wrote a simple test cart to investigate a little further.
function _init() s102 = stat(102) end function _update() end function _draw() cls() color(7) print("stat(102):",0,0) print("["..s102.."]",0,6) print("type:"..type(s102),0,18) end |
Here is what I found...
.html standalone, BBS and splore

The .html standalone returns an empty string when running directly from the filesystem. I suppose that, if I upload this somewhere, it will return the domain, like "itch.io".
I don't want to upload this test cart to the BBS, but I suppose it would return "www.lexaloffle.com" if I did, both running from a post in the forum and running from splore.
Can someone confirm this?
.bin standalones and .p8 carts

Unfortunately, both .bin standalones (which can NOT load BBS carts) and .p8 carts running inside PICO-8 (which CAN load BBS carts) returns 0, so I can't use stat(102)
to differentiate.
Note: I only tested the Windows executable.
Any suggestions on another way to detect if the code is running from an exported binary or from a .p8 cart inside PICO-8?



you can run a cart from another one with load("#cart_id")
When you do, everything LUA side is lost, but the high memory isn't cleared so you come up with your own communication protocol between carts by using this space.
Depending on your game, cartdata can suffice, alternatively.



Thanks for replying, @RealShadowCaster. I already knew that, actually.
I'm not doing any communication between carts. I just want to load my first game from my new one in case the player wants to try it.
My only issue is that I would like the code to detect if it's running from an exported binary - if it is, loading another BBS cart won't be possible, so I won't show the option.
I'd also like to confirm that I will be able to load another BBS cart from SPLORE (I hope stat(102)
returns "www.lexaloffle.com", just like running from a forum post.



I think that, if I can't figure out a better solution, I will just try to load("#my_first_game")
and, if that fails, print the URL for the first game's forum post for the player to copy manually. Or simply print a message saying "load failed", perhaps.
But I'd rather detect if I'm running from an exported cart. If that's the case, I think I prefer not to show the loading option at all...



I know you said you don't want to upload the test to the BBS, but you could make an unlisted post and upload it so it won't show in the main feed, only you (or someone with the link) would see it.



Thanks for replying, @2bitchuck. I thought about that... But it wouldn't give me any new information.
You see, I already know that carts on the BBS will return "www.lexaloffle.com" for stat(102)
, and unlisted carts won't show up in SPLORE.
My questions, simplifying them as much as I can, are these:
-
Is there a way to detect that my code is running in an exported cart, so that I don't try to
load("#my_first_game")
? - What happens in SPLORE? Does it return "www.lexaloffle.com" for
stat(102)
? Doesload("#my_first_game")
work?



Ok, so I decided to bite the bullet and posted the test cart as a "Work in Progress".
I also addded the load()
call, using my first game's ID as an example. I even included a breadcrumb parameter to go back to the test cart.
In summary, these are the test results:
- When you get the number 0 from
stat(102)
, the cart may be executing from SPLORE or PICO-8 (in which cases the load call will work) or as an exported binary (in which case the call will fail). - When you get a string from
stat(102)
, you can check its value. If it's "www.lexaloffle.com", the cart is runnning on a BBS forum post (and the load call will work). If it's not, it's running somewhere else (and the call will fail).
I was thinking about deleting the cart, but I think I'll just leave it as a "Work in Progress", so that people may find the post when searching for stat(102)
behaviour. It may be helpful for someone.



Since stat(102) is undocumented, I wonder if a feature request to have specific return values for SPLORE vs. PICO-8 desktop vs. binary export would be possible to implement. I also tend to think that stat(102) would be better if it always returned a number and if the number meant "HTML export" then a different stat() call returned the URL string, but I might just be overthinking this entirely.



I agree, @2bitchuck. I don't know how to request that feature, though...
In the mean time, I decided to implement my feature like this:
- There is an option in my new game that says something like, "play first game".
- When player selects that option, I call load().
- Immediately after the load() call, I assume it failed and show a message saying, "you can play the first game at"... Follwed by the link to the first game's BBS post.
- I don't display error messages. The player will only know something went wrong in the HTML export, because of the "download failed" notification.
In any case, it will be a minor inconvenience. I don't intend to post my games on other forums, and I don't believe many players download the exports I provide in my GitHub projects...
[Please log in to post a comment]