Log In  

I suspect this is to do with how lua thinks it can trust numbers vs. how the pico-8 fixed-point numbers are limited, but I'm not sure that's actually the reason. See the end of this post for why I think so.

A for loop will fail, hard, if the end point is -32768 (0x8000.0000), which is a valid (albeit icky) value in PICO-8's fixed-point system:

> for i=-32766,-32768,-1 do print(i) end
-32766
-32767
-32768
32767
32766
32765
... this is the loop that never ends, it just goes on and on my friend ...

This works correctly when hitting the upper bound:

> for i=32766,32767 do print(i) end
32766
32767
> _

If you reverse the params to for, it also fails, but in a different way:

> for i=-32768,-32766 do print(i) end
> _

The same loop works if it starts one higher:

> for i=-32767,-32766 do print(i) end
-32767
-32766
> _

What's weird is that the wrapping of fixed-point values doesn't hurt the loop at the top end, so I'm not clear on why it fails at the bottom end. If it was just a wrapping issue it ought to happen at both ends. That's why I'm not sure it's about lua expecting to be safe doing math beyond the endpoint. Maybe you treat 0x8000 in special ways?

I hope you'll know what's up here, @zep.

P#49152 2018-02-11 02:39 ( Edited 2018-02-11 07:51)


[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-20 10:12:29 | 0.005s | Q:7