Page 1 of 2

Custom expression help !

Posted: 13 Jan 2019, 01:20
by jojo86
Hello,
I want to calculate a book status with a formulea.
I tried this one but It doesn’t works :
|| is for OR condition is it correct?

Code: Select all

If ([SIMCONNECT:INDICATED ALTITUDE] - 50 =  [SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR]
|| 
[SIMCONNECT:INDICATED ALTITUDE] + 50.00 =  [SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR] ,
1, 
0
)


I want to set the result of my expression to 1 if indicated altitude more or less than 50ft equals to autopilot altitude lock var.

After that, I want to use this expression like a variable.

But when I try, I can’t see any variable change... always equal to zero...

Maybe my expression is bad?

Thanx for your help,

Re: Custom expression help !

Posted: 13 Jan 2019, 10:42
by thedazman
Without looking at the expression syntax, I can see you are never getting a match with that.

You are looking to see if the altitudes are the same at + and - 50 and they might for a millisecond as they cross over

You need to use greater than and less than, not equals!

>
<

Daz

Re: Custom expression help !

Posted: 13 Jan 2019, 10:51
by thedazman
Without considering syntax your statement should be more like...

if altitude greater than ap lock + 50 or altitude less then ap lock - 50

Your statement is only true if alt = 5050 and ap lock =5000 the moment you altitude goes to 5051 it’s no longer true.

Daz

Re: Custom expression help !

Posted: 13 Jan 2019, 10:59
by jojo86
thedazman wrote:
13 Jan 2019, 10:51
Without considering syntax your statement should be more like...

if altitude greater than ap lock + 50 or altitude less then ap lock - 50

Your statement is only true if alt = 5050 and ap lock =5000 the moment you altitude goes to 5051 it’s no longer true.

Daz
Yes this is my objectif. This expression is like a trigger. I know that the expression can’t always be set to I. But I want to look on this status and if 0 become 1 I want to change led status.

Re: Custom expression help !

Posted: 13 Jan 2019, 11:11
by thedazman
That’s fine you can use the expression as a led trigger and it should work, but not while you are using = instead of less than/greater than.

Daz

Re: Custom expression help !

Posted: 13 Jan 2019, 11:41
by jojo86
thedazman wrote:
13 Jan 2019, 11:11
That’s fine you can use the expression as a led trigger and it should work, but not while you are using = instead of less than/greater than.

Daz
Ok, can you help me to write this condition ?
I want to change the status when the real altitude is near my autopilot altitude lock +-50feet.

I can try again but if you could help me I could spend a nice sunday :

Code: Select all

If ( [SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR] - 50 = [SIMCONNECT:INDICATED ALTITUDE] 
|| 
 [SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR] + 50 = [SIMCONNECT:INDICATED ALTITUDE]  ,
1, 
0
)
I don't know how I can do that with < or >...

Re: Custom expression help !

Posted: 13 Jan 2019, 13:44
by thedazman
Unfortunately I don’t know the expression syntax off the top of my head but greater and less then are usually coded as &gt; &lt;

Admin would be better to advise regarding expression syntax I can only advise you are using the operators

Daz

Re: Custom expression help !

Posted: 14 Jan 2019, 00:29
by jojo86
Hi, how can I use a AND operator ???
I tried this but I'm not sure that's works :

Code: Select all

If ( [SIMCONNECT:INDICATED ALTITUDE]  >=  [SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR] - 50 
  &&
 [SIMCONNECT:INDICATED ALTITUDE]<= [SIMCONNECT:AUTOPILOT ALTITUDE LOCK VAR] + 50
  , 1, 0)
 

Re: Custom expression help !

Posted: 14 Jan 2019, 08:31
by Oz Flyer
Try this, Just change the field names:

Code: Select all

If ( [LOCAL:OZ_TEST_1] > [LOCAL:OZ_TEST_2] - 51
    &&
   [LOCAL:OZ_TEST_1] < [LOCAL:OZ_TEST_2] + 51
, 1, 0)
If OZ_TEST_2 is set to 2550
Then output is "1" when OZ_TEST_1 is any where from 2500 to 2600.

I am no coder just dumb luck testing hope it work for you.

Re: Custom expression help !

Posted: 14 Jan 2019, 11:55
by thedazman
You can’t use < and > in xml they are reserved for xml tags and as all the programming is stored in xml profiles I’m not sure you can use <> ?

I haven’t done much expression programming with is why I said I can’t advise about expression syntax but would be interested to know if <> works

Daz