Hello!
This is my first time developing for the playdate and I’m having trouble with updateTimers().
Whenver i try to call updateTimers() from the update function, it always spits out this error message
main.lua:43: attempt to index a nil value (field 'timer')
stack traceback:
main.lua:43: in function <main.lua:38>
and if I don’t use updateTimers() my game just freezes.
here are revelvant bits of code
local pd = playdate
local gfx = pd.graphics
...
...
...
local isTalking = false
local textToWrite = {}
local textboxImg = gfx.image.new("assets/ui/textbox.png")
local textboxSImg = gfx.image.new("assets/ui/textbox_small.png")
function playdate.update()
if(isTalking == false) then
gfx.clear()
end
pd.timer.updateTimers()
if (gfx.font ~= GBFont) then
gfx.setFont(GBFont)
end
...
...
more code
end
function Talk()
print("talking!")
isTalking = true
Co = coroutine.create(function()
pd.timer.new(100,NextCharacter)
textToWrite = { "Hi! I'm soda! It's nice\nto meet you!", "Woah! Im on the playdate??" }
if(textboxSImg ~= nil) then
for i = 1, #textToWrite, 1 do
print(textToWrite[i])
for c = 1, string.len(textToWrite[i]), 1 do
textboxSImg:draw(100, 156)
print(string.sub(textToWrite[i],1,c))
gfx.drawText(string.sub(textToWrite[i],1,c), textPosX, textPosY)
coroutine.yield()
end
coroutine.yield()
end
isTalking = false
end
end)
coroutine.resume(Co)
end
function NextCharacter()
coroutine.resume(Co)
end
my goal for this is for game to wait just a second so the characters to type themselves out one-by-one. it’s currently too fast and just displays all at once
any help would be appreciated!
running SDK v3.0.6 on Linux Mint
EDIT: I’m stupid, I just had to import CoreLibs/timer