FANDOM


This tutorial covers some basics of Rednet like how to send and receive messages.

For this tutorial you need 2 computers with a Wireless Modem for each of them. Place the modems at the back.

Now, we'll jump straight into coding one of the computers.

--Simpler chat client by Tyab
--This one actually WORKS and has USER HANDLES
--I feel sad you cannot SAVE YOUR HANDLE, tho.

function clear()
 term.clear()
 term.setCursorPos(1,1)
end

rednet.open("back")
username = "Chum"
local chatBuddy = nil

function help()
 print("Welcome to Pesterchum 1.0")
 print("Press C to Connect")
 print("Press H to set your Handle")
 print("Press A to Abscond to menu")
 print("Press T to Type")
end

clear()
help()

while true do
 event, id, msg = os.pullEvent()

 if event == "rednet_message" and id == chatBuddy then
  print(msg)

 elseif event == "char" then

  if id == "t" then
   write(username.." > ")
   msgsent = read()
   if chatBuddy ~= nil then
    rednet.send(chatBuddy,username.." > "..msgsent)
   else
    print("Quit talking to yourself, dumbass!")
    --always punish users for doing stuff wrong
   end

  elseif id == "h" then
   write("New username: ")
   username = read()

  elseif id == "c" then
   write("Chum ID: ") --put your chum's computer ID here
   chatBuddy = tonumber(read())
   clear()
   print("Conncted. You may chat if your chum")
   print("is connected to you right now")

  elseif id == "a" then
   chatBuddy = nil
   clear()
   help()

  end

 end

end

And there we have it, just remember to put the program at BOTH computers. Happy chatting!

This is on pastebin for easier typing. Simply type this code into the interface when starting up the ComputerCraft computer (Not in the code window!)

pastebin get QBExpj3N PrivateChat

And then run the program PrivateChat. (If this doesn't work, either enter the code manually into the code window or go to %appdata%/.technic/config/mod_ComputerCraft.cfg and change enableAPI_http=0 to  enableAPI_http=1

Start a Discussion Discussions about Tutorial/Simple Chat System

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.