I'm getting this error from both my physical Playdate running 1.12.2 and the 1.12.2 PlaydateSimulator, and I cannot figure out why. Changes to a vector2d cause a call to math.floor, a call which doesn't involve the vector2d at all, directly or indirectly, to fail with this error:
Update error: main.lua:12: bad argument #1 to '(temp)' (number expected, got playdate.geometry.point)
stack traceback:
[C]: in function 'math.floor'
main.lua:12: in function <main.lua:6>
I'm using pdc 1.12.2 and PlaydateSimular 1.12.2 on Ubuntu 20.04.4 running on an Intel x86-64 system. I build my project with "pdc src Oddbehavior.pdx". I run it with "PlaydateSimulator Oddbehavior.pdx". The entire contents of src are pdxinfo and main.lua.
src/pdxinfo:
name=Odd behavior
author=Alan De Smet
description=Testing odd behavior
bundleID=com.highprogrammer.test-program
version=0.1
buildNumber=100
This version of the program works; the Playdate Console fills with "(0.0, 0.0)" 30 times or so per second:
src/main.lua: (working version)
local Point <const> = playdate.geometry.point
local Vector <const> = playdate.geometry.vector2D
TEST_SIZE = Point.new(0, 0)
function playdate.update()
local max_cells = Vector.new(0,0)
max_cells.dx -= 0
max_cells.dy -= 0
local second_point = Point.new(0, 0)
second_point.x -= math.floor(TEST_SIZE.x)
second_point.y -= math.floor(TEST_SIZE.y)
print(second_point)
end
But a bunch of inexplicable things break it, generating this error. When things go wrong, they generate this error:
stack traceback:
[C]: in function 'math.floor'
main.lua:12: in function <main.lua:6>
Update error: main.lua:12: bad argument #1 to '(temp)' (number expected, got playdate.geometry.point)
Error case: Comment out both "max_cells.SOMETHING -= 0
" lines. That should do nothing. And even if it did something, max_cells is never referenced again after yet. But it fails.
src/main.lua: (broken version)
local Point <const> = playdate.geometry.point
local Vector <const> = playdate.geometry.vector2D
TEST_SIZE = Point.new(0, 0)
function playdate.update()
local max_cells = Vector.new(0,0)
--max_cells.dx -= 0
--max_cells.dy -= 0
local second_point = Point.new(0, 0)
second_point.x -= math.floor(TEST_SIZE.x)
second_point.y -= math.floor(TEST_SIZE.y)
print(second_point)
end
Alternatively, initialize max_cells using the full namespace to vector2D instead of the local alias and it fails:
src/main.lua: (broken version)
local Point <const> = playdate.geometry.point
local Vector <const> = playdate.geometry.vector2D
TEST_SIZE = Point.new(0, 0)
function playdate.update()
local max_cells = playdate.geometry.vector2D.new(0,0)
max_cells.dx -= 0
max_cells.dy -= 0
local second_point = Point.new(0, 0)
second_point.x -= math.floor(TEST_SIZE.x)
second_point.y -= math.floor(TEST_SIZE.y)
print(second_point)
end