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

Help With String.match/string.find

Started by bigbaddevil6, 30 August 2013 - 08:56 PM
bigbaddevil6 #1
Posted 30 August 2013 - 10:56 PM
I am currently using the Miscperipherals chat box that they added in. I'm trying to get it where you can ask the turtle a question such as "turtle: speak" or "turtle: i would like for you to speak" or "turtle: for the last time will you speak to me". I want it so that it detects the keywords such as "turtle:" as a make shift "/" for commands and then "speak" which is an example of one of the commands that can be called. I want it so that you don't have to say it in any order but instead have the turtle look for the keywords. As far as ive gotten with previous help is this.


m = peripheral.wrap("left")
		while true do
				event, player, message = os.pullEvent("chat")
				local target, command = string.match(message, "^%s*(.+)%s*:%s*(.+)%s*$")
				print(target, command) -- debug code
				if target == "turtle" and command == "speak" then
						 m.say("HI")
		end
end

it will work if you do "turtle:speak" or "turtle: speak" but if you try to put anything else in it "turtle: will you speak" it wont run.
jay5476 #2
Posted 31 August 2013 - 12:00 AM
try
 if message:find("turtle:")  and message:find("speak") then -- code 
bigbaddevil6 #3
Posted 31 August 2013 - 02:08 AM
ahh works perfectly was easier than i thought it would be