Log In  


The console is amazing and I'm loving making stuff in it but, to be honest, the in-console editors suck sometimes. Especially the code editor. And sometimes I'd really like to be editing the graphics and music in a more robust program.

One fairly simple feature that would help a lot is auto-reload when a cartridge changes. I pretty much always have a cartridge open in both a text editor, to write Lua code, and in Pico, to test changes. The text editor reloads automatically and that's awesome, but I have to manually reload the cartridge in Pico whenever I make changes to the code. And not only is it tedious, but I'm also prone to forgetting and making and saving some change in Pico, thereby overwriting the data that had been previously saved by the text editor.

In the same vein of making it easier to write code in an external program: Please don't lower-case all my code. It might not matter in Pico's text editor but it does when viewed in an external program.

An alternate cartridge format could help with using external editors, especially for sprite and audio data. A cartridge could be represented by a directory containing one Lua file, an image file containing the sprite data, a data file (perhaps in TMX format, that looks fairly popular?) for map data, another data file for sprite flags, more data files for sound effects and music, hopefully in a standard format. It might get dodgy with the way data can be shared across sprites and maps, for example, but I'm sure there's a way to make it work.

2


In case it helps, there's a keyboard shortcut for reloading the cart from the last known filename: Ctrl-R on Windows and Linux, Cmd-R on a Mac.

I'm already using my picotool library in a dev workflow that involves assembling a cart from multiple files. It'd be trivial to write a tool that merges a Lua file into an existing cart, so you can use Pico-8 to edit graphics and sound on the original cart, then refresh the code with a command-line tool. I plan to make a tool that does this and also supports assembling Lua from multiple files (statically imported libraries). I was hoping to do dead code elimination with this (so unused lib routines don't get added), but it'd probably be useful without that feature.

Such a tool adds the invocation of the tool to the workflow, and doesn't remove the need to reload the cart in Pico-8. The tool could watch files for changes and rebuild the cart automatically (a little "watch" server), but you'd still have to Ctrl-R in the Pico-8 window.


Ctrl-R runs, but it doesn't seem to reload.


It works for me.

Important note: Ctrl-R won't do anything if you've changed the cart in Pico-8 since it was last loaded or saved. You either have to revert the Pico-8 changes by loading the file with the "load" command, or preserve the Pico-8 changes by saving the file (overwriting what's on disk).

(It'd be an improvement if Pico-8 put up a message in this case saying that it's refusing to load the changed file. Not sure what the UX should be exactly, but otherwise it looks like Ctrl-R doesn't do anything.)


Oh, I see - I had tried making a change in pico and reloading. But you're right, with no changes it does indeed reload. That helps!


If you use Sublime Text on OS X, here's a pico-8 build system using applescript:

{
	"shell_cmd": "osascript -e 'tell application \"PICO-8\" to activate' -e 'tell application \"System Events\" \n key code 53 \n \"load $file_name\" \n key code 36 \n delay .1 \n key code 15 using control down \n end tell' -e 'tell application \"Sublime Text\" to activate'"
}

Save it as PICO-8.sublime-build and drop it into the following dir:

/Users/YOUR_USERNAME/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/

In the Sublime menu, select Tools -> Build System -> PICO-8.
Now you can reload your latest changes from sublime via cmd+b :)


Thanks jozanza – super handy. There's something strange though – it worked the first time I modified the code and saved + built, but not after that... I wonder what's up with that?


Yeah, the method is admittedly a little hacky -- but I don't think there's a better way of auto-reloading carts yet :\

One thing that you might try is bumping up some of the delays in the script. You may need to wait longer between commands in order to give Pico-8 more time to load your script before attempting to run it.

I've also noticed that simultaneously editing a cart in Pico-8 and Sublime can cause break the auto-reload script as well. In those cases, it's best to manually load your cart in Pico-8, then try building in Sublime again.

Hope that helps!


Damn, I tried to get the same kinda thing working on windows using Windows Script Host but no dice. (Cant seem to get 'Ctrl-R' (or any non textual keys to trigger as expected)

Maybe the community could help?
// Run on the cmd using wscript or cscript test.js

var wshShell = WScript.CreateObject("WScript.Shell");
wshShell.AppActivate('pico-8');
wshShell.SendKeys("^r"); // doesn't work

(Oh and it assumes that pico 8 is already running)


I'm able to send stuff to PICO-8 with AutoHotkey, so it's definitely possible. One caveat is that I'm having to use "blind" mode, which results in my having to send individual events for, e.g., ctrl down, R down, R up, ctrl up.

Also, in cases where my own hotkeys include a modifier, I have to manually lift the modifier during the duration of my send. E.g., to have shift-del emit ^X (cut), I had do send shift up, ctrl down, X down, X up, ctrl up, shift down. Othewise PICO-8 believes it got shift-ctrl-X. That got me the effect I needed and didn't leave PICO-8 confused about keyboard state.

Maybe try something like that?



Ah! Thanks @Felice I'll give it a shot!

@Neko250, I'm using your packages (and they're great; thanks & initially running using the cartridge runner works flawlessly) but it doesn't seem to trigger a reload on save unless I'm missing something?

Update (taken from @Felice's book) I'm simply using AutoHotKey (not only triggered when from sublime)

reload-p8.ahk

#SingleInstance force
#IfWinActive ahk_exe sublime_text.exe
^s::
Send, {ctrl down}s{ctrl up}
WinGetActiveTitle, Title
IfWinExist, pico-8
  WinActivate
  Send, {ctrl down}r{ctrl up}
IfWinNotActive, %Title%
  WinActivate %Title%
Return
#IfWinActive

You're right, it doesn't trigger auto-reload on PICO-8 at all.
It just launches a new PICO-8 process passing the cartridge as an argument and calling "-run" on it.


Add build command (pico8.exe -run *.p8) for p8 files to Sublime Text 3 editor.

1) press Tools/Build system/New Build system ...
2) put this line:

{
"shell_cmd": "<your path to>pico8.exe -run $file"
}

Note: set full path to your pico8.exe !!! i.e.: e:\pico-8\pico8.exe

3) Save as: Pico8
4) Select Pico8 from Tools/Build system
5) load any p8 file and press CTRL+B

AndyGFX.


Thanks AndyGFX, awesome to be able to build right out of Sublime Text

I did run in to one issue, as that format did not work with Pico in my "Program Files (x86)" folder due to Sublime Text not liking the spaces and parentheses. What did work was formatting it like this:

{
"shell_cmd": "C:/Progra~2/PICO-8/pico8.exe -run $file"
}


Neko - I want to thank you for all of your work with Sublime and Pico-8 ... but, for some reason, I can't get the cartridge runner to work with OSX (10.11.6) -- I've followed your directions but, for whatever reason, when I click the runner option after pressing cmd-shift-P ... well, nothing happens.

I suspect that I'm missing something really simple. About the only thing that I've noticed is that when I change the default path to the app, it doesn't seem to stick. Whenever I click on change default path, it shows :

/path/to/PICO-8.app/Contents/MacOS/pico8

I change it to the correct path but I'm not sure if it is actually sticking. ...

Any thoughts?

D.



[Please log in to post a comment]