Here is a simple function to convert a number to its hexadecimal string representation:
function num2hex(number) local base = 16 local result = {} local resultstr = "" local digits = "0123456789abcdef" local quotient = flr(number / base) local remainder = number % base add(result, sub(digits, remainder + 1, remainder + 1)) while (quotient > 0) do local old = quotient quotient /= base quotient = flr(quotient) remainder = old % base add(result, sub(digits, remainder + 1, remainder + 1)) end for i = #result, 1, -1 do resultstr = resultstr..result[i] end return resultstr end |
Usage:
print(num2hex(255)) -- ff print(num2hex(10)) -- a print(num2hex(1050)) -- 41a |


I love the simplicity of Pico, but for quick coding like in Game Jams it's nice to have a foundation to work off of. That's why I wrote this toolkit that provides some basic functionality like debugging and physics. Has anyone else done something like this before? Should I add anything else?
Thanks!



Converting shr() safely to simple math:
shr(v, 16) ==> v * 0x.0001 shr(v, 15) ==> v * 0x.0002 ... shr(v, 2) ==> v * 0x.4000 (or 0.25) shr(v, 1) ==> v * 0x.8000 (or 0.5) |
Multiplying by the fraction avoids a hazard where a negative number can go to 0 when dividing by numbers greater than 1, which destroys the sign-extending upper bits you expect to keep with shr().
It also allows shifts up to 16, whereas dividing only allows shifts up to 14. This is because PICO-8 can't represent any powers of 2 larger then 16384.
Similarly, because it is safe to divide by a fractional number less than 1, you can use the same idea to shift left up to 16 bits:
shl(v, 16) ==> v / 0x.0001 shl(v, 15) ==> v / 0x.0002 ... shl(v, 2) ==> v / 0x.4000 (or 0.25) shl(v, 1) ==> v / 0x.8000 (or 0.5) |
In this case, it's down to style or the need to shift by more than 14. Unlike dividing, multiplying by values greater than 1 is safe, so you can also obviously just convert shl(v,2) to v*4. PICO-8 performs divides as fast as multiplies, so performance is the same either way.
Basically, your safe bet is always to use the fractional power of two, whether dividing or multiplying. If you want to be sure, start your constant with "0x." and you'll always get it the right way around. :)
The reason some of us want to do this, rather than the more-intuitive shift calls, is that it saves one token per shift. That can add up quickly in a program heavy with binary math.

Yesterday, I try to create different think. First, I create a little auto tilting system in PICO-8 from this article.
After that, I create a maze generator with the Drunkard Walk algorithm (more information here). It's not very hard but I spend time on that. Finaly, I add a player, and a little hitbox system (with PICO-8 flag systeme), some monster (with lot of bugs), some coins and an exit. I've create a Rogue Like! I think I'm going to add some mecanics so, stay tuned on my Twitter!

Description
This is my platformer in the style of classic Mario games. I called it Platformer Base because I can't think of a good name. Play as the guy with the green helmet, jump on robots and stop their evil machinations once and for all!
Instructions
The game is fairly simple. Jump on the robots with O, and make it to the end of the stages. You can play them in any order you like.
Version
The current version is 1.2 and features the following changes:
+Added a flag that prevents autojumping
+Added SFX that can be toggled on and off
All previously published versions can be found Here.





On yonder thread, where you wisely noted we should stop polluting its subject, you responded to me and said:
[box=404040]Static preprocessors like cpp are a weird fit for dynamic languages like Lua. For example, cpp-style includes have no order-dependent side effects in the languages they're used for (other than in the preprocessor macro language itself, I think?), so they can more simply insert code at first mention. This is not the case in Lua. Lua modules make the handling of side effects in the code explicit, so there's no confusion as to what a require() is expected to do. I'm very interested to know why a Pico-8 developer would prefer an #include-like to a require() because I can't think of a reason, as long as require() is implemented correctly.
Re: defines and such, I think what we actually want, especially in the context of Pico-8, is build-time constant folding and dead code elimination.
But we should take build tool discussion somewhere else, so people can use this thread to discuss Compos. :)



EDIT: Fixed as of 0.2.0!
Original post:
Pretty sure when you originally added _update60(), you compensated for the doubled frame rate when returning time() values, but these days time() is running at double speed when you have _update60() instead of _update().
I noticed this when playing with a simple seven-segment-display demo. Here's one that uses update() and updates once per second as expected:
And this is the same cart, but switched to _update60() and runs twice as fast:

BROOKSATRON was a little "game jam" experiment I made with my little sister. We sat down one afternoon over Thanksgiving and I showed her what sort of wonders PICO-8 had to offer. Over the next couple days, she drew most of the sprites, composed the music, and drew out the levels. It was a lovely weekend.
Inspired by the TweetJam-thread, I tried to make a small game myself - but I ended up at 594 chars (though not optimized at all).
Anyone know how to make this smaller?
(It's an "Air Combat" Mini Game... try to shoot down the attacking planes - before they get you! Controls: Arrows and X to shoot. C to restart.)
/ Pingo


