Log In  


Does pico-8 not support Lua's // (floor division) operator?

> PRINT(15 / 8)
1.875
> PRINT(15 // 8)
SYNTAX ERROR


It does. Just use a backslash. \


I guess we just use flr(x / y)?


Ah, any reason why it is different from normal Lua?


PICO-8 extends Lua to support C++-style line comments that begin with "//".

> ?9\4
2

> ?9//4
9

@dddaaannn, you got me curious now.

What does "//" do ? I experimented with it in different ways in Pico-8, even trying NIL, and always only got back the first argument to it.


It starts a line comment, similar to “--“. It’s not a binary operator.

// this is a line comment
-- so is this

Okay, thanks. Wow, I have to laugh, @dddaaannn. :D

Here I was trying to work it into a formula and all I was doing was remming out my results. I couldn't see this of course as I was experimenting in immediate mode.

?34//89

I know ATM there is % ^ * - + / \ << >>

Are there any other mathematical or logical symbols besides those listed - possibly added in this recent update of Pico-8 ?


The manual is thorough about operators: https://www.lexaloffle.com/dl/docs/pico-8_manual.html

Bitwise operators: & | ^^ ~ << >> >>> <<> >><

Logical operators include the comparisons, notably both != and ~= as "not equal" in PICO-8. String concatenation is an operator (..). There's also assignment (=) and all of the modify-and-assign variants (+=, ..=, etc.). #t is considered a unary operator for sequence length. PICO-8 has unary "peek" operators: @ADDR, %ADDR, $ADDR (byte, 2-byte, 4-byte, respectively).


Oh man, lookit all that candy ! Phew ! I will definitely add what you wrote to my reading list.

I do have one more question though, @dddaaannn.

Why have @ADDR() the same as PEEK(), which I use quite often, and why is it faster ? That is not explained in the help file you listed.


It's faster because zep made it faster, maybe for a general intuition that operators should be faster than function calls. It's also one fewer token and six fewer characters. I can see these being useful in tweet carts and fancy memory-based expressions, but someone with more experience than I using them would know better.

fillp(0b0011001111001100)

-- four tokens
patt = %0x5f31

-- five tokens
patt = peek2(0x5f31)

Now that's something I can really look forward to, @dddaaannn. Improved coding ability for tweets. Most of them really rock and are awesome to play if not watch others do so.

I'm in no possession to speed-up my code nor cut down on the tokens. I'll try to continue to use conventional and familiar coding if I can when it's available for my own carts.

It's just interesting to see how far Pico-8 has come ... and what it will become ...


zep made them faster in fake CPU cycles, but they were added in the first place because the bitwise functions had performance issues on real CPU. I don’t remember details, must be in the release thread.



[Please log in to post a comment]