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

Run 2 checks in a if statement?

Started by THC_Butterz, 08 December 2013 - 11:49 AM
THC_Butterz #1
Posted 08 December 2013 - 12:49 PM
how would i run multiple, 2 or more, checks in a if statement?
for example:


f = false
t1 = redstone.getBundledInput("back", 1)
t2 = redstone.getBundledInput("back", 2)
t3 = redstone.getBundledInput("back", 4)
if t2 ~= f and t3 ==f then
print("orange wire active")
end
awsmazinggenius #2
Posted 08 December 2013 - 12:52 PM
Do you mean an elseif, or more then one if statement? Please make yourself a little more clear.
electrodude512 #3
Posted 08 December 2013 - 12:57 PM
I'm not really sure if you mean an elseif or a this and that, but this does both:


t1 = redstone.getBundledInput("back", 1)
t2 = redstone.getBundledInput("back", 2)
t3 = redstone.getBundledInput("back", 4)
if t2 and not t1 and not t3 then
print("orange wire active")
elseif t1 and not t2 and not t3 then
print("white wire active")
elseif t3 and not t1 and not t2 then
print("magenta wire active")
else
print("no wire active")
end
Kingdaro #4
Posted 08 December 2013 - 01:16 PM
Yeah, that's not the right usage of getBundledInput anyway, and the solution you want is overcomplicating the issue.

rs.getBundledInput() (rs is just short for redstone) does not accept a second number, and returns the actual input. To test what that input actually is, you use colors.test().

local input = rs.getBundledInput('back')

if colors.test(input, colors.white) then
  --# white wire active
elseif colors.test(input, colors.orange) then
  --# orange wire active
elseif colors.test(input, colors.magenta) then
  --# etc.
end
Edited on 08 December 2013 - 12:16 PM