Log In  


I'm trying to prepare a pico-8 web export that won't start up the game until the user has pressed a button. This is useful for determining whether to display a touch interface or a desktop interface based on the type of event we get.

My current solution is to dynamically add the game script tag to the document after the user clicks. This is working on my Android device but it seems to have issues on my friend's iPhone - there is no sound! I believe the problem is that the audio is taking too long to start after the button is pressed, so the iPhone browser believes the page is trying to serve audio that wasn't initiated by the user, and blocks it.

The ideal solution would be to add the script tag to the HTML document without any fancy async script loading, so the game parses and prepares immediately, but to just defer the part where the cart actually runs until I emit some kind of event to say "ok, you can play the cart now." I was having trouble finding a way to do this. Is there any documented (or undocumented) method I may have missed?

I noticed the Module object can use an array of "preRun" callbacks but there doesn't seem to be any obvious way to defer execution.

P#51251 2018-04-03 09:56 ( Edited 2018-04-03 16:58)

I was wondering this same thing the other day. Basically it would be cool if the HTML5 export could have the same "play" button overlay as the one that shows up here on the BBS.

P#51252 2018-04-03 10:36 ( Edited 2018-04-03 14:59)

Yeah I agree! I suspect that's coming in the next big release but a way to do that manually in the meantime would be a lifesaver for me.

P#51255 2018-04-03 11:12 ( Edited 2018-04-03 15:12)

I dug into the export source code and found a way to do this.

When you're creating the Module object before the game script include:

var Module = {};
// ...
Module.noInitialRun = true;
<script src="mygame.js"></script>
// called sometime later.......
function startGame() {
  Module.calledRun = false;
  window.shouldRunNow = true;

This doesn't seem to be documented so it could definitely change in a future release.

P#51261 2018-04-03 11:57 ( Edited 2018-04-03 15:58)

P.S. For what it's worth the BBS version seems to asynchronously add the script tag as I was doing, so it may have the same audio issues on mobile.

P#51267 2018-04-03 12:58 ( Edited 2018-04-03 16:58)

[Please log in to post a comment]