尝试调用方法“查找”(nil值)

时间:2019-11-04 09:48:49

标签: lua

试图在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("found VIP!")
            if train.passenger then
                dropPassenger(train)
            end
            return p
        end
    end
    return passengers[1]
end

1 个答案:

答案 0 :(得分:0)

https://github.com/Germanunkol/trAInsported/blob/e0ed49e73ffd447ba1024c8f08bcc0fb24bf3cdb/Scripts/ai.lua#L390

那里的代码表明train.passenger是一个表,而不是字符串。

由于表train.passenger没有实现功能find,因此无法调用它。

几行之后,您致电p.name:find("Show me the money!"),这对我来说没有太大意义。为什么乘客的名字包含“告诉我钱!”?

passenger.name是一个字符串。也许您打算在上面做同样的事情。