Difference between revisions of "ScriptIf"

From Amulets & Armor Wiki
Jump to: navigation, search
(Created page with "'''If( [Result], [ScriptNum])''' Checks the result of the last Compare statement and jumps to the specified script number if the results match. This is used...")
 
 
Line 50: Line 50:
 
End()
 
End()
 
</nowiki>
 
</nowiki>
 +
 +
 +
----
 +
Back to [[Scripting]] Main Page

Latest revision as of 21:29, 17 October 2016

If( [Result], [ScriptNum])

Checks the result of the last Compare statement and jumps to the specified script number if the results match. This is used like conditional goto statements in assembly languages. The code will stop executing from the current script and move to the new script without returning.

One trick is to use an empty script function, normally #99, to end execution. In the Code Example below, the If statement jumps to an empty block if the switch has already been activated. This prevents further uses of the same switch.

Possible Result comparisons are:

  • Equal
  • NotEqual
  • LessThan
  • NotLessThan
  • GreaterThan
  • NotGreaterThan
  • LessThanOrEqual
  • GreaterThanOrEqual

Arguments

Result - Result comparison to check if true

ScriptNum - Script number to jump into.

Code Example

defnum	NOT_COMPLETE	0
defnum	COMPLETE		1

// Variables are defined with defvar and you have 1..255 of them
defvar	ExitSwitch		1
defvar	Block1			2

Initialize:
0: // Script run when the level is loaded
	Set(ExitSwitch, NOT_COMPLETE);
	Unblock(Block1);
	End()

40:  // raise exit floor with switch
	Compare(ExitSwitch, COMPLETE);
	If (Equal, 99); 
	Block(Block1);   
	ChangeSideTexture(1373,"SWIT1U");
	AreaSound(6007,-2943,-12,300,255);
	SlideFloorNice(114, -400, -64, 100, -1);
	Set(ExitSwitch, COMPLETE);
	Unblock(Block1);
	End()

99: //Escape function
	End()



Back to Scripting Main Page