Log In  

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

> PRINT(15 / 8)
1.875
> PRINT(15 // 8)
SYNTAX ERROR
P#100719 2021-11-23 22:28

It does. Just use a backslash. \

P#100721 2021-11-23 22:30

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

P#100722 2021-11-23 22:30

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

P#100723 2021-11-23 22:31

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

> ?9\4
2

> ?9//4
9
P#100731 2021-11-24 00:37
:: dw817

@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.

P#100740 2021-11-24 02:55 ( Edited 2021-11-24 02:56)

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

// this is a line comment
-- so is this
P#100741 2021-11-24 03:05
:: dw817

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 ?

P#100742 2021-11-24 03:16

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).

P#100743 2021-11-24 03:47
:: dw817

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.

P#100745 2021-11-24 03:54 ( Edited 2021-11-24 04:10)

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)
P#100746 2021-11-24 05:16
:: dw817

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 ...

P#100750 2021-11-24 06:09
:: merwok

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.

P#100761 2021-11-24 15:56

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2021-12-07 09:49:36 | 0.065s | Q:29