2016-08-09 77 views
0
local meshId = message:sub(message, message:find(message, "/hat%s%d"), message:find(message, "/hat %d+")) 

message:find()返回两个值;在第一字符和最后字符。我将如何让它只返回最后一个字符忽略返回值

回答

0

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

function returntwo() return "first", "second" end 
print(select(2, returntwo())) -- prints "second" 

在有问题的情况下,你会用它作为local meshId = message:sub(message, select(2, message:find(message, "/hat%s%d")), select(2, message:find(message, "/hat %d+")))

+1

非最终位置@Oka功能被调整为单一的返回值。 (在括号中包含函数调用等也会这样做。)因此,在OP调用中:':find'调用不能返回多个值,因此使用'select'将按预期工作。 –

+0

非常感谢您的帮助,但我将如何将其专门应用于此?我是卢阿的新手,对不起。 – onlineone22

0

简单地说,我认为解决方案。只是第二prameter返回

​​

包裹消息:发现功能,并返回第二个值

怎么样?

+0

是否这样?本地的a,b =消息:发现(”“) \t \t \t \t本地meshId =消息:子(6,B - 1) \t \t本地textureId =消息:子(B + 1,消息:LEN() ) – onlineone22

+0

我不知道消息对象是什么,是string类吗?,lua默认的字符串函数是一样的吗? – gogothing