With regards
Qwerty.
peripheral.find("modem", rednet.open)
while true do
if not rs.getInput("left") then
rednet.send(1, "")
print("Message sent...")
end
os.pullEvent("redstone")
end
it's good but I edited a little of the code since it didn't do what I hoped for, tho now it works, so thank you!Looks like you want something along these lines:peripheral.find("modem", rednet.open) while true do if not rs.getInput("left") then rednet.send(1, "") print("Message sent...") end os.pullEvent("redstone") end
If you truly want it to send one message, full stop, then stick a "break" after the "print" line.
That instructs the computer to wait until the redstone input changes again. If you didn't have that then your computer will be trying to check the redstone input several thousand times a second which, as you can imagine, is rather inefficient. As you've noticed, these loops can also cause all sorts of other problems. ComputerCraft generally will abort them if it detects them, though this doesn't always work.Can I ask you Mr.Bloke, what is the purpose of os.pullEvent() at the end of the code? I see no use for it…
Thank you for your sorta, not really usable information. tho how do I get it to send the message when the redstone gets toggled on to off because right nw I just restart the computer to achive what I want (extremeley in-efficient, I know).That instructs the computer to wait until the redstone input changes again. If you didn't have that then your computer will be trying to check the redstone input several thousand times a second which, as you can imagine, is rather inefficient. As you've noticed, these loops can also cause all sorts of other problems. ComputerCraft generally will abort them if it detects them, though this doesn't always work.Can I ask you Mr.Bloke, what is the purpose of os.pullEvent() at the end of the code? I see no use for it…
Thank you for your sorta, not really usable information.
tho how do I get it to send the message when the redstone gets toggled on to off
well since I succ at describing my troubles I meant when the redstone gets turned on or off it sends a message only once per loop basically when redstone changes send a message (I'm really sorry if I've wasted anyone's time asking these (useless and dumb) questions)
with regards
Qwerty
peripheral.find("modem", rednet.open)
local previousState
while true do
if previousState ~= rs.getInput("left") then
previousState = rs.getInput("left")
rednet.send(1, "")
print("Message sent...")
end
os.pullEvent("redstone")
end
nice program but it doesn't work could you explain why it doesn't work? I read the code and seems logic to me but it just doesn't want to work… or maybe it's because I'm playing 1.10.2 with the pre-release of 1.9.4 with unborkedwell since I succ at describing my troubles I meant when the redstone gets turned on or off it sends a message only once per loop basically when redstone changes send a message (I'm really sorry if I've wasted anyone's time asking these (useless and dumb) questions)
with regards
Qwerty
Adapting BomeBlokes code:peripheral.find("modem", rednet.open) local previousState while true do if previousState ~= rs.getInput("left") then previousState = rs.getInput("left") rednet.send(1, "") print("Message sent...") end os.pullEvent("redstone") end
nice program but it doesn't work could you explain why it doesn't work? I read the code and seems logic to me but it just doesn't want to work… or maybe it's because I'm playing 1.10.2 with the pre-release of 1.9.4 with unborked
HI, so here's the code https://pastebin.com/4hDvzCKb and I don't mean executing when the loop breaks but instead to execute it once in the loop until a condition is met like you send a message and when a condition is true i.e. the energy storage is full the rednet message gets sent again btw the "sides" API is just to open the rednet sides made by the one, the only Lyqyd! Anyways thank you for your future help.
with regards
Qwerty
local sent = false --# variable to keep track of whether or not we've sent a message
peripheral.find("modem", rednet.open)
while true do
if redstone.getInput("left") == false then
if sent == false then --# only send the message if the variable is false
sent = true
rednet.send(1,"")
print("Message sent...")
end
else
sent = false
end
os.pullEvent("redstone") --# pullEvent to make it not constantly check
end
everything except the first time it sends the message and then nothing happens.nice program but it doesn't work could you explain why it doesn't work? I read the code and seems logic to me but it just doesn't want to work… or maybe it's because I'm playing 1.10.2 with the pre-release of 1.9.4 with unborked
what does the code do? explain what is not working.
HI valithor, did you test it because when I try to run it, it gives me this error: "<program name>:7: attempt to call nil" anyways I am going to stop to waste anyone's time so feel free to not reply to this post!
What is the point in using a repeat loop? It would just end up being trading one infinite loop for another.HI, so here's the code https://pastebin.com/4hDvzCKb and I don't mean executing when the loop breaks but instead to execute it once in the loop until a condition is met like you send a message and when a condition is true i.e. the energy storage is full the rednet message gets sent again btw the "sides" API is just to open the rednet sides made by the one, the only Lyqyd! Anyways thank you for your future help.
with regards
Qwerty
From my interpretation of what you are wanting to do, it would be something more like this:local sent = false --# variable to keep track of whether or not we've sent a message peripheral.find("modem", rednet.open) while true do if redstone.getInput("left") == false then if sent == false then --# only send the message if the variable is false sent = true rs.send(1,"") print("Message sent...") end else sent = false end os.pullEvent("redstone") --# pullEvent to make it not constantly check end
For future reference… "it just doesn't want to work… " does not help us help you. Please give how it does not work. Give what it does, such as it errors, or it doesn't send a message (if it doesn't send a message is it printing that a message is sent). We can't begin to help you fix the problem if you don't tell us the problem.