Jump to content




or


  • You cannot reply to this topic
11 replies to this topic

#1 applesauce10189

  • Members
  • 162 posts

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


#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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 by theoriginalbit, 10 January 2014 - 11:15 PM.


#3 applesauce10189

  • Members
  • 162 posts

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 by applesauce10189, 10 January 2014 - 11:34 PM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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 by Bomb Bloke, 11 January 2014 - 12:26 AM.


#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 11 January 2014 - 12:51 AM

View Postapplesauce10189, on 10 January 2014 - 11:24 PM, said:

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.

#6 Buho

  • Members
  • 110 posts

Posted 11 January 2014 - 09:48 AM

View PostLyqyd, on 11 January 2014 - 12:51 AM, said:

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.

#7 subzero22

  • Members
  • 97 posts

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.

#8 Anavrins

  • Members
  • 775 posts

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 by Anavrins, 11 January 2014 - 10:36 AM.


#9 applesauce10189

  • Members
  • 162 posts

Posted 11 January 2014 - 12:55 PM

Wow, lottsa replies,

View PostBomb Bloke, on 11 January 2014 - 12:23 AM, said:

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,

View PostLyqyd, on 11 January 2014 - 12:51 AM, said:

View Postapplesauce10189, on 10 January 2014 - 11:24 PM, said:

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.

#10 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

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 by Hellkid98, 11 January 2014 - 02:31 PM.


#11 CometWolf

  • Members
  • 1,283 posts

Posted 11 January 2014 - 02:43 PM

View PostHellkid98, on 11 January 2014 - 02:29 PM, said:

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


#12 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 11 January 2014 - 05:02 PM

View PostCometWolf, on 11 January 2014 - 02:43 PM, said:

View PostHellkid98, on 11 January 2014 - 02:29 PM, said:

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 :)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users