If/Then/Else statements; Having trouble

Posted by Kagai on Tue 17 Nov 2009 09:00 AM — 3 posts, 16,201 views.

#0
Alright, so I've really gotten into scripting, and my prefered method is using VBscript, easy, simple, I should know the language like the back of my hand. I create a trigger, with not one, but two if statements in it, as follows:


if EKill = "off" then
world.EnableTrigger "Balance", FALSE
else
	If eshield = "1" then
	world.send "raze @target"
	else if eprism = "1" then
	world.send "raze @target"
	else if ereflect = "1" then
	world.send "raze @target"
	Else
	world.send "wave"
	end if
end if


but I go to test it out, and it gives me this error:

Error number: -2146827274
Event: Execution of line 13 column 7
Description: Expected 'End'

Line in error:

end if
Called by: Immediate execution

But, with VB, and VBscript, even, it tries to tell me that it's the wrong way to end an If statement, but when I go and take out the "If" of end if, it gives me this message:

Error number: -2146827276
Event: Execution of line 12 column 5
Description: Expected 'If'

Line in error:

end
Called by: Immediate execution
Australia Forum Administrator #1
Well, I count a lot more than 2 ifs there:


if EKill = "off" then
world.EnableTrigger "Balance", FALSE
else
	if eshield = "1" then
	world.send "raze @target"
	else if eprism = "1" then
	world.send "raze @target"
	else if ereflect = "1" then
	world.send "raze @target"
	Else
	world.send "wave"
	end if
end if


You need an "end if" for each if. However, if you make it "elseif" then you don't.

eg.


if EKill = "off" then
   EnableTrigger "Balance", vbFalse
else
  if eshield = "1" then
    Send "raze @target"
  elseif eprism = "1" then
    Send "raze @target"
  elseif ereflect = "1" then
    Send "raze @target"
  Else
    Send "wave"
  end if
end if

Amended on Tue 17 Nov 2009 09:38 AM by Nick Gammon
#2
well, I've redesigned the whole thing, and realized I was just wasting my time with the first REAL if statement, and had forgotten that it was Elseif, not Else If. Thanks for the reminder.