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

Run a function 2 times

Started by logsys, 06 August 2013 - 04:02 PM
logsys #1
Posted 06 August 2013 - 06:02 PM
I'm trying to make a program check for a rednet message and once it receives, it rechecks the second time and go to a different function.

function receive()
id, message = rednet.receive()
if message == 1 then
  if line1 then
   line1 = false
  else
   line1 = true
  end
elseif message == 2 then
  if line2 then
   line2 = false
  else
   line2 = true
  end
elseif message == "da" then
  if da then
   da = false
  else
   da = true
  end
elseif message == "ds" then
  if ds then
   ds = false
  else
   ds = true
  end
elseif message == "as" then
  if as then
   as = false
  else
   as = true
  end
end
I have this code, but to be easier, I would like to run 2 times to give the first number and the second variable, like: First transmission: 1; Second transmission: as
Is this possible to make?
Also, sorry by my bad english :rolleyes:/>
Kingdaro #2
Posted 06 August 2013 - 06:55 PM
Alright, first thing's first, the first two "if"s will never run because "message" can never actually be a number. Try this instead:
if message == "1" then
...
if message == "2" then

As for your question, you can reverse a boolean by simply saying "var = not var". So for your example, you could shorten this:

  if line1 then
   line1 = false
  else
   line1 = true
  end

To this:

  line1 = not line1

And that's most of what you're going to be able to do here.