Operators and conditionals

From EQ2Interface Wiki

Jump to: navigation, search

Contents

Operators

= - assignment
== != - comparison
< <= - less than
> >= - greater than
&& || - AND OR
! - negative
+ - * / - math
## - concat
?: - conditional
$ - assignment. calls "/<lhs> <rhs>"

Explained

  • <=, >=, < and >
The values on either side will be converted to numbers (temporary during the comparison). If any of the values cannot be converted (i.e. a text or a poorly formatted number) it will become 0.
  • Example ('a' < 1) is true as 'a' is equal to 0.
Please note that == and != is purely string conversations; this means that 0 == 00 is false, 'a' == 0 is false and 1 == 1 is true. Good programming practice is to enclose the comparison operators in 's, as this is a requirement in order to use <= and >=. I.e.: a '<=' 1 The above rules that applies for ## is applied here as well. Another good one is that && and || should have their left and right sides contained within blocks. But that's of course up to the modder =) Also remember, no ( ) blocks, or comparisons, at the left side of the && or || operators.
  • (1 == 1) && (2 == 2)
IS NOT VALID A note about XML: Since the &-character is special in XML, doing '&&' will probably just hang your client. Instead, replace '&&' with '&amp;&amp;' This should do the trick!
  • Conditional operators '?' and ':';
Each side on both of the operators must contain real values (or variables), no special characters, operators or blocks.
  • (1 == 1) ? yes : no
The above example will not work, as left side of ? contains a block. So how do we compare? Simple workaround.
COND ? yes : no COND = (1 == 1)

Examples

Concatenate Strings

There are a few syntax rules that must be followed.

<Button LocalText="Happy" A="Very" B="Happy"
OnPress="LocalText=A ## ' ' ## B"/>

Keep in mind; always space between the property/value and the ##, unless you put it in a block (...).

This does not work:

<Button LocalText="Happy" A="Very" B="Happy"
OnPress="LocalText=A##' '##B"/>

... but this does:

<Button LocalText="Happy" A="Very" B="Happy"
OnPress="LocalText=(A)##(' ')##(B)"/>


Scripting Eengine info

The UI scripting engine interprets the text from top to bottom, and from right to left.

COND is set first, then LocalText:

COND=1
LocalText=COND

Same here, COND is set.. then LocalText:

LocalText=COND COND=1

Assign (1 == 1) to COND, and use COND as the condition for ? :

And if we want to have some more complicated things to do, we'll have to put them outside of the condition segment...

COND = MyGender == male
BROTHER = 'Welcome brother ' ## MyName 
SISTER = 'Welcome sister ' ## MyName
LocalText = COND ? BROTHER : SISTER

Please note this:

If the condition is TRUE - no further text can be appended to the resulting value, but this doesn't prevent processing through.

LocalText = (X ? 'Cool' : 'Very' ) ## ' funny'

The above is a good example of this; if X is TRUE, LocalText will be set to 'Cool' .. ignoring the text after the ( ? : ) block.

If X is FALSE, LocalText becomes 'Very' and ' funny' is appended to the string.

Automatic per-character mail signature function

A combination of conditionals and concatenation:

SignatureLocation=&apos;Parent.&apos; ## Parent.Selfname.LocalText ## &apos;.Signature&apos;
Parent.RetrieveSignature.OnPress=&apos;Parent.AddSignature.SignatureText=&apos; ## (SignatureLocation)
Parent.RetrieveSignature.Press=True
COND=SignatureText == SignatureLocation
Parent.Parent.Body.Text=Parent.Parent.Body.LocalText ## COND ? Parent.Default.Signature : SignatureText

Show class icons in the group window

<Button eX_Test="false" LocalText="eXtremeClass" Name="ClassControler" OnActivate="
Parent.Paladin.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Paladin)
Parent.Shadowknight.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Shadowknight)
Parent.Berserker.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Berserker)
Parent.Guardian.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Guardian)
Parent.Bruiser.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Bruiser)
Parent.Monk.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Monk)
Parent.Swashbuckler.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Swashbuckler)
Parent.Brigand.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Brigand)
Parent.Dirge.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Dirge)
Parent.Troubador.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Troubador)
Parent.Ranger.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Ranger)
Parent.Assassin.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Assassin)
Parent.Wizard.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Wizard)
Parent.Warlock.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Warlock)
Parent.Illusionist.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Illusionist)
Parent.Coercer.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Coercer)
Parent.Necromancer.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Necromancer)
Parent.Conjuror.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Conjuror)
Parent.Templar.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Templar)
Parent.Inquisitor.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Inquisitor)
Parent.Warden.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Warden)
Parent.Fury.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Fury)
Parent.Mystic.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Mystic)
Parent.Defiler.Visible=(eX_Test ? True : False) eX_Test=(Parent.Class.LocalText==Defiler)
Activated=False">eXtremeClass</Button>
Credit: Many Authors
Personal tools