Log In  


I often use shell scripts to export and then upload my games to itch.io, and there's a small inconvenience that trips me up sometimes: If my game is too large, the export fails, but I have no way of detecting that from my shell script.

> pico8 game.p8 -export "-f froggypaint.html"
EXPORT: -f froggypaint.html
failed: code block too large

> echo $?
0

I would expect the status code (echo $?) to be 1 or some other failure code

(Hm, now that I've written this up I suppose I could work around this by reading stderr stdout and checking for the string "failed"...)

3


1

workaround: instead of pico8 game.p8 -export "-f froggypaint.html", use this instead:

function pico8_export() {
    P8FILE=${1?"need file"}
    EXPORT_ARGS=${2?"need export command"}

    TEMPFILE=$(mktemp)

    pico8 "$P8FILE" -export "$EXPORT_ARGS" | tee "$TEMPFILE"

    # ! = invert, so grep match => failure exit code
    ! grep -q -F -e'fail' -e'not' -e'limit' -e'future version' -e'too many' -e'#include' "$TEMPFILE"
}

pico8_export game.p8 "-f froggypaint.html" || exit 1

# do more stuff here...
echo "success"

today I ran into a situation where pico8 said "could not compress code" which my script didn't catch (b/c it didn't have the string "failed" in it). I glanced through strings pico8 and updated the script with various other messages that it might produce, but it's very possible I missed some


It seems kind of odd that Pico-8 doesn’t set an error code in that situation, but there might be a better workaround you can use. If Pico-8 sends errors to stderr, you can check stderr for output. If there’s anything there, it’s an error. That way, you don’t have to worry about grepping for specific strings.


Yeah, that's a good point. I considered | wc -l to check the number of lines of output (1 line = success, 2+ lines = error) which might be more robust, but this script works well enough so I didn't bother to change it. (and I just checked - pico8 prints the errors to stdout, not stderr, unfortunately)



[Please log in to post a comment]