Jump to content

Basic else/if script question


Malavok

Recommended Posts

Conserning correct placement of else/if in a script (I'm a noob), I'd like to know if this is the correct way to place if and else (I'm thinking that the second subscript should be something more, or that it should be placed within the "else" tag)?:

 

If

[subscript1]

If

[subscript2]

Else

[subscript3]

Endif

Endif

Link to comment
Share on other sites

Two conditions and an else:

 

if

[subscript1]

elseif

[subscript2]

Else

[subscript3]

Endif

 

You can list as many elseifs as you want, and you only need one endif. If you nest the ifs you'll need a corresponding number of endifs

 

if

[subscript1]

else

if

[subscript2]

else

[subscript3]

endif

endif

Link to comment
Share on other sites

If(subscript) 
If(subscript)

EndIf
ElseIf(subscript)

EndIf
;----------------------------------
;You can do stuff like this too
;-----------------------------------
If(subscript && subscript) || (subscript && subscript)

If(subscript || (subscript && subscript))
EndIf
EndIf

 

Make sure you indent your Code. Add comments if you write alot. It's easy to get lost in code in the GECK.

Link to comment
Share on other sites

Please use proper indenting. It helps understanding code.

 

Proper forms should be this:

 

If (Condition)
[Stuff]
EndIf

 

this:

If (Condition)
[Stuff]
Else
[Stuff2]
EndIf

 

This:

If (Condition)
[Stuff]
ElseIf (Condition2)
[Stuff2]
EndIf

 

And This:

If (Condition)
[Stuff]
ElseIf (Condition2)
[Stuff2]
Else
[Stuff3]
EndIf

 

Which can be expanded indefinitely like this:

 

If (Condition)
[Stuff]
ElseIf (Condition2)
[Stuff2]
ElseIf (Condition3)
[Stuff3]
ElseIf (Condition4)
[Stuff4]
ElseIf (Condition5)
[Stuff5]
ElseIf (Condition6)
[Stuff6]
ElseIf (Condition7)
[Stuff7]
ElseIf (Condition8)
[Stuff8]
ElseIf (Condition9)
[Stuff9]
Else
[Stuff10]
EndIf

 

 

Nesting is also valid:

 

If (Condition1)
[Stuff]
If (Condition2)
	[Other Stuff]
Else
	[More Stuff]
	If (Condition3)
	Else
		 [Even More Stuff]
	EndIf
EndIf
EndIf

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...