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

Chatbox MiscPeripherals

Started by jarifle, 11 May 2015 - 05:20 PM
jarifle #1
Posted 11 May 2015 - 07:20 PM
Hello me again,

I've writen 2 programs that are made for the chatbox and teh speaker but i have 2 issues.

The miner program does not actually understand what number the message is for example:"if my message is "5" it would not stop at 5 but keep going."
2 but thats a small thing the name of the computer doesn't go in chat.

This is the core program


os.loadAPI("cleverbot")
bot = cleverbot.Cleverbot.new()
a = peripheral.wrap("speaker_0")
b = peripheral.wrap("chatBox_0")
range = 10000
lang = "en"
while true do
rs.setOutput("back", true)
event, player, message = os.pullEvent("chat")
if player == "jarifle" then
  if message == "door" then
   b.say("The door is open master.", range, true, "GladOs")
   a.speak("The door is open master.", range, lang)
   sleep(0.5)
   rs.setOutput("back", false)
   sleep(2)
   rs.setOutput("back", true)
  elseif message == "miner" then
    b.say("Miner program is booting.", range, true, "GladOs")
    a.speak("Miner program is booting.", range, lang)
sleep(3)
    shell.run("miner")
  elseif message ~= nil then
	 response = bot:send(message)
	  if response ~= nil then
	   b.say(response, range, true, "GladOs")
	   a.speak(response, range, lang)
    end
end
elseif message == "bitch" then
  b.say("Fack you!", range, true, "GladOs")
  a.speak("Fack you!", range, lang)
elseif message == "BITCH" then
  b.say("Fack you!", range, true, "GladOs")
  a.speak("Fack you!", range, lang)
else
  b.say("You are not my master!", range, true, "GladOs")
  a.speak("You are not my master", range, lang)
end
end

And this is the subprogram for the miner


a = peripheral.wrap("speaker_0")
b = peripheral.wrap("chatBox_0")
b.say("How far do you want to mine?", range, true, "GladOs")
a.speak("How far do you want to mine?", range, lang)
i = 0
while true do
  event, player, message = os.pullEvent("chat")
    if player == "jarifle" then
   m = message
	   if m then
		 repeat
	    print(m)
		  print(i)
		  rs.setOutput("right", true)
		  sleep(0.5)
		  rs.setOutput("right", false)
		  sleep(3)
		  rs.setOutput("left", true)
		  sleep(10)
		  rs.setOutput("left", false)
		  i = i + 1
		 until i == m
	 os.reboot()
    end
  end
end

Thank you!
KingofGamesYami #2
Posted 11 May 2015 - 07:25 PM
You may have to use

m = tonumber( message )

Because the chatbox returns a string.

Example:

print( "5" == 5 )
jarifle #3
Posted 11 May 2015 - 07:41 PM
Ah i see wil try that.
Any idea on the nickname thing?
KingofGamesYami #4
Posted 11 May 2015 - 09:02 PM
I have no idea about the nickname thing, is the chatbox supposed to do that?

The computer can find it's own name through os.getComputerLabel.
jarifle #5
Posted 13 May 2015 - 02:19 PM
It is if you look at etho's video's you can see the computer (chatbox) has a name when it speaks.
SquidDev #6
Posted 13 May 2015 - 02:34 PM
Etho, from what I remember, uses Peripherals++ instead of MoarPeripherals. Functionally they are pretty similar so I wouldn't worry.

However, reading through the MoarPeripherals code it looks like there is a setLabel function which allows you to set a nickname.

Edit: If you do mean Peripherals++, the last argument (fourth for say and fifth for tell) allows you to set a name. (Ughhr, why are there so many *Peripherals mods?).
Edited on 13 May 2015 - 12:37 PM
jarifle #7
Posted 13 May 2015 - 03:44 PM
SquidDev thanks for the reply.

But i also use peripheral++ and i have a fourth argument as you can see in the code but is just gives the computers coords.


b.say("How far do you want to mine?", range, true, "GladOs")
Edited on 13 May 2015 - 01:45 PM
SquidDev #8
Posted 13 May 2015 - 04:47 PM
There should be a config item called logCoords in the chatbox section. If you set this to false you will be able to use custom names.
Edited on 13 May 2015 - 02:48 PM
jarifle #9
Posted 13 May 2015 - 06:26 PM
Ooooooooh it all makes sense now.

Thanks alot everyone.