Jump to content




Chatbox peripheral help


  • You cannot reply to this topic
3 replies to this topic

#1 AssossaGPB

  • Members
  • 126 posts
  • LocationFlorida, USA

Posted 01 July 2014 - 04: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!

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 01 July 2014 - 04: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 by theoriginalbit, 01 July 2014 - 04:25 AM.


#3 AssossaGPB

  • Members
  • 126 posts
  • LocationFlorida, USA

Posted 01 July 2014 - 01:19 PM

View Posttheoriginalbit, on 01 July 2014 - 04:24 AM, said:

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.

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 July 2014 - 02: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)






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users