This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ExtendLord's profile picture

[solved]read() args

Started by ExtendLord, 14 September 2015 - 11:02 AM
ExtendLord #1
Posted 14 September 2015 - 01:02 PM
Already Solved please lock this thread
Edited on 14 September 2015 - 11:36 AM
KingofGamesYami #2
Posted 14 September 2015 - 01:28 PM
read returns a string. There are string manipulation functions, such as string.match. To split into words, do this:


local words = {}

for word in read():gmatch( "%S+" ) do
  words[ #words + 1 ] = word
end

if words[ 1 ] == "/pm" then
  --#words[ 2 ] is the user, words[ 3 ] and higher are parts of the message
end
ExtendLord #3
Posted 14 September 2015 - 01:34 PM
read returns a string. There are string manipulation functions, such as string.match. To split into words, do this:


local words = {}

for word in read():gmatch( "%S+" ) do
  words[ #words + 1 ] = word
end

if words[ 1 ] == "/pm" then
  --#words[ 2 ] is the user, words[ 3 ] and higher are parts of the message
end
thank you it works. :)/>
Lyqyd #4
Posted 14 September 2015 - 03:22 PM
Please do not destroy your question when it has been answered. That prevents people who are doing the right thing and using the search feature from being able to find and learn from your question and the answer to it.
TheOddByte #5
Posted 14 September 2015 - 04:43 PM
Please do not destroy your question when it has been answered. That prevents people who are doing the right thing and using the search feature from being able to find and learn from your question and the answer to it.
Maybe you should add that to this: http://www.computercraft.info/forums2/index.php?/topic/14531-read-this-post-before-asking-questions/ because this is something I've seen multiple times now, and this is the reason people ask the same question over and over again.