contents.gifindex.gifprev1.gifnext1.gif

pueblo00000000.gif TinTin #if command

This command works similarly to the ‘if’ statement in other programming languages, and is loosely based on the way C handles conditional statements.

Command syntax

#if {condition} {success command} {failure command}

The conditional statement will be evaluated. If the result is true (non-zero), then the ‘success command’ will be executed. If the result is false (zero), then the ’failure command’ will be executed.

If {failure command} is omitted, then nothing will be done if condition is false.

Examples

The following command will say ‘Wow!’ if the variable $bankaccount is greater than 10,000:

#if {$bankaccount > 10,000} {say Wow!}

The following action will automatically thank someone when they give you more than 500 coins:

#action {%0 gives you %1 gold coins} {#if {%%1 > 500} {thank %%0}}

Note: The percentage signs are doubled in the #if directive in the last example because they belong to the #action command, and not to the #if command.

The following action will watch for the number of ‘hit points’ you have on DIKU servers, and store that number to the variable ‘$points’. The associated alias will tell you whether you’re healthy or not when you type ‘stat’:

#action {^hp:%0 } {#var {points} {%%0}}

#alias {stat} {#if {$points > 50} {#showme Healthy} {#showme SICK!}}

Also see

TinTin expressions

#math