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

[SOLVED]Me being derp

Started by Engineer, 22 January 2013 - 07:49 AM
Engineer #1
Posted 22 January 2013 - 08:49 AM
Hello, I got this two pieces of code running and it denies to send rednet OR receive rednet. Of course I turned on both modems and checked ID's. I also tried using the rednet command in between print to see what it it outputs. This is true.


Program 1:wireless turtle:


rednet.close("right")
rednet.open("right")

local sorts = {"iron ingot", "copper ingot", "tin ingot", "gold ingot"}
local turtle = 0
local numb = 0

sendID = 3
sender = tonumber(sendID)

term.clear()
term.setCursorPos(1,1)
print("Main Turtle 1.0")

print("Receiving..")
local p1, p2, p3 = rednet.receive()
local input = p2
print(input)
local p1, p2, p3 = rednet.receive()
local inputNumb = p2
print(inputNumb)

for i = 1, tonumber(#sorts) do
sleep(.1)
if input == sorts[i] then
print("Item found!")
print("Sending..")
print(rednet.send(sender, "true"))
numb = numb - numb + i
break
elseif i > #sorts then
print("Item not found!")
rednet.send(sender, "false")
sleep(10)
os.reboot()
end
end

print("Comparing..")
if numb > 0 and numb < 17 then
turtle = 5
--elseif numb > 16 and numb < 33 then
end

rednet.send(tonumber(turtle), tostring(input))
rednet.send(tonumber(turtle), tostring(inputNumb))

This program should reboot at the end but I removed that for debugging.

program 2:computer:monitorOnTop:


local m = peripheral.wrap("top")
local sendID = 7
local sender = tonumber(sendID)
local input = "-"
local inputNumb = "-"
local param2 = "-"
local p2 = "-"
function mon()
m.clear()
m.setCursorPos(1,1)
m.setTextScale(1.5)
m.write("Item: "..input)
m.setCursorPos(1,2)
m.write("Aantal: "..tostring(inputNumb))
m.setCursorPos(1,5)
m.write("In storage: "..param2)
m.setCursorPos(1,6)
m.write("Status: "..p2)
end

for k, v in pairs(rs.getSides()) do
  rednet.close(v)
  rednet.open(v)
end

mon()

term.clear()
term.setCursorPos(1,1)

print("Exact item name: ")
input = string.lower(read())
mon()
rednet.send(sender, tostring(input))

while true do
term.setCursorPos(1,5)
term.clearLine()
term.setCursorPos(1,4)
term.clearLine()
print("Max items per send: 1024")
write("Amount: ")
inputNumb = read()
if tonumber(inputNumb) ~= nil then
if tonumber(inputNumb) < 1025 then
mon()
rednet.send(sender, tostring(inputNumb))
break
end
end
end

term.setCursorPos(1,7)
print("Status: ")

param1, param2, param3 = rednet.receive()
if param2 == "false" then
p2 = param2
mon()
term.setCursorPos(1, 9)
print("Your item is not in storage.")
print("Press any key to continue..")
term.setCursorPos(1,7)
print("Status: Not in storage room")
local px = os.pullEvent("key")
if px ~= 1 then
os.reboot()
end
elseif param == "true" then
term.setCursorPos(1,7)
print("Status: In storage room")
mon()
end

for i = 1, 4 do
p1, p2, p3 = rednet.receive()
term.setCursorPos(1,7)
term.clearLine()
print("Status: "..p2)
mon()
end
sleep(2)
os.reboot()

EDIT: Sorry, the prints are in dutch. It is changed to english now.

Should I go to bug reports with this?

I went to the IRC and came to the conclusion that the fault is not at the mod but at my bad coding :(/>

Can someone find out what the actual problem is?

The problem + fix:


param1, param2, param3 = rednet.receive()
if param2 == "false" then
p2 = param2
mon()
term.setCursorPos(1, 9)
print("Your item is not in storage.")
print("Press any key to continue..")
term.setCursorPos(1,7)
print("Status: Not in storage room")
local px = os.pullEvent("key")
if px ~= 1 then
os.reboot()
end
[b]elseif param == "true" then[/b]
term.setCursorPos(1,7)
print("Status: In storage room")
mon()
end


param1, param2, param3 = rednet.receive()
if param2 == "false" then
p2 = param2
mon()
term.setCursorPos(1, 9)
print("Your item is not in storage.")
print("Press any key to continue..")
term.setCursorPos(1,7)
print("Status: Not in storage room")
local px = os.pullEvent("key")
if px ~= 1 then
os.reboot()
end
[b]elseif param2 == "true" then[/b]
term.setCursorPos(1,7)
print("Status: In storage room")
mon()
end

I derp a lot..
I apoligse for the trouble I caused in the IRC, I take back everything I said. (I was claiming a bug….)
Sorry for all the trouble I caused, I punched myself already
:P/>


Thanks, Engineer
Edited by
ChunLing #2
Posted 22 January 2013 - 08:59 AM
What exactly is happening, and exactly what do you think should happen?
Engineer #3
Posted 22 January 2013 - 09:03 AM
What exactly is happening, and exactly what do you think should happen?
Sometimes the first program doesnt even receive rednet, or it is not sended. I think it's somewhere in the 1st program in the first send. My debug pointed out that doesnt work for some odd reason. Or on the other computer it isnt being received. I am cleuless
ChunLing #4
Posted 22 January 2013 - 01:27 PM
"Sometimes", is it? I think that you need to look at whether there are factors that are interfering with rednet communication. For instance, there is no protection on your rednet.receives() to make sure that stray messages/spam aren't activating the program with incorrect values. If an invalid message is received, then there will be unexpected behavior.

But you really need to describe exactly what is happening. The exact output and behavior when things are working how you want, and at least one example of exactly what happens differently on occasions when it doesn't work as you expect.