Gfx method missing from Lua API? `field 'fillCircleAtPoint' is not callable (a nil value)`

I'm very new to Lua so its possible that I am just doing something wrong, but I am getting the following error:

pellet.lua:13: field 'fillCircleAtPoint' is not callable (a nil value)
stack traceback:
	pellet.lua:13: in method 'render'
	main.lua:26: in function <main.lua:22>

for the following file:

local geometry = playdate.geometry
local gfx = playdate.graphics

function makePellet(type, xPos, yPos)
  local pellet = { 
    type = type, 
    position = geometry.point.new(xPos, yPos),
    radius = 10
  }

  function pellet:render()
    setDrawStyleFor(type)
    gfx.fillCircleAtPoint(self.position, self.radius)
  end

  return pellet
end

which, based on Inside Playdate, should be a valid function call (unless I am doing something wrong, which I might be)

UPDATE: I found a workaround, by replacing

gfx.fillCircleAtPoint(self.position, self.radius)

with

gfx.fillEllipseInRect(self.position.x, self.position.y, self.diameter, self.diameter)

The fact that this worked seems like a strong indication that fillCircleAtPoint is missing from the API

1 Like

You need to import "CoreLibs/graphics" at the top of your file to use that method.

2 Likes

Ah yes, thank you! Can confirm that this works.

I'm curious why this method requires importing the library and gfx.fillEllipseInRect(self.position.x, self.position.y, self.diameter, self.diameter) does not though

You can take a look at the CoreLibs/graphics code yourself to see why

Ah, I see. drawCircleAtPoint is a syntactic sugar in the CoreLibs/graphics library which calls drawEllipseInRect under the hood

1 Like