<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://wiki.herc.ws/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://wiki.herc.ws/w/index.php?action=history&amp;feed=atom&amp;title=If</id>
		<title>If - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://wiki.herc.ws/w/index.php?action=history&amp;feed=atom&amp;title=If"/>
		<link rel="alternate" type="text/html" href="https://wiki.herc.ws/w/index.php?title=If&amp;action=history"/>
		<updated>2026-05-01T07:44:31Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.21.11</generator>

	<entry>
		<id>https://wiki.herc.ws/w/index.php?title=If&amp;diff=186&amp;oldid=prev</id>
		<title>Nameless2you: Created page with &quot;Category:Script_Command ==Syntax== * if (&lt;condition&gt;) &lt;statement&gt;; * if (&lt;condition&gt;) { &lt;statements&gt; }; ==Description== This is the basic conditional statement com...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.herc.ws/w/index.php?title=If&amp;diff=186&amp;oldid=prev"/>
				<updated>2013-01-13T19:44:07Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;a href=&quot;/wiki/Category:Script_Command&quot; title=&quot;Category:Script Command&quot;&gt;Category:Script_Command&lt;/a&gt; ==Syntax== * &lt;a href=&quot;/wiki/If&quot; title=&quot;If&quot;&gt;if&lt;/a&gt; (&amp;lt;condition&amp;gt;) &amp;lt;statement&amp;gt;; * &lt;a href=&quot;/wiki/If&quot; title=&quot;If&quot;&gt;if&lt;/a&gt; (&amp;lt;condition&amp;gt;) { &amp;lt;statements&amp;gt; }; ==Description== This is the basic conditional statement com...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Script_Command]]&lt;br /&gt;
==Syntax==&lt;br /&gt;
* [[if]] (&amp;lt;condition&amp;gt;) &amp;lt;statement&amp;gt;;&lt;br /&gt;
* [[if]] (&amp;lt;condition&amp;gt;) { &amp;lt;statements&amp;gt; };&lt;br /&gt;
==Description==&lt;br /&gt;
This is the basic conditional statement command, and just about the only one &lt;br /&gt;
available in this scripting language. &lt;br /&gt;
&lt;br /&gt;
The condition can be any expression. All expressions resulting in a non-zero &lt;br /&gt;
value will be considered True, including negative values. All expressions &lt;br /&gt;
resulting in a zero are false.&lt;br /&gt;
&lt;br /&gt;
If the expression results in True, the statement will be executed. If it isn't &lt;br /&gt;
true, nothing happens and we move on to the next line of the script.&lt;br /&gt;
&lt;br /&gt;
    if (1)  mes &amp;quot;This will always print.&amp;quot;;&lt;br /&gt;
    if (0)  mes &amp;quot;And this will never print.&amp;quot;;&lt;br /&gt;
    if (5)  mes &amp;quot;This will also always print.&amp;quot;;&lt;br /&gt;
    if (-1) mes &amp;quot;Funny as it is, this will also print just fine.&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
For more information on conditional operators see the operators section above.&lt;br /&gt;
Anything that is returned by a function can be used in a condition check without &lt;br /&gt;
bothering to store it in a specific variable:&lt;br /&gt;
&lt;br /&gt;
    if (strcharinfo(0) == &amp;quot;Daniel Jackson&amp;quot;) mes &amp;quot;It is true, you are Daniel!&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
With the Advanced scripting engine, we got nested if's. That is:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if (&amp;lt;condition&amp;gt;)&lt;br /&gt;
	dothis;&lt;br /&gt;
else&lt;br /&gt;
	dothat;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If the condition doesn't meet, it'll do the action following the else.&lt;br /&gt;
We can also group several actions depending on a condition, the following way:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if (&amp;lt;condition) {&lt;br /&gt;
	dothis1;&lt;br /&gt;
	dothis2;&lt;br /&gt;
	dothis3;&lt;br /&gt;
} else {&lt;br /&gt;
	dothat1;&lt;br /&gt;
	dothat2;&lt;br /&gt;
	dothat3;&lt;br /&gt;
	dothat4;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Remember that if you plan to do several actions upon the condition being false, and &lt;br /&gt;
you forget to use the curlies (the { } ), the second action will be executed regardless&lt;br /&gt;
the output of the condition, unless of course, you stop the execution of the script if the&lt;br /&gt;
condition is true (that is, in the first grouping using a return; , and end; or a close; )&lt;br /&gt;
&lt;br /&gt;
Also, you can have multiple conditions nested or chained, and don't worry about limits as to &lt;br /&gt;
how many nested if you can have, there is no spoon ;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if (&amp;lt;condition 1&amp;gt;)&lt;br /&gt;
	dothis;&lt;br /&gt;
else if (&amp;lt;condition 2&amp;gt;){&lt;br /&gt;
	dotheother;&lt;br /&gt;
	do that;&lt;br /&gt;
	end;&lt;br /&gt;
} else&lt;br /&gt;
	do this;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Examples==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    set .@var1,1;&lt;br /&gt;
    input .@var2;&lt;br /&gt;
    if(.@var1 == .@var2)&lt;br /&gt;
       close;&lt;br /&gt;
    mes &amp;quot;Sorry that is wrong&amp;quot;;&lt;br /&gt;
    close;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    input .@var2;&lt;br /&gt;
    if(.@var2 != 1) mes &amp;quot;Sorry that is wrong&amp;quot;;&lt;br /&gt;
    close;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Notice examples 1 and 2 have the same effect.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    mes &amp;quot;[Quest Person]&amp;quot;;&lt;br /&gt;
    if(countitem(512) &amp;gt;= 1) {&lt;br /&gt;
       mes &amp;quot;Oh an apple, I didn't want it, I just wanted to see one&amp;quot;;&lt;br /&gt;
       close;&lt;br /&gt;
    }&lt;br /&gt;
    // The number 512 was found from item_db, it is the item number for the Apple.&lt;br /&gt;
    mes &amp;quot;Can you please bring me an apple?&amp;quot;;&lt;br /&gt;
    close;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    mes &amp;quot;[Multi Checker]&amp;quot;;&lt;br /&gt;
    if(queststarted == 1 &amp;amp;&amp;amp; countitem(512) &amp;gt;= 5) {&lt;br /&gt;
       // This will only be done if the quest has been started AND you have 5 apples with you&lt;br /&gt;
       mes &amp;quot;[Multi Checker]&amp;quot;;&lt;br /&gt;
       mes &amp;quot;Well done you have started the quest of got me 5 apples&amp;quot;;&lt;br /&gt;
       mes &amp;quot;Thank you&amp;quot;;&lt;br /&gt;
       set queststarted,0;&lt;br /&gt;
       delitem 512,5;&lt;br /&gt;
       close;&lt;br /&gt;
    }&lt;br /&gt;
    mes &amp;quot;Please get me 5 apples&amp;quot;;&lt;br /&gt;
    set queststarted,1;&lt;br /&gt;
    close;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    set .@var1,.@var1+1;&lt;br /&gt;
    mes &amp;quot;[Forgetful Man]&amp;quot;;&lt;br /&gt;
    if (.@var == 1) mes &amp;quot;This is the first time you have talked to me.&amp;quot;;&lt;br /&gt;
    if (.@var == 2) mes &amp;quot;This is the second time you have talked to me.&amp;quot;;&lt;br /&gt;
    if (.@var == 3) mes &amp;quot;This is the third time you have talked to me.&amp;quot;;&lt;br /&gt;
    if (.@var == 4) {&lt;br /&gt;
       mes &amp;quot;This is the forth time you have talked to me, but I think I am getting amnesia, I have forgotten about you.&amp;quot;;&lt;br /&gt;
       set .@var,0;&lt;br /&gt;
    }&lt;br /&gt;
    close;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you plan to something like this, better look at the '[[switch]]' command.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    mes &amp;quot;[Person Checker]&amp;quot;;&lt;br /&gt;
    if($name$ != null &amp;amp;&amp;amp; $name$ == strcharinfo(0)) {&lt;br /&gt;
       mes &amp;quot;[Person Checker]&amp;quot;;&lt;br /&gt;
       mes &amp;quot;You are the person that &amp;quot; +$name2$+ &amp;quot; just mentioned&amp;quot;;&lt;br /&gt;
       mes &amp;quot;nice to meet you&amp;quot;;&lt;br /&gt;
    } else if($name$ != null){&lt;br /&gt;
       mes &amp;quot;[Person Checker]&amp;quot;;&lt;br /&gt;
       mes &amp;quot;You are not the person that &amp;quot; +$name2$+ &amp;quot; mentioned&amp;quot;;&lt;br /&gt;
    } else {&lt;br /&gt;
       mes &amp;quot;Please tell me someones name&amp;quot;;&lt;br /&gt;
       next;&lt;br /&gt;
       input $name$;&lt;br /&gt;
       set $name2$,strcharinfo(0);&lt;br /&gt;
       mes &amp;quot;[Person Checker]&amp;quot;;&lt;br /&gt;
       mes &amp;quot;Thank you&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    set $name$,null;&lt;br /&gt;
    set $name2$,null;&lt;br /&gt;
    close;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See '[[strcharinfo]]' for explanation of what this function does.&lt;/div&gt;</summary>
		<author><name>Nameless2you</name></author>	</entry>

	</feed>