Posted 18 March 2013 - 01:53 PM
Problem Solved.
My plan was to make a script using MiscPeripherals' ChatBox to refuel my turtles to a certain level via chat.
Yes. I'm that lazy…
My problem isn't catching the input or even adding commas for the sake of my OCD. My problem is I can't figure out how to newline after each set of numbers.
Example:
Chat: quarry 40000
Returns: quarry 40,000
However I want to catch multiple input on the same chat line. Thus making me even lazier.
Example:
Chat: quarry 40000 xquarry 4000 ….
should return:
quarry 40,000
xquarry 40,000
Except it doesn't. It gives me an 'attempt to index ? (a nil value)' error.
So I guess my question is how would I split the string after the numbers and interpret each one?
Here's the code:
Pastebin: http://pastebin.com/mpT4jJ7v
My plan was to make a script using MiscPeripherals' ChatBox to refuel my turtles to a certain level via chat.
Yes. I'm that lazy…
My problem isn't catching the input or even adding commas for the sake of my OCD. My problem is I can't figure out how to newline after each set of numbers.
Example:
Chat: quarry 40000
Returns: quarry 40,000
However I want to catch multiple input on the same chat line. Thus making me even lazier.
Example:
Chat: quarry 40000 xquarry 4000 ….
should return:
quarry 40,000
xquarry 40,000
Except it doesn't. It gives me an 'attempt to index ? (a nil value)' error.
So I guess my question is how would I split the string after the numbers and interpret each one?
Here's the code:
Spoiler
function comma(num)
local a,b = string.match(num, '^([^%d]*%d)(%d*)$')
return a..(b:reverse():gsub('%d%d%d', '%1,'):reverse())
end
while true do
local e, player, text = os.pullEvent("chat")
print("Player: "..tostring(player))
print("Text: "..comma(text))
end
Pastebin: http://pastebin.com/mpT4jJ7v