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

or

Started by applesauce10189, 10 January 2014 - 10:10 PM
applesauce10189 #1
Posted 10 January 2014 - 11:10 PM
Can you use "or" in a "if" statement? ex:

rednet.open("right")
while true do
id, message = rednet.receive()
if message == "open" or rs.getInput("righ") == true then
  turtle.forward()
  turtle.turnLeft()
  turtle.dig()
  turtle.up()
  turtle.dig()
  turtle.down()
  turtle.turnRight()
  turtle.back()
  sleep(5)
  turtle.forward()
  turtle.turnLeft()
  turtle.place()
  turtle.up()
  turtle.place()
  turtle.down()
  turtle.turnRight()
  turtle.back()
end
end
theoriginalbit #2
Posted 10 January 2014 - 11:14 PM
Yes of course you can. you can use any number of combinations of and, or, and not to apply your logic. Its the main time you use boolean logic, in conditionals, whether its an if, while, or repeat.

if you're having and error it's because its rs.getInput("right") you missed the t in right.
Edited on 10 January 2014 - 10:15 PM
applesauce10189 #3
Posted 10 January 2014 - 11:24 PM
Actually shortly after making this I found/fixed that, but applying a redstone signal doesn't seem to work, I'm thinking but at the same time doubting that it might be the wireless modem on that side of the turtle,


edit: I made it or rs.getInput("back") == true then etc…
and made the redstone come from the back and it still doesn't work. I'm confused.
Edited on 10 January 2014 - 10:34 PM
Bomb Bloke #4
Posted 11 January 2014 - 12:23 AM
Avoid the phrase "doesn't work"; it's not a useful one. What does happen? What did you expect to happen? How do those two things differ?

If you're expecting a change in redstone to make it skip past the rednet.receive() call, that's not going to happen because that call specifically waits until such time as a rednet message comes in.

A simple way around that would be to pass a short timeout value to it, eg:

id, message = rednet.receive(1)
Edited on 10 January 2014 - 11:26 PM
Lyqyd #5
Posted 11 January 2014 - 12:51 AM
it might be the wireless modem on that side of the turtle,

Aside from what Bomb Bloke covered above, this is correct–a wireless modem, tool, or other peripheral on the side of the turtle means that it cannot use that side for redstone i/o.
Buho #6
Posted 11 January 2014 - 09:48 AM
Aside from what Bomb Bloke covered above, this is correct–a wireless modem, tool, or other peripheral on the side of the turtle means that it cannot use that side for redstone i/o.
I found that out a few weeks ago. Really confused me for a while :P/> Had to redesign the turtle's interface.
subzero22 #7
Posted 11 January 2014 - 09:56 AM
Just wanting to point out that you got dig twice in your code without moving forward? Is there a reason for that? Also with a redstone behind it I don't think it can move backwards.
Anavrins #8
Posted 11 January 2014 - 10:35 AM
rednet.receive won't yield if it receive a redstone signal.
Would be better replacing id, message = rednet.receive() to something like event, id, message = os.pullEvent()
Which would yield to both a rednet message and a redstone signal.
Edited on 11 January 2014 - 09:36 AM
applesauce10189 #9
Posted 11 January 2014 - 12:55 PM
Wow, lottsa replies,
Avoid the phrase "doesn't work"; it's not a useful one. What does happen? What did you expect to happen? How do those two things differ?

If you're expecting a change in redstone to make it skip past the rednet.receive() call, that's not going to happen because that call specifically waits until such time as a rednet message comes in.

A simple way around that would be to pass a short timeout value to it, eg:

id, message = rednet.receive(1)
thank you for telling me that,
it might be the wireless modem on that side of the turtle,

Aside from what Bomb Bloke covered above, this is correct–a wireless modem, tool, or other peripheral on the side of the turtle means that it cannot use that side for redstone i/o.
seriously? that's actually a thing? That was just a crazy guess because I was slowly getting frustrated with what I thought should've triggered the "if" statement.


If there's any derpy spellings I woke up under half an hour ago. That's my excuse. I need to stop making excuses. Oh well.
TheOddByte #10
Posted 11 January 2014 - 02:29 PM
I would like to add that when checking booleans you can do this

if bool then -- Checking if bool is true
	-- Code
elseif not bool then -- Checking if it's false
	-- Code
else -- If it's nil or whatever :-P
    -- Code
end
Edited on 11 January 2014 - 01:31 PM
CometWolf #11
Posted 11 January 2014 - 02:43 PM
I would like to add that when checking booleans you can do this
Incorrect, see comments.

if bool then -- Checking if bool is anything other than false or nil
	-- Code
elseif not bool then -- Checking if it's false or nil, might aswell use the else here and drop the other one.
	-- Code
else -- This will never happen
	-- Code
end
TheOddByte #12
Posted 11 January 2014 - 05:02 PM
I would like to add that when checking booleans you can do this
Incorrect, see comments.

if bool then -- Checking if bool is anything other than false or nil
	-- Code
elseif not bool then -- Checking if it's false or nil, might aswell use the else here and drop the other one.
	-- Code
else -- This will never happen
	-- Code
end
Lol, I was in a hurry when writing that.. Thanks for correcting me :)/>