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

Chatbox peripheral help

Started by AssossaGPB, 01 July 2014 - 03:16 AM
AssossaGPB #1
Posted 01 July 2014 - 05:16 AM
I am trying to have the computer read from chat, replace all '@' with '.' (because I can't type . in chat), then execute the command. When I tell it a command it throws the error:
string:1:attempt to index ? (a nil value)
Here is the code:

chat = peripheral.wrap("left")

local cmd = nil

while true do
  event, side, player, mes = os.pullEvent("chat_message")
  print(player.." said: "..mes)
  if mes:sub(0,9) == "Chatbox, " then
	cmd = mes:sub(10,-1)
	cmd = string.gsub(cmd,"[@]",".")
	local command = loadstring(cmd)()
  end
end

Please help! Thanks!
theoriginalbit #2
Posted 01 July 2014 - 05:24 AM
did you retype the program here on the forums? if so confirm you've spelt peripheral in the peripheral.wrap call correctly in your program.
Edited on 01 July 2014 - 03:25 AM
AssossaGPB #3
Posted 01 July 2014 - 02:19 PM
did you retype the program here on the forums? if so confirm you've spelt peripheral in the peripheral.wrap call correctly in your program.
No, I uploaded the program to pastebin and copy/pasted it over to the forums.
Bomb Bloke #4
Posted 01 July 2014 - 03:40 PM
It's not complaining about the first line of this script, but rather something's going awry in "string". It'll be triggered by either the attempt to pull substrings, or the gsub.

If you want the first nine characters of mes, you'd use:

mes:sub(1,9)

If you want the tenth character onwards, you'd use:

mes:sub(10)