You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PICO-8代码第13行提示未闭合函数语法错误是什么原因?

PICO-8 语法错误修复说明

问题根源

你遇到的报错由两处嵌套的语法遗漏导致:

  • _update函数内的if btn(1) then条件判断没有对应的end闭合
  • 整个_update函数本身也缺少对应的end闭合
    你目前只写了1个end,无法同时覆盖if判断和函数的闭合需求,因此编译器会定位到_update函数定义的第13行,提示存在未闭合函数。

修正后的完整代码

local guy_x
local guy_y

    -- lua scripting language

function _init()
    -- all the code that happens
    -- when the cart is firt run
    guy_x=64
    guy_y=64
end

function _update()
    --  all the code that
    -- updates the game state
    if btn(1) then
        guy_x+=1
    end -- 闭合if判断
end -- 闭合_update函数

function _draw()
    -- all the code that
    -- drwas thing to the screen
    cls() -- clears screen!
    rect(10,20,100,60,12) -- draws a blue rectangle
    -- rect(x1,y1,x2,y2,color)
    circ(20,20,20,14) -- draws a pink circle
    pset(90,50,9) -- draws one pixel
    rectfill(85,50,90,40,9)
    circfill(guy_x,guy_y,5,9)
    --  circfill(x,y,radius,color
end

内容的提问来源于stack exchange,提问作者Yoshi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 18:24:01