No such function 'update'

I am new to programming with Lua for the playdate and need help with this issue. The issue I am having is the error message “no such function ‘update’” pops up when I try to run my code. I have seen other people have this problem and all have it solved by adding an update function. But I already have an update function. The strange thing is, I can still run my program by deleting part of the update function in main.lua and then re-writing it. It is almost as if I have to remind the program that the update function is there.

I’m on a Apple M1 pro

what does your code look like. You’re update function should be like this:

function playdate.update()
-- My code
end

exactly the same unless you see something i’m not

function pd.update()
    gfx.sprite.update()
    pd.timer.updateTimers()
    gfx.drawTextAligned(" *"..letterSelected.."* ", 40, 0, kTextAlignment.center)
    gfx.drawTextAligned("*"..currentWord.."*", 400, 0, kTextAlignment.right)
    gfx.drawRect(0, 16, 400, 2)
    gfx.drawRect(0, 16, 8, 240)
    gfx.fillRect(0, 240-2.24*player.health, 8, 240)
end

btw i set pd = playdate at the beginning

Have you defined playdate.graphics.sprite.update, it's something you need to define yourself I'm pretty sure (if you need it, if you don't then you can just remove that call)?

playdate.graphics.sprite.update() calls :update() on all sprites that have been added to the update list and afaik you don't necessarily even need to define the function.

I'd play it safe and write function playdate.update(). The main loop might have some magic to it that prevents a reference from working.

yes I have defined gfx = playdate.graphics

I tried this and it doesn’t fix it. maybe its some sort of bug

What’s in your code above function pd.update()...? Maybe some syntax error higher up is messing with the update function?

here it is. for reference i am making a game about spelling words to cast spells

import "Player.lua"
import "Map.lua"
import "Enemy.lua"
import "CoreLibs/object"    
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/timer"

local pd <const> = playdate
local gfx <const> = pd.graphics 
tileSize = 32
letters = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z','Submit'}
pd.display.setInverted(true)


PLANT_WORDS = {
  "PLANT","LEAF", "ROOT", "VINE", "BLOOM", "SPROUT", "SEED", "PETAL", "STEM", "FLOWER", "TREE",
  "FOREST", "GRASS", "HERB", "SHRUB", "MOSS", "FERN", "SAP", "BUD", "BRANCH", "GARDEN", "GROW", "NATURE",
  "WILD", "WILDERNESS", "JUNGLE", "BUSH", "CREEPER", "TWIG", "FROND", "CANOPY", "FOLIAGE", "THORN", "BARK", "CLOVER",
  "DANDELION", "IVY", "LAWN", "MEADOW", "ORCHARD", "POLLEN", "VIRIDIAN"
}

FIRE_WORDS = {
  "SUN","FIRE","FLAME", "EMBER", "BLAZE", "SCORCH", "IGNITE", "INFERNO", "TORCH", "COMBUST", "BONFIRE", "SPARK",
  "CHAR", "SINGE", "PYRE", "HEAT", "FIRESTORM", "WILDFIRE", "FURNACE", "CANDLE", "ASHES", "SMOKE", "BURN", "GLOW", 
  "LIGHT", "FLARE", "BLAZING", "SIZZLE", "ROAST", "TOAST", "KINDLE", "FURY", "RAGE", "BURNING"
}

EARTH_WORDS = {
  "ROCK", "STONE", "SOIL", "BOULDER", "MUD", "CLAY", "DIRT", "SAND", "QUARTZ", "CAVE",
  "MOUNTAIN", "VALLEY", "HILL", "PLATEAU", "CRUST", "CORE", "MINERAL", "FOSSIL", "TERRAIN", "PEBBLE", "GRAVEL",
  "BEDROCK", "GEODE", "CANYON", "CAVERN", "DUNE", "GEOLOGY", "LAND", "LANDSCAPE", "TOPOGRAPHY", "EARTHQUAKE", "EROSION", "SEDIMENT"
}

HEALING_WORDS = {
  "HEAL", "MEND", "SOOTHE", "CURE", "RESTORE", "REMEDY", "REJUVENATE", "COMFORT", "RELIEF", "THERAPY",
  "MEDICINE", "WELLNESS", "TRANQUILITY", "SERENITY", "BALANCE", "NOURISH", "REGENERATE", "REVITALIZE", "SUPPORT", "RECOVERY", "LIFE", 
  "VITALITY", "ENERGY", "STRENGTH", "IMMUNITY", "PROTECT", "SHIELD", "BARRIER", "FORTIFY", "DEFEND", "GUARD"
}

WATER_WORDS = {
  "WAVE", "STREAM", "RAIN", "FLOOD", "DRIP", "POOL", "OCEAN", "LAKE", "RIVER", "TIDE",
  "CURRENT", "SPRAY", "MIST", "DROPLET", "RIPPLE", "WATERFALL", "BROOK", "AQUIFER", "SPRING", "DELTA", "BAY","DRINK", "SPLASH", "SOAK",
  "DRENCH", "SUBMERGE", "SWIM", "FLOAT", "DIVE", "SURGE", "CLEANSE", "REFRESH", "HYDRATE" 
}

map = Map("images/Tile", map_1)
player = Player(playerStartX, playerStartY, gfx.image.new("images/Player"))

function contains(table, element)
    for _, value in pairs(table) do
        if value == element then
            return true
        end
    end
    return false
end

function indexOf(table, element)
    for index, value in pairs(table) do
        if value == element then
            return index
        end
    end
    return 0
end

function advanceTime()
end

One thing I'm noticing is that you're supposed to leave off the .lua extension when using import. I think that's causing pdc not to bundle in the correct files.

1 Like

This worked! wow. Thank you so much!

nevermind i continued programming and it came up again

WAIT I FIGURED IT OUT! While I would work on the different scripts i would hit run on files that weren’t the main.lua file, like player.lua, i would then go into the main.lua file and change something and hit run in the main.lua file! It wasn’t the code, it was me!

1 Like