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

[1.47] Chatv - Updated, Better than ever!

Started by Spongy141, 19 March 2012 - 05:11 AM
Spongy141 #1
Posted 19 March 2012 - 06:11 AM
Hello, A while ago I made Chatv not knowing how do even use rednet right, lol. But now I do, and updated it to work RIGHT!
There is a pastebin link http://pastebin.com/0XyDRMVy also, and the code also, Enjoy :)/> !


function top()
  term.clear()
  term.setCursorPos(1,1)
  term.setTextColor(colors.purple)
  print("Welcome to Chatv")
  term.setTextColor(colors.gray)
  print("====================================================")
end

function detectDevice(DeviceName)
DeviceSide="none"
for k,v in pairs(redstone.getSides()) do
if peripheral.getType(v)==DeviceName then
   DeviceSide = v
   break
end
end
  return(DeviceSide)
end

top()
ModemSide=detectDevice("modem")
rednet.open(ModemSide)
term.setTextColor(colors.green)
write("Username: ")
term.setTextColor(colors.white)
local user = read()
term.clear()
term.setCursorPos(1,1)
top()
while true do
  term.setTextColor(colors.lime)
  write("Message: ")
  term.setTextColor(colors.white)
  local a = read()
  rednet.broadcast(user.. ": " ..a)
  id, msg = rednet.receive()
  print(id.. ": is sending a message")
  print(msg)
end
Spongy141 #2
Posted 19 March 2012 - 06:12 AM
You can try the code it works but just not if you want to chat with others
Casper7526 #3
Posted 19 March 2012 - 06:31 AM
while true do

local a = read()
term.write(B)
print(a)

end
bbqroast #4
Posted 23 March 2012 - 01:31 AM
Hmmm… I think you need to open a connection first?
As in before you send messages.
http://computercraft...ednet_%28API%29
StrangeWill #5
Posted 23 March 2012 - 04:09 AM
I wanted to type more to my friend but the program ended, it needs more reads.
Luanub #6
Posted 23 March 2012 - 05:26 AM
I wanted to type more to my friend but the program ended, it needs more reads.

You shouldn't have to have more then 1 read. All you need is a while true loop like what Casper posted above, its basically an infinite loop.

while true do

local a = read()
term.write(B)
print(a)

end
hamish1001 #7
Posted 23 March 2012 - 05:35 AM
so if i use this it will let me talk to other people on my map connected to each other? and how do wireless modems work?
xXNinjaMXx #8
Posted 03 April 2012 - 01:26 AM
I found the Source of Your Problem your print the variable a which is from another computer the variable you should be printing is message

term.setCursorPos(1,1)
rednet.open("left")
while true do
id, message = rednet.receive()
print ("The Computer Number".. id .." Has Sent You A Message")
print (message)
sleep(1)
end
where the variable ID is the computer ID and the variable message is the actual message as written in the send code :)/>/> i know I've written a program Similar to this! Which will be released :D/>/>
Spongy141 #9
Posted 27 April 2012 - 10:54 PM
(To ALL) Thanks for the feed back, sorry that i couldn't get back sooner… i really haven't used this mod since 1.31 but when it first can out, and I'm very happy to c my code worked… Yes i will use what both xXNinjaMXx and Casper7526 and upgrade my code, But for now i hope to c more feed back after i finish the new code, or add on to it. I really like the fact that i got some feed back. Really Thank you!
Spongy141 #10
Posted 27 April 2012 - 11:04 PM
I found the Source of Your Problem your print the variable a which is from another computer the variable you should be printing is message

term.setCursorPos(1,1)
rednet.open("left")
while true do
id, message = rednet.receive()
print ("The Computer Number".. id .." Has Sent You A Message")
print (message)
sleep(1)
end
where the variable ID is the computer ID and the variable message is the actual message as written in the send code :)/>/> i know I've written a program Similar to this! Which will be released :)/>/>
I found the Source of Your Problem your print the variable a which is from another computer the variable you should be printing is message

term.setCursorPos(1,1)
rednet.open("left")
while true do
id, message = rednet.receive()
print ("The Computer Number".. id .." Has Sent You A Message")
print (message)
sleep(1)
end
where the variable ID is the computer ID and the variable message is the actual message as written in the send code ;)/>/> i know I've written a program Similar to this! Which will be released :)/>/>
I have to say… I really made this to allow people to chat with usernames that fact when it says

print ("The Computer Number".. id .." Has Sent You A Message") 
it doesn't let you know WHO is talking to you, but i like that idea. But really , its not good if you want to know you sent you the message, you would have to memorize peoples computer IDs which I wouldst want to do at all. But thanks for the feed back!
Spongy141 #11
Posted 28 April 2012 - 06:03 PM
:Edit to the last thing i said: Nvm that code would be more for a mail type chat, i like that idea, i might add that later when i can make an options bar or system to it.
D_Technodude #12
Posted 28 April 2012 - 06:04 PM
you would have to memorize peoples computer IDs which I wouldst want to do at all.

And thus DNS was invented. =P Maybe create a database system for the users? Heh maybe it's just me but that sounds like fun, I think I might go try that. :)/>/>
Spongy141 #13
Posted 28 April 2012 - 06:11 PM
you would have to memorize peoples computer IDs which I wouldst want to do at all.

And thus DNS was invented. =P Maybe create a database system for the users? Heh maybe it's just me but that sounds like fun, I think I might go try that. :)/>/>
that is what the username part in my code is for, if i used his code upabove then i you all would have to memorize your friends or other peoples computer id, which i really dont like, but it would be great for a private msg type of thing.
D_Technodude #14
Posted 28 April 2012 - 06:18 PM
Hmm, well, I like complicated things. If I were to do this, which I think I might, I would have it send a request to a designated "server" for the service. If the server has your computer's ID in it's DB it would return your username. If it didn't then it would have your computer prompt you for a username. Then it would map your username to your comp's ID on the server. When you send a message to a username, it requests the ID from the server. The server could also have a password for security and even an online/offline feature, but I'm getting ahead of myself. =P I, personally, am a Java guru, not Lua, so I don't really know what the limitations of the language are, but from what I've heard it's very flexible and you could do something like that.
Spongy141 #15
Posted 28 April 2012 - 06:33 PM
I could add the data base thing in a future update… but right now im working on the allow others to see the message the person sent, because it isnt working atm. what its doing is after one Computer sends the message the one that sends it freeze and won't unfreeze untill the other computer sends a message, but you cant even see the message.

also that code i posted is already old cuz i already add more stuff.
Spongy141 #16
Posted 04 December 2012 - 04:50 PM
UPDATED IT, RE DID IT! sorry for the caps.