尝试调用方法'find'(空值)

尝试在trAInsportedgame中调用方法'find'(空值)

function ai.foundPassengers(train, passengers)
    if train.passenger and train.passenger:find("Show me the money!") then return nil end

    for k, p in pairs(passengers) do
        print(p)
        if p.name:find("Show me the money!") then
            print("找到VIP!")
            if train.passenger then
                dropPassenger(train)
            end
            return p
        end
    end
    return passengers[1]
end
点赞
用户2858170
用户2858170

这段代码表明 train.passenger 是一个表格,而不是一个字符串。

由于你的表格 train.passenger 没有实现一个叫做 find 的函数,所以你不能调用它。

几行代码后,你调用了 p.name:find("Show me the money!"),对我来说这没有太多意义。为什么乘客的名字会包含“Show me the money!”?

passenger.name 是一个字符串。也许你以上意图相同。

2019-11-04 10:27:07