Fandom

Pico-8 Wiki

Known Bugs

162pages on
this wiki
Add New Page
Comments0 Share

Little wrinkles in PICO-8's language implementation.

Overflow and Distance Calculations Edit

Pico-8's numbers are 16.16 fixed point, with a maximum integer value of 32767. This means it's quite easy to overflow numbers when squaring for distance calculations: 181^2==32761, almost overflowing, so even pixels two screens away will overflow a naive distance calculation. One workaround is to use different units like this:

function distk(x0,y0,x1,y1)
 local dx=x0/1000-x1/1000
 local dy=y0/1000-y1/1000
 local dsq=dx^2+dy^2
 
 if dsq>0 then
  return sqrt(dsq)
 elseif dsq==0 then
  return 0
 else
  --shouldn't happen
  return 32727
 end
end

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.