EQ2Interface

EQ2Interface (https://www.eq2interface.com/forums/index.php)
-   XML Modification Help & Info (https://www.eq2interface.com/forums/forumdisplay.php?f=22)
-   -   Operators and conditionals (https://www.eq2interface.com/forums/showthread.php?t=5406)

Erahain 01-12-2006 03:39 PM

Operators and conditionals
 
My second post about this; but this time in a new
thread =P

-

I don't know if this has already been discovered, but I'm
posting it in case of...

While doing some research, I stumbled across the ##
operator. It is used to concatenate strings. However, there
are a few syntax rules that must be followed.

Look at the example below:

Code:

<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:

Code:

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

... but this does...

Code:

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


mother9987 01-12-2006 07:39 PM

Wow, I love you man... and in the most macho possible way.

Now, if only I could remember what I wanted Concatenate for. There's been so many things and I've just found ways to work around it. But there might be a few things I could still use it for...

Edit: Here's a use for it that I could never get around... Albiet not an earth-shattering use. Mother's Mail now with mail forward button! (Might still be pending approval)

depechenode 01-12-2006 08:34 PM

Omg!!!
 
If this does what it says, I can get my grp window mod a GREAT BIG FACE LIFT!!! THANK YOU!!!!!!!

Erahain 01-13-2006 06:13 AM

Well I'm sure a lot of people will find it usefull =)

SOE_Bobble 01-14-2006 02:36 AM

Nicely done.

I have access to the code and didn't even know this existed. So I went into the UIScriptEngine code tonight but didn't find any other secrets treasures.

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


Did anyone ever figure out the syntax for the conditional operator? If not, the spacing rules and () syntax of ## might be a clue.

Bobble

Erahain 01-14-2006 07:26 AM

The comparison operators works as they should, but there are a few rules
to this as well.

<=, >=, < 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 formated 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 ofcourse up to the modder =)

Also remember, no ( ) blocks, or comparisons, at the left side of the &&
or || operators. *UPDATED*

(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!

Now to the 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.

Code:

COND ? yes : no COND = (1 == 1)
------------
A side note:

The UI scripting engine interprets the text from top to bottom, and from
right to left; examples below:

COND is set first, then LocalText:
Code:

COND=1
LocalText=COND

Same here, COND is set.. then LocalText:
Code:

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...

Code:

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.

Code:

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.

-

If you have any more questions, please ask =)

Daniel

Landiin 01-14-2006 12:59 PM

Dude you rock.. I tried a couple of time to get the conditional to work but gave up, I never once thought to put the condition into a variable

Deathbane27 01-14-2006 04:10 PM

I hereby dub thee... SIR Erahain, Knight of the Script Functions, Duke of the Operators, and my successor. :p

Erahain 01-14-2006 04:22 PM

Thank yee ;)

Dolby 01-14-2006 04:27 PM

Great find Erahain! I cant wait to see what interface authors make with this.

Stickied this thread to the top. :)

Zonx 02-25-2006 04:30 PM

1 minor correction on comparisons...

Text is not converted to 0 if both sides of the comparison are text. I've been using text comparisons against sub-class name to derive Market window menu selections for a while now.

Some of this stuff was experimented with and dicussed in this thread ;)

I suspect the cat opperator was added shortly after that discussion and passed on to us in the semi-recent UIBuilder update. I did discuss this with one of Bobble's colleges around that time.

Erahain 07-21-2006 12:34 PM

Are you sure you are not only talking about the == and != operators
now? They are purely for string comparison if i remember correctly.
I.e. its never converted to numbers.

The operators I suggested converted string to numbers were
>= <= > and <.

This was explained in an earlier post.

It might even be possibe that a string is converted to strlen(string);
thus the length of the string in numbers.

Maybe we should try making a length comparison:
COND1 = 'helloo' > 5
... should in theory return true.

I've not been playing with this for a while. :p
But I'm gonna do that now.

Othesus 04-21-2007 12:42 AM

Has anyone really gotten a conditional to work or have any actual working examples? I've been trying to use one and it never does anything.

COND ? case1

gives me case1 regardless of what COND is.

COND ? case1 : case2

gives me case2 regardless of what COND is.

gm9 04-21-2007 07:07 AM

Conditionals are great, same as the operators - they allow you to do at least some minimal processing in the code. I use them in several windows. See below for a combination of conditionals and concactenation from my automatic per-character mail signature function:

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


If you want to see heavy use of conditionals, take a look at Mother's timer window, that one is a beast, possibly the most impressive (or excessive? :D) example of what you can do with the XML operators that I have seen on here (although Talyns
has excellent examples as well, search for his kills before level up XP window on the forums, for example).

Not sure what may be wrong with your code, maybe the condition isn't set up correctly. :confused:

Othesus 04-21-2007 07:15 AM

Thanks, I actually ended up having to backtrack a few hours and use a different approach. The primary browser object has to be at the first level of the browser window for the homepage or /browser <URL> to work. I was trying to leave that primary browser object there as a dummy and then copy the URI text into different tabs but I ran into a time delay problem anyway so I went back to an earlier design idea.

Landiin 04-22-2007 06:33 PM

Quote:

Originally Posted by Othesus (Post 58306)
Has anyone really gotten a conditional to work or have any actual working examples? I've been trying to use one and it never does anything.

COND ? case1

gives me case1 regardless of what COND is.

COND ? case1 : case2

gives me case2 regardless of what COND is.

Works

COND=1>2
Visible=(COND?True:False)

Visible=(COND?True:False) COND=1>2

(remember EQ2 exec it's script right to left, top to bottom)

Does not work

Visible=(1>2?True:False)

Here is a snip of the code I use to show class icons in the group window
Code:

<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>


Syndic 04-27-2007 01:40 PM

OK sometimes things like this fly right over my head.

I recently returned to EQ2. I found that the /Gamedata.Self.LevelClass has been changed to include the word "Level" at the beginning of it. Now it doesn't fit in the areas I have for it. After finding this thread I thought there might be hope in creating a single text which concats Level + Class together to get the old result again (ie "55 Shadowknight" instead of "Level 55 Shadowknight"), just the examples above seem to concentrate more on conditions than concatenation.

I just can't figure out how or if it is possible to use 2 Gamadatas in one field. I know I could go along and create 2 Texts but the spacing would out. I also tried looking at several UI's to see if anyone has done this but have yet to stumble across it.

gm9 04-27-2007 02:38 PM

You cannot assign two Gamedatas, assign each to a different invisble text field like charlvl and charclass, then have a third text field that you want to display and populate it via an OnShow event like this: Text=charlvl.LocalText ## charclass.LocalText

Talyns 04-27-2007 03:46 PM

Quote:

Originally Posted by gm9 (Post 58550)
You cannot assign two Gamedatas, assign each to a different invisble text field like charlvl and charclass, then have a third text field that you want to display and populate it via an OnShow event like this: Text=charlvl.LocalText ## charclass.LocalText

you would probably want a space in there too so

Text=charlvl.LocalText ## (' ') ## charclass.LocalText

Syndic 04-27-2007 10:23 PM

Thanks I'll give that a shot.

Syndic 04-29-2007 09:47 AM

OK there is certainly something I'm missing here.

The 3 texts I've listed below, I only seem to be getting the words "Not working" to appear. Anyone able to spot the stupid mistake I'm making?

This is inside the player window btw.
Code:

<Text Visible="False" DynamicData="/GameData.Self.Level" Font="/Fonts.FontZapf15" LocalText="70" Margin="0,0,5,0" Name="advLevel" ScrollExtent="120,15" ShadowStyle="/ShadowStyles.Outline1" Size="120,15" TextAlignment="Right" TextAlignmentVertical="Center" TextColor="#F0D090">70</Text>
<Text Visible="False" DynamicData="/GameData.Self.SubClass" Font="/Fonts.FontZapf15" LocalText="Shadowknight" Margin="0,0,5,0" Name="advClass" ScrollExtent="120,15" ShadowStyle="/ShadowStyles.Outline1" Size="120,15" TextAlignment="Right" TextAlignmentVertical="Center" TextColor="#F0D090">Shadowknight</Text>
<Text AbsorbsInput="false" Font="/Fonts.FontZapf15" LocalText="50 Shadowknight"  OnShow="Text=advLevel.LocalText ## (' ') ## advClass.LocalText" Margin="0,0,5,0" Name="advLevelClass" ScrollExtent="130,15" ShadowStyle="/ShadowStyles.Outline1" Size="130,15" TextAlignment="Right" TextAlignmentVertical="Center" TextColor="#F0D090">Not working</Text>


Othesus 04-29-2007 08:35 PM

I didn't test it but try this:

OnShow="Text=advLevel.LocalText ## (' ') ## advClass.LocalText"

change to

OnShow="Text=Parent.advLevel.LocalText ## (' ') ## Parent.advClass.LocalText"

Syndic 04-30-2007 07:19 AM

Yep did that Othesus, didn't seem to make any difference.

If anyone knows of a mod that actually does this, I could even go there and see what I did wrong.

gm9 04-30-2007 07:43 AM

If it does show your "Not working" all the time that means that your OnShow event is not getting triggered. Try putting your code in the topmost <page> of your window, or if you never hide that window, put it in another window that receives OnShow events. Of course you can also just change it to a OnHoverIn= event or something like that.

Othesus 04-30-2007 09:28 AM

Are you testing the script in the UIBuilder? You can trigger any OnShow script by clicking the eyeball.

Othesus 05-26-2007 12:06 AM

Just a note about the syntax for the ! (negation) operator. It has to be enclosed in single quotes, like:

Parent.ShineyTestButton.Activated='!'Parent.Info.Visible

Genen 11-23-2008 11:42 AM

Can I run counters?

Example:

I have a label displayed on a window. Let's call it 'TotalLabel'

If TotalLabel.Localtext is '0', then I will see a '0' on the window.

How do I increment that by 1?

Does "Parent.TotalLabel.Localtext=Parent.TotalLabel.Localtext + 1" work?

Any existing windows out there I can look at for examples?

gm9 11-23-2008 12:38 PM

Yes. Also see here.

samejima 01-08-2009 06:54 AM

HOW IN GODS NAME DO YOU GET A WORKING AND OR STATEMENT :( I give up! :confused::confused::confused::confused::(:(:(:(

gm9 01-08-2009 07:02 AM

As far as I found you can only ever do one operation at the same time, so you can't do any kind of nested statements including two comparisons. At least I gave up trying as well. So you need to do two separate comparisons.

samejima 01-08-2009 07:06 AM

Quote:

Originally Posted by SOE_Bobble (Post 39464)
Nicely done.

I have access to the code and didn't even know this existed. So I went into the UIScriptEngine code tonight but didn't find any other secrets treasures.

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


Did anyone ever figure out the syntax for the conditional operator? If not, the spacing rules and () syntax of ## might be a clue.

Bobble

So that doesn't exist or just not working properly? I just want to do if x= y || z

gm9 01-08-2009 07:21 AM

Oh no that works fine. Example:
y=(a == 10)
z=(a == 5)
COND=y || z
x=COND ? true : false
Will be true for values of a = 5 or 10 and false for anything else.

samejima 01-08-2009 07:25 AM

OK I was trying to do stuff like

Cond= a==10 || a==5

with that being said would this be a valid statment


y=(a == 10)
z=(a == 5)
x=(COND ? true : false) COND=y || z

And this?
x=(COND ? true : false) COND=y || z y=(a == 10) z=(a == 5)

trying to keep it all on one line for a change instead of pressing return 1000x

gm9 01-08-2009 07:35 AM

Quote:

Originally Posted by samejima (Post 79549)
OK I was trying to do stuff like

Cond= a==10 || a==5

That's basically what I tried to express above (and what should be mentioned earlier in this thread), you can't combine different operations (here == and ||), the parser doesn't pick it up correctly, you need to put them in separate statements that you reference via variables. You can combine similar operations though, so COND = a || b || c || d works.

Quote:

Originally Posted by samejima (Post 79549)
with that being said would this be a valid statment


y=(a == 10)
z=(a == 5)
x=(COND ? true : false) COND=y || z

And this?
x=(COND ? true : false) COND=y || z y=(a == 10) z=(a == 5)

trying to keep it all on one line for a change instead of pressing return 1000x

I find it easier to read with linebreaks but both ways work, it's purely cosmetic. :)

samejima 01-08-2009 07:37 AM

All my code is normally done with line breaks but for this I just want to keep it on one line, plus I was just curious after trying for so long!!! thanks for the help.

Regn 04-30-2019 10:03 AM

I hope it's ok that I add code examples that I've made work. If you know something I don't in terms of having to be careful with /GameData.General.Time let me know.

Concatenation

Code purpose:
To concatenate the AA Experience string with square brackets, allowing e.g. AA Experience to be displayed in square brackets next to AA Points like so: "173 [43.5%]".

Code example:
Code:

<?xml version="1.0" encoding="utf-8"?>

<Page Name="Main">
 
  <Text Name="AAXPValue" DynamicData="/GameData.Achievement.ExperienceCurrent" />
  <Text Name="Init" DynamicData="/GameData.General.Time" DynamicDataFilter="FFFE" OnTextChanged="Parent.DisplayArea.AAXPDisplay.Text=('[') ## Parent.AAXPValue.LocalText ## (']')" />
 
  <Page Name="DisplayArea">
    <Text Name="AAXPDisplay" LocalText="N/A" />
  </Page>
 
</Page>

Code output:
Code:

[100%]
Code explanation:
  • AAXPValue contains the DynamicData string that we want to concat.
  • Init is an idea that I've borrowed from one of Drums xml files, and edited for a simpler purpose.
  • Init uses the DynamicData called GameData.General.Time for the sole purposes of triggering OnTextChanged, which then makes our desired change to AAXPDisplay.

Code note:
  • You will have to add the required Page and Text properties to Main, DisplayArea, and AAXPDisplay. I removed these properties for the purpose of keeping the code easy to read and understand.
  • Don't swap out the square brackets with parenthesis. Your EQ2 client will crash if you try to run it with parenthesis.
  • AA Points were not added in the code example to avoid confusion.

Drumstix42 05-05-2019 07:31 PM

Pretty interesting that concatenating parenthesis in a string causes the game to crash, LOL. There might be a work around using like an ascii/unicode version of parenthesis instead, but not sure :)


All times are GMT -5. The time now is 01:19 PM.

vBulletin® - Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
© MMOUI