Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua TIC-80有问题吗_Lua - Fatal编程技术网

Lua TIC-80有问题吗

Lua TIC-80有问题吗,lua,Lua,嗨!我试图做一个简单的TIC-80(基本上是lüa)脚本,但我得到了一个错误 添加LastFace()函数后开始出现错误。老实说,我知道我做错了什么 代码如下: --width and height vars w=240 h=136 -- Last faced var lf='r' --Player X and Y, W, H, ID vars p = { id=0, x=w/2, y=h/2, w=16, h=16, draw = function() spr(p.id, p.x,

嗨!我试图做一个简单的TIC-80(基本上是lüa)脚本,但我得到了一个错误

添加LastFace()函数后开始出现错误。老实说,我知道我做错了什么

代码如下:

--width and height vars
w=240
h=136

-- Last faced var
lf='r'

--Player X and Y, W, H, ID vars
p = {
id=0,
x=w/2,
y=h/2,
w=16,
h=16,
draw = function()
    spr(p.id, p.x, p.y, 1, 1)
end
}

   --movement function here


function lastfaced()
    if btn(2) then
        lf='l'
        
    elseif btn(3) then
        lf='r'

    elseif lf="l" then
        p.id=4
        
    elseif lf="r" then
        p.id=0
    end
end
    
function TIC()
    cls(12)
    
    move()
    p.draw()
    lastfaced()
    
end
下面是错误:

[string "..."]:49: 'then' expected near '='

有人能帮忙吗?

Ehm,当你想比较时,你必须使用==使其工作,一个=将不工作

function lastfaced()
    if btn(2) then
        lf='l'
        
    elseif btn(3) then
        lf='r'

    elseif lf="l" then
        p.id==4
        
    elseif lf=="r" then
        p.id=0
    end
end

哦,对了。谢谢
如果lf==“l”,那么p.id=4
此时不要使用second
elseif
,屏幕需要额外的游戏循环才能更新。