忽略返回值

local meshId = message:sub(message, message:find(message, "/hat%s%d"), message:find(message, "/hat %d+"))

message:find() 返回两个值;第一个字符和最后一个字符。我该如何使其仅返回 最后一个字符

点赞
用户1442917
用户1442917

如果一个函数返回多个参数,你可以使用 select(2, functioncall()) 来获取第二个参数。例如:

function returntwo() return "first", "second" end
print(select(2, returntwo())) -- 打印出 "second"

在这种情况下,你需要这样使用它 local meshId = message:sub(message, select(2, message:find(message, "/hat%s%d")), select(2, message:find(message, "/hat %d+")))

2016-08-09 01:52:05
用户4988149
用户4988149
简单地说,我的解决方案是只返回第二个参数。
function returnTwo(...)
    -- 通过使用"..."作为不定参数可以将所有参数传递给message:find函数
    local a, b = message:find(...)
    return b
end

我将message:find函数进行了包装,只返回它的第二个值。

这个怎么样?

2016-08-09 06:13:44