EQ2Interface

EQ2Interface (https://www.eq2interface.com/forums/index.php)
-   XML Modification Help & Info (https://www.eq2interface.com/forums/forumdisplay.php?f=22)
-   -   Working IF statements! (https://www.eq2interface.com/forums/showthread.php?t=2480)

Deathbane27 04-08-2005 04:35 PM

Working IF statements!
 
1 Attachment(s)
I need to go to work in a few minutes. I leave it to you to do something cool while I'm away.

<Button A="10" B="20" OnPress="Parent.Bool.Visible=(A)<(B)" ...
<Page OnShow="(script)" OnHide="(script)"


Yup, that's how you do IF statements. You set an event-triggering Boolean (aka true/false) property to the true/false value of the statement, and put a script in the object's corresponding event.

Supported operators:

==
<
>



Not supported directly:

!= (Replace with Parent.Bool.Visible=(!(A)==(B))
<= (Replace with Parent.Bool.Visible=(!(A)>(B))
>= (Replace with Parent.Bool.Visible=(!(A)<(B))

(I may be using more parenthesis than I actually need.)

One step closer to world domination!


Attached demonstration Persona window that doesn't do anything useful. And you can see that I stumbled on this while attempting to combine text strings. :p

taco-man 04-08-2005 04:59 PM

omg this is so awesome!!!! sorry i cant help myself

Drumstix42 04-08-2005 05:40 PM

You'll have to explain a bit more with the example, since me finding it on my own would probably take a bit :rolleyes: Good find nonetheless if it can be used.

hirebrand 04-08-2005 05:42 PM

So

<Button
A="/GameData.Self.Power"
B="50"
OnPress="Emoter.Bool.Visible=(A)>(B)" }

<Page
Name="Emoter"
OnShow="laugh"
OnHide="cry" }

is the equivalent of

IF GameData.Self.Power > 50
THEN laugh
ELSE cry

?

hirebrand 04-08-2005 06:09 PM

Guess not. Trying a different way

Zonx 04-08-2005 06:19 PM

That should prove usefull :D

Hehe, personally I'd use a button with Activated as the switch.

Hierbrand, other than the flubbed bracket at the end, that should work unless gamedata.self.power returns a string it can't compair to a number.

Drumstix42 04-08-2005 10:10 PM

Hmmm... now to figure out && and || ! :o

ger 04-08-2005 10:21 PM

Quote:

Originally Posted by Drumstix42
Hmmm... now to figure out && and || ! :o

Keep in mind that

IF ((A == true) && (B == true)) { DoThis }

is the same as

IF (A == TRUE) { IF (B == true) { DoThis }}

and

IF ((A == true) || (B == true)) { DoThat }

is the same as

IF (A == true) { DoThat }
IF (B == true) { DoThat }

So while it isn't as efficient, we don't need to figure out how to use && and ||.

Edit: while the above would work for IF-THENs, IF-THEN-ELSEs get a bit more complicated. Examples:

For &&:

IF (A == true) { IF (B == true) { DoThis; DoneThis = true }}
IF !(DoneThis == true) { DoTheOther }

For ||:

IF (A == true) { DoThat; DoneThat = true }
IF (B == true) { DoThat; DoneThat = true }
IF !(DoneThat == true) { DoTheOtherOther }

Why do you need the exra flag/test for IF-THEN-ELSEs? The simple answer is that you can't tie it the ELSE to either of the individual IFs or they'll end up triggering when they shouldn't (one IF is false, the other isn't) or they won't trigger when they should (the wrong IF is false.) An example:

IF (A == true) { IF (B == true) { DoThis } ELSE { DoTheOther }}

will only trigger DoTheOther whe B isn't true, not when A isn't true as you'd want an && to.

IF (A == true) { IF (B == true) { DoThis }} ELSE { DoTheOther }

will only trigger DoTheOther when A isn't true, not when B isn't true as you'd want an && to.

IF (A == true) { DoThat } ELSE { DoTheOtherOther }
IF (B == true) { DoThat } ELSE { DoTheOtherOther }

will trigger DoTheOtherOther when either A or B aren't true, when we want it to trigger only if both A and B aren't true.

An alternate to flagging for &&:

IF (A == true) { IF (B == true) { DoThis } ELSE { DoTheOther}} ELSE { DoTheOther }

still not as efficient as a && would be, but it, too, will work.

(Please note that all of this is pseudo-code and would need to be massaged into several different chained objects to be used in an actual UI XML.)

ger 04-08-2005 11:09 PM

Just had a scary thought. It may be possible to create working WHILE loops using this technique. For instance:

<Button Name="Start" OnPress="Parent.Loop.Looping=true Parent.Loop.Press=true"></Button>
<Button Name="Stop" OnPress="Parent.Loop.Looping=false"></Button>
<Button Looping="false" Name="Loop" OnPress="DoStuff Press=Looping" Visible="false"></Button>

FOR loops would work in a similar fashion, except it'd be something like:

<Button Name="Start" OnPress="Parent.Loop.Looping=true Parent.Loop.Press=true"></Button>
<Button Looping="false" Name="Loop" OnPress="DoStuff Looping=(TestArgument < TestCondition) Press=Looping" Visible="false"></Button>

Oh, the implications of it all!

Quib 04-08-2005 11:11 PM

If we can get while loops working, and if they cause no slowdown during an infinite loop, they could be used to cause active operations occur with the UI. Like a tooltip constantly updated with some odd data that we specify, or hotkey labels that are constantly kept updated rather than OnHoverIn/Out.

Quib

ger 04-08-2005 11:14 PM

Quote:

Originally Posted by Quib
If we can get while loops working, and if they cause no slowdown during an infinite loop, they could be used to cause active operations occur with the UI. Like a tooltip constantly updated with some odd data that we specify, of hotkey labels that are constantly kept updated rather than OnHoverIn/Out.

Quib

{Emphasis added}

Why do I have the feeling we're about to bring every EQ2 server to is knees? Or maybe just the client machines. ;)

ger 04-08-2005 11:25 PM

So much for that theory. I just tried the following:

Code:

<Page AbsorbsInput="false" Location="8,62" Name="SpellsPage" OnShow="Loop.Press=true" ScrollExtent="570,367" Size="570,367">
<Button Name="Loop" OnPress="Entry0.Name.Text=Entry0.Icon.Tooltip
    Entry1.Name.Text=Entry1.Icon.Tooltip
    Entry2.Name.Text=Entry2.Icon.Tooltip
    Entry3.Name.Text=Entry3.Icon.Tooltip
    Entry4.Name.Text=Entry4.Icon.Tooltip
    Entry5.Name.Text=Entry5.Icon.Tooltip
    Entry6.Name.Text=Entry6.Icon.Tooltip
    Entry7.Name.Text=Entry7.Icon.Tooltip
    Entry8.Name.Text=Entry8.Icon.Tooltip
    Entry9.Name.Text=Entry9.Icon.Tooltip
    Entry10.Name.Text=Entry10.Icon.Tooltip
    Entry11.Name.Text=Entry11.Icon.Tooltip
    Entry12.Name.Text=Entry12.Icon.Tooltip
    Entry13.Name.Text=Entry13.Icon.Tooltip
    Entry14.Name.Text=Entry14.Icon.Tooltip
    Entry15.Name.Text=Entry15.Icon.Tooltip
    Press=Parent.Visible" ScrollExtent="1,1" Size="1,1" Visible="false"></Button>
{Other usual spell page stuff}
</Page>

The second I clicked the 'Spells' tab in my Knowledge window my game froze. About 15 seconds later it crashed silently to the desktop. So it seems we'll neither bring the servers nor the client machines to their knees, just the client application. ;)

Quib 04-08-2005 11:27 PM

Hehehe, oh well. I was hoping it wouldn't do a true loop and would only run the OnEvent once per frame.

Quib

Deathbane27 04-09-2005 01:17 AM

Quote:

Originally Posted by hirebrand
So

<Button
A="/GameData.Self.Power"
B="50"
OnPress="Emoter.Bool.Visible=(A)>(B)" }

<Page
Name="Emoter"
OnShow="laugh"
OnHide="cry" }

is the equivalent of

IF GameData.Self.Power > 50
THEN laugh
ELSE cry

?


You can't set a property to DynamicData. Here's how you'd do that:

<Progressbar Name="Power" DynamicData="/Gamedata.Self.Power"...
<Button OnPress="Parent.Trigger.Activated=(Parent.Power.Progress)>0.500"...
<Button name="Trigger" OnActivate="laugh" OnDeActivate="cry"...


Of course you'd actually have to have TWO triggers, one for activate, one for deactivate, because the OnActivate doesn't trigger if it's already activated, etc. But that's relatively minor. :D




More brainstorming:

Had someone request for a on-screen visual or sound when you are under attack. Best I could do was make it so when anything near you was attacked it brought up a window.

Now we can have that window check to see if your health is less than 100%, and if it is, make trigger some flashing and noise. :D

ger 04-09-2005 01:23 AM

Quote:

Originally Posted by Deathbane27
More brainstorming:

Had someone request for a on-screen visual or sound when you are under attack. Best I could do was make it so when anything near you was attacked it brought up a window.

Now we can have that window check to see if your health is less than 100%, and if it is, make trigger some flashing and noise. :D

Often times when I'm first attacked the attack misses or is resisted. In cases such as these a health<100% check would return false even though I really am under attack. But it's a good start. :D

Zonx 04-10-2005 08:40 PM

Text comparisons work!
(fubar)==(fubar)
returns true

If parent.text='fubar'
(parent.text)==(fubar)
is true

Simpler notation
parent.text=='fubar'


AND
(test1)&(test2) returns true if both tests are true
parent.text=='fubar'&1==1
is true
parent.text=='fubar'&1==2
is false

Bitwise
&! and !& appear to do the same as &.

OR and XOR
| and || seam to result in the second test being ignored. Resturns value of the first test. Same for ^


All times are GMT -5. The time now is 08:13 PM.

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