34 posts
Posted 08 February 2014 - 05:35 AM
Well i created a code and what it is supposed to do or what i want it to do is.
when it receives a message from 722 then it sends a message to me.
when it receives a message from me then it send a message back to my friend
heres my code the program doesnt give any errors at all.
-- SR.OS Public Server Settings
local Stefan = 722
local Ramon = 627
local restart = "Startup"
-- Waiting For Message --
while true do
id,msg = rednet.receive()
msg = msg .. "."
-- When message Receive check if message is From stefan --
if id == Stefan then
rednet.send(Ramon, msg)
shell.run(restart)
elseif id == Ramon then
rednet.send(Stefan, msg)
shell.run(restart)
else
rednet.send(id, "Access denied Ask Owner For Access")
shell.run(restart)
end
end
1281 posts
Posted 08 February 2014 - 07:18 AM
Your computer Ids probably aren't 722 or 627.
34 posts
Posted 08 February 2014 - 08:08 AM
Your computer Ids probably aren't 722 or 627.
the id`s are correct and when i terminate it i need to terminate it twice
7083 posts
Location
Tasmania (AU)
Posted 08 February 2014 - 08:16 AM
Assuming the IDs were incorrect, he'd still expect to see "access denied" messages appear.
But since there's no use of
rednet.open(), the script likely won't do much at all. It'll sit there waiting for messages it cannot receive.
Assuming this script is called "Startup", the "shell.run(restart)" lines are completely redundant (the "while" loop handles all required repetition).
34 posts
Posted 08 February 2014 - 08:32 AM
Assuming the IDs were incorrect, he'd still expect to see "access denied" messages appear.
But since there's no use of
rednet.open(), the script likely won't do much at all. It'll sit there waiting for messages it cannot receive.
Assuming this script is called "Startup", the "shell.run(restart)" lines are completely redundant (the "while" loop handles all required repetition).
well there is an rednet connection cuz when i broadcast then i get Access denied so that means that my id is not 729 or so but my id is correct and i still dont know whats wrong ??
7083 posts
Location
Tasmania (AU)
Posted 08 February 2014 - 08:39 AM
In that case, you're either using another script to open a rednet side, or you've opened one and never closed it (in the latter case, the next time your computer restarts you'll run into more problems, so bear it in mind).
This script otherwise appears to do exactly what you want it to. I recommend posting the associated scripts you're running on your other computers.
34 posts
Posted 08 February 2014 - 09:17 AM
In that case, you're either using another script to open a rednet side, or you've opened one and never closed it (in the latter case, the next time your computer restarts you'll run into more problems, so bear it in mind).
This script otherwise appears to do exactly what you want it to. I recommend posting the associated scripts you're running on your other computers.
well this is what i do with the other computers:
Lua > rednet.send(broadcasterid, "Hello")
195 posts
Location
Cambridgeshire, England
Posted 08 February 2014 - 09:24 AM
You do need to do rednet.open("side"), also calling shell.run("startup") is *very* bad practise. This is known as recursion, all you will do with that is allocate more and more resources to the lua VM and slow the entire system down eventually leading to crash (hopefully garbage collection will kick in first but it handles recursion terribly with reason). Use a loop instead.
Edited on 08 February 2014 - 08:28 AM
34 posts
Posted 08 February 2014 - 10:02 AM
Well guys thank you for your help and telling me some stuff i didnt know i finaly fixed the problem i dont know what is was but heres the code that works.
-- Settings stuff
local input = ""
local modem = "back"
local server = 1
local Ramon = 2
local Stefan = 0
local mon = peripheral.wrap("left")
function send()
rednet.open("back")
print("Enter Message You want to Send:")
local input = read()
rednet.send(server, input)
input = ""
term.clear()
shell.run("send")
end
function listen()
while true do
rednet.open("back")
id,msg = rednet.receive()
if id == server then
mon.print("Stefan: "..msg)
send()
else
rednet.send(id, "Your not allowed to talk over this chat!")
end
end
end
parallel.waitForAll(listen, send)
Edited on 08 February 2014 - 09:05 AM