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

rednet increase int

Started by dorky106, 08 November 2012 - 05:35 AM
dorky106 #1
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.
Leo Verto #2
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.
dorky106 #3
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.
remiX #4
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
Leo Verto #5
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?
PixelToast #6
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
remiX #7
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/>/>