19 posts
Posted 08 November 2012 - 06:35 AM
Is there a way to make a setup that every time the program gets a rednet.receive to increase a integer?
Trying to add onto a program I already made but I'm trying to get it to keep track of the number of stacks mined up.
514 posts
Location
Over there
Posted 08 November 2012 - 06:38 AM
calls = 0
while true do
id, msg = rednet.receive()
-- do something with that data
calls = calls + 1
end
Decide whether you want to increase it before or after executing code.
19 posts
Posted 08 November 2012 - 07:13 AM
Thank you, I got it all working now :P/>/>
Now my mining program works really well.
Tells the number of stacks mined up and the max amount it can mine before it has to be reset, which is the number of stacks you want to mine up * the number of turtles you have going.
2088 posts
Location
South Africa
Posted 08 November 2012 - 07:33 AM
calls = 0
while true do
id, msg = rednet.receive()
-- do something with that data
calls = calls + 1
end
Decide whether you want to increase it before or after executing code.
calls = 0
while true do
e, id, msg = os.pullEvent("rednet_message") -- this is a better option
-- do something with that data
calls = calls + 1
end
514 posts
Location
Over there
Posted 08 November 2012 - 08:46 AM
calls = 0
while true do
e, id, msg = os.pullEvent("rednet_message") -- this is a better option
-- do something with that data
calls = calls + 1
end
It is another option, but why would it be better in this case?
2217 posts
Location
3232235883
Posted 08 November 2012 - 08:49 AM
rednet.receive is the same thing as os.pullEvent("rednet_message")
Spoiler
function receive( nTimeout )
local timer = nil
local sEvent = "rednet_message"
if nTimeout then
timer = os.startTimer( nTimeout )
sEvent = nil
end
while true do
local e, p1, p2, p3 = os.pullEvent( sEvent )
if e == "rednet_message" then
return p1, p2, p3
elseif e == "timer" and p1 == timer then
return nil, nil, nil
end
end
end
the only difference is the timeout option
2088 posts
Location
South Africa
Posted 08 November 2012 - 08:56 AM
calls = 0
while true do
e, id, msg = os.pullEvent("rednet_message") -- this is a better option
-- do something with that data
calls = calls + 1
end
It is another option, but why would it be better in this case?
Nevermind, doesn't matter - wasn't thinking :P/>/>