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

IRC style program

Started by kylergs, 28 April 2012 - 01:41 PM
kylergs #1
Posted 28 April 2012 - 03:41 PM
This is an IRC style chat program using the rednet.
I welcome any ideas for improvements/ constructive criticism.


tower = 28 --The id of the broadcasting tower that you want to use
rednetside = "top" -- the side that the router is on.


term.clear()
term.setCursorPos(1,1)
print("Kylergs's IRC Program")
count = 2
line = 2
rednet.open(rednetside)
input = ""
x,y=term.getSize()
my = y-3
while true do
event, id, mess = os.pullEventRaw()
if event == "rednet_message" and id==tower then
  if count > my then
	term.scroll(1)
  else
	line = line+1
  end
  term.setCursorPos(1, line)
  write(id.." :"..mess)
  count = count+1
elseif event =="char" then
  term.setCursorPos(1, y)
  input = input..id
  write(input)
elseif event=="key" and id ==28 then
  rednet.send(tower,input)
  term.setCursorPos(1,y)
  term.clearLine()
  input=""
end
end

And also the broadcasting tower code that I use:

rednet.open("top")
while true do
event,id,msg= os.pullEvent("rednet_message")
rednet.broadcast(msg)
print(id.." : "..msg)
sleep(0.1) -- This is to get rid of feedback loops that I was getting between towers.
end
Spongy141 #2
Posted 28 April 2012 - 06:59 PM
This isnt a chat system… like you send it broadcasts, also i read your code, it doesn't allow you to write inside the program what you want to say, this just looks like a bunch of random code. if you want to add a part so you can really allow you to broadcast a REAL message, the do this some were

local {what ever you want to call it} = read()
rednet.broadcast({what ever you called it above})
while true do
local {what ever you want to call it} = read()
rednet.broadcast({what ever you called it above})
This will allow you to write what you want to say INSIDE the program, but make sure the other rednet stuff is working, also will add a loop to it so u don't have to add more reads
Leo Verto #3
Posted 28 April 2012 - 08:44 PM
You can write inside the program, but it doesn't send it to the server.
I wrote a similar IRC system without a server, but at that point I didn't know about term.scroll() :)/>/>
CypherAJ #4
Posted 30 April 2012 - 10:24 AM
1. add event for Backspace so you can edit your message at least by rewriting.
2. get tower send (id..": "..msg) and client print only (mess) so you can see who sent message. i already did it to my version
or make client to send it's name (written on program start) and tower only to broadcast it
CypherAJ #5
Posted 30 April 2012 - 09:10 PM
i did some changes to your program and don't see any copyright or "ask me for blahblahblah" notes at OP so i'll just post it here.

Changes:
1. Added possibility to use Backspace to edit your message without sending.
2. Programs now says ID of sender, not tower's one.
3. Tower now logs every message in irc.log file
4. Added commands (currently only ~clear). To use command type it like ordinary message. Note: It will not be sent to tower. (Actually now this just reloads program but if that will matter with future versions i'll remake it

Client:
http://pastebin.com/ukJ4d3Bx

Tower:
http://pastebin.com/DRCwxzuq