尝试索引本地变量(一个数字值)

对不起这是一个愚蠢的问题,但我是新手

在运行这段代码时,我会收到错误消息:尝试索引本地变量(一个数字值)

以下是代码的一部分!

function simple_haunt_ai(mon,m) --构造函数
    if m.typ=="walker" then
        for m in all(mon) do
            if m.y>97 then m.y-=m.spd*2
            else
                if pl.x>m.x then m.x+=m.spd;m.f=false end
                if pl.x<m.x then m.x-=m.spd;m.f=true end
            end
        end
    elseif m.typ=="jumper" then
        for m in all(mon) do
            if m.y>97 then m.y-=m.spd*4
            else
                if pl.x<m.x then
                    if m.grav then
                        m.ang=0.4
                        m.x-=m.spd*3
                        m.y+=sin(m.ang)+m.spd
                        if m.y<92 then m.grav=false end
                    elseif not m.grav then
                        m.y-=sin(m.ang)+m.spd
                        if m.y>97 then m.grav=true end
                    end
                end
                if pl.x>m.x then
                    if m.grav then
                        m.ang=0.1
                        m.x+=m.spd*3
                        m.y+=sin(m.ang)+m.spd
                        if (m.y<92) m.grav=false
                    elseif not m.grav then
                        m.y-=sin(m.ang)+m.spd
                        if (m.y>97) m.grav=true
                    end
                end
            end
        end
    end
end

调用

simple_haunt_ai(slimes,s)

slimes - 所有对象史莱姆的表

slimes={}

s - 参数

s={x=rnd(124),y=104,ang=0,f=0,
spd=0.25,t=0,sprt=16,atk=1,type="walker",
hp=1,box={x1=1,y1=5,x2=6,y2=7}}
点赞