Nikolay_888 Posted July 29, 2015 Share Posted July 29, 2015 Hello. I know, functions in Lua can take variable number of arguments by (...) So I try this: function testSumm (thePlayer, command, ...) local s = 0 for i, n in pairs(arg) do s = s + n end outputChatBox (s, thePlayer) end addCommandHandler("summ", testSumm) But this functions works not well. For example, command "/summ 1 2 3" output into the chat 9, not 6. Where is mistake? Thank you Link to comment
GTX Posted July 29, 2015 Share Posted July 29, 2015 Try this. function testSumm (thePlayer, command, ...) local s = 0 local t = {...} for i, n in ipairs(t) do s = s + n end outputChatBox (s, thePlayer) end addCommandHandler("summ", testSumm) Link to comment
Nikolay_888 Posted July 29, 2015 Author Share Posted July 29, 2015 GTX, it works, thank you very much Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now