26 posts
Posted 23 July 2014 - 04:22 PM
A program I made to chat between computers using rednet. It's simple and has a few chat commands. Anyone got ideas on how to improve it?
v1.0.0
Pastebin Linkpastebin get sUrkhM4r sirchat
v1.1.0
Pastebin Linkpastebin get NpgWPC0U sirchat
Changes*Only receives messages from SirChat users.
*Automatically checks for modem, no need for user input.
v1.1.2
Pastebin Linkpastebin get KsmuNbuT sirchat
Changes*Fixed glitch when someone sends a message after the receiver typed /info,
*Using /connect now does not clear the entire screen.
*Screen automatically clears after it reaches =>18 line down. (This is a work around for getting /connect to work like it does now, I'll work on fixing it later so the screen will hopefully scroll!)
v1.2.0
(Latest)Pastebin Linkpastebin get JE9PXjjy sirchat
Changes*Now utilizes monitors! (Use a minimal of 3x1 row of monitors next to the computer for decent results.)
Images:
Spoiler
Edited on 05 August 2014 - 01:36 PM
515 posts
Location
Australia
Posted 23 July 2014 - 04:29 PM
Using just plain receive and broadcast isn't such a great idea on servers where other programs could be communicating with each other using broadcast too. I would suggest using protocols instead. See:
http://computercraft...tle=Rednet_(API)More specifically:
rednet.receive([ [string protocolFilter])
rednet.broadcast(string message, [string protocol])
Good luck on your coding projects!
Edited on 23 July 2014 - 02:30 PM
26 posts
Posted 28 July 2014 - 05:41 PM
Alright, so I tried to add protocols to my program, but I kept getting an error. Can someone help? Look at the send() and receive() functions.
Spoiler
--SirChat v1.1.0 -Created by Sir.Mongoose
local ex = false
local ID = os.getComputerID()
local cl = false
local line = 3
function receive()
local senderID, message, protocol = rednet.receive("sirchat")
term.clearLine()
term.setCursorPos(1,line)
print("<ID#"..senderID.."> "..(tostring(message)))
line = line + 1
end
function send()
term.write("<ID#"..ID.."> ")
local mesg = read()
if mesg == "/exit" then
ex = true
term.clear()
term.setCursorPos(1,1)
elseif mesg == "/commands" then
print("> '/exit' terminates the program.")
print("> '/clear' clears chat completely.")
print("> '/connect' connects you to a different ID.")
print("> '/info' Tells you about SirChat.")
line = line + 5
elseif mesg == "/clear" then
cl = true
elseif mesg == "/connect" then
connect()
elseif mesg == "/info" then
print("> SirChat was a program made by Sir.Mongoose.")
print("> SirChat is currently in version 1.1.")
elseif mesg ~= "/exit" or "/commands" or "/clear" or "/connect" or "/info" then
rednet.send((tonumber(targetID)), (tostring(mesg)), "sirchat")
line = line + 1
end
end
function chat()
term.clear()
term.setCursorPos(1,1)
print("**Connected with ComputerID#"..(tostring(targetID)).."**")
print("**Type '/commands' for the list of commands**")
while ex == false do
parallel.waitForAny(receive, send)
if cl == true then
term.clear()
term.setCursorPos(1,1)
print("**Connected with ComputerID#"..(tostring(targetID)).."**")
print("**Type '/commands' for the list of commands**")
line = 3
cl = false
end
end
end
function numCheck(a)
if ((tonumber(a)) == nil) == true then
return false
else
return true
end
end
function connect()
term.clear()
term.setCursorPos(1,1)
print("**Enter the ComputerID you want to connect to**")
targetID = read()
if numCheck(targetID) == true then
chat()
else
while numCheck(targetID) == false do
term.setCursorPos(1,2)
term.clearLine()
targetID = read()
end
chat()
end
end
function connectModem()
term.clear()
term.setCursorPos(1,1)
if peripheral.isPresent("back") and peripheral.getType("back") == "modem" then
rednet.open("back")
connect()
elseif peripheral.isPresent("front") and peripheral.getType("front") == "modem" then
rednet.open("front")
connect()
elseif peripheral.isPresent("left") and peripheral.getType("left") == "modem" then
rednet.open("left")
connect()
elseif peripheral.isPresent("right") and peripheral.getType("right") == "modem" then
rednet.open("right")
connect()
elseif peripheral.isPresent("top") and peripheral.getType("top") == "modem" then
rednet.open("top")
connect()
elseif peripheral.isPresent("bottom") and peripheral.getType("bottom") == "modem" then
rednet.open("bottom")
connect()
else
print("**No modem connected, please place one on an available side and press enter**")
read()
connectModem()
end
end
connectModem()
Edited on 28 July 2014 - 03:50 PM
252 posts
Location
The Netherlands
Posted 28 July 2014 - 06:21 PM
Alright, so I tried to add protocols to my program, but I kept getting an error. Can someone help? Look at the send() and receive() functions.
-code snip-
Where are you getting errors? What errors are you getting? You can't expect people to go scan through the code to find out what's wrong.
26 posts
Posted 28 July 2014 - 06:24 PM
Alright, so I tried to add protocols to my program, but I kept getting an error. Can someone help? Look at the send() and receive() functions.
-code snip-
Where are you getting errors? What errors are you getting? You can't expect people to go scan through the code to find out what's wrong.
If you ran the program in CC, you would notice the error "parallel:22: rednet:68: Expected Number". This error occurs when I add the protocol strings to rednet.send() and rednet.receive(). Sorry for the inconvenience.
Edited on 29 July 2014 - 12:28 AM
453 posts
Location
Holland
Posted 28 July 2014 - 11:11 PM
we do really need a deeper stack trace in CC -_-/>
26 posts
Posted 29 July 2014 - 04:18 PM
Fixed it, and now is updated to v1.1.2.
Edited on 31 July 2014 - 05:53 PM
1114 posts
Location
UK
Posted 29 July 2014 - 07:35 PM
we do really need a deeper stack trace in CC -_-/>
I second this notion. :lol:/>
26 posts
Posted 04 August 2014 - 06:39 PM
Alright, v1.2.0 out now! Now utilizes monitors! :)/>
598 posts
Location
The United States
Posted 04 August 2014 - 08:43 PM
You can use the "Full Editor" button to change your post title to the latest version, because right now it still says "v1.0.0"
26 posts
Posted 04 August 2014 - 09:06 PM
You can use the "Full Editor" button to change your post title to the latest version, because right now it still says "v1.0.0"
Thanks!
1326 posts
Location
Error 404: Could not find.
Posted 05 August 2014 - 12:05 AM
I can actually help you with the screen to scroll rather than clear it.
Click
Here to view the code.
If that was helpful, please let me know, if not I'll see if I can help with your scroll part in a different way.
Edited on 04 August 2014 - 10:25 PM
26 posts
Posted 05 August 2014 - 01:07 AM
I can actually help you with the screen to scroll rather than clear it.
Click
Here to view the code.
If that was helpful, please let me know, if not I'll see if I can help with your scroll part in a different way.
Seems to be crashing minecraft for me… Might need help with using it.
A"logo/menu/msg function" ?
Edited on 04 August 2014 - 11:12 PM
1326 posts
Location
Error 404: Could not find.
Posted 05 August 2014 - 01:29 AM
I can actually help you with the screen to scroll rather than clear it.
Click
Here to view the code.
If that was helpful, please let me know, if not I'll see if I can help with your scroll part in a different way.
Seems to be crashing minecraft for me… Might need help with using it.
A"logo/menu/msg function" ?
The Logo/Menu/Msg Function would be your function you use to make your title.
Example:
function drawMenu()
term.setCursorPos(1,1)
term.write( "Porky the Pig" )
end
Plus what error are you getting?
BTW: newLine(line) the line part is how many lines you want to scroll down. Leave it blank and it will be 1
Edited on 04 August 2014 - 11:32 PM
1326 posts
Location
Error 404: Could not find.
Posted 05 August 2014 - 01:37 AM
Found my own error, my bad. move the "yp = 4" outside the function.
26 posts
Posted 05 August 2014 - 02:07 AM
Found my own error, my bad. move the "yp = 4" outside the function.
Alright, I'm starting to get it to work! Thanks for the help, it is really appreciated! I'll be sure to give you a little credit for the function. :)/>
Only one problem, once it reaches the end of the screen and begins to scroll, there is a gap between the desired stopping point and where scrolling begins. Anyway to fix this? Or is this on my part?Never mind, just had to add "term.setCursorPos(1,yp - 1)" under "if yp >= 19 then" before term.scroll(x).
Edited on 05 August 2014 - 12:13 AM
1326 posts
Location
Error 404: Could not find.
Posted 05 August 2014 - 02:11 AM
What did you set the scroll number to in term.scroll() of that function?
If it is set higher than 1 then that is what happens
Nvm. Seems you figured it out.
[Edit] Your Welcome, If you need anymore help. Let me know and I'll see what I can do.
Edited on 05 August 2014 - 12:24 AM