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

Elseif and == (And other McGuffins)

Started by Oggman13, 30 October 2012 - 12:48 PM
Oggman13 #1
Posted 30 October 2012 - 01:48 PM
So I'm writing up some interesting doors for a friends "Secret Base" on our Multiplayer Tekkit server, and I've slowly ran into a brick wall. I've managed to get past multiple hindrances (through googling and this lovely site) around multiple outputs and such and I'm having issues using the Elseif statement.

I've got it so this door checks the label of the disk, and if it's "Furor" it outputs below (Wire leading to the door) and to the side (A green light that turns on). What he also wants is if you put in the wrong Floppy, it outputs to an Alarm, and to a Red light ontop.

The only way I could think of wiring this up is using this (Most of it is taken from a Youtube tutorial, that I've modified for my own means).

while true do
if disk.getLabel("left") == "Furor" then
	rs.setOutput("front", true)
	rs.setOutput("bottom", true)
	disk.eject("left")
	sleep(5)
	rs.setOutput("front", false)
	rs.setOutput("bottom", false)


Now what I'm wondering, is if I use an "If" statement again, about if disk.getLabel == "Furor" is false (If this is the case, how would I write that?) or do I use an elseif in the same manner. I was using a else statement, but now I have a cycling flashing red light and alarm. My other question is, what does the "==" signify before the label?

Many thanks, Ogg
sjele #2
Posted 30 October 2012 - 01:57 PM
First of all == means equal too. ~= means unequaltoo

To acive what you want you can use an elseif or an else. I'll make to examples:


while true do
if disk.getLabel("left") == "Furor" then
	    rs.setOutput("front", true)
	    rs.setOutput("bottom", true)
	    disk.eject("left")
	    sleep(5)
	    rs.setOutput("front", false)
	    rs.setOutput("bottom", false)
elseif disk.getLabel("left") ~= "Furor" then
	    --alarm code
end --end if/elseif
end- while


while true do
if disk.getLabel("left") == "Furor" then
	    rs.setOutput("front", true)
	    rs.setOutput("bottom", true)
	    disk.eject("left")
	    sleep(5)
	    rs.setOutput("front", false)
	    rs.setOutput("bottom", false)
else --If it is anything else that the if statement:
	    --Alarm code
end--if
end--while
KaoS #3
Posted 30 October 2012 - 01:58 PM

while true do
  if disk.getLabel("left") == "Furor" then
	rs.setOutput("front", true)
	rs.setOutput("bottom", true)
	disk.eject("left")
	sleep(5)
	rs.setOutput("front", false)
	rs.setOutput("bottom", false)
  elseif disk.getLabel("left") ~= "Furor" then
	--some code here
  end
end

EDIT: ninja every time :P/>/> power died so delayed :P/>/>
Cranium #4
Posted 30 October 2012 - 01:59 PM
Good so far, so If I read you right, you want to add another condition to your if statement? Simple. You already have it in your head to use elseif, and you are also using "equates equal" in your statement. What you want is this:

while true do
if disk.getLabel("left") == "Furor" then
		rs.setOutput("front", true)
		rs.setOutput("bottom", true)
		disk.eject("left")
		sleep(5)
		rs.setOutput("front", false)
		rs.setOutput("bottom", false)
elseif not disk.getLabel("left") == "Furor" then --add the not into the statement to check if it is NOT "Furor"
		--do something here
end
end
Oggman13 #5
Posted 30 October 2012 - 03:12 PM
Thank you all! :P/>/>
The "elseif not" is going to come in real handy, so is the ~=