Functions in rules. For example, ABS.
Moderators: grovkillen, Stuntteam, TD-er
- Andrew Mamohin
- Normal user
- Posts: 95
- Joined: 12 Jun 2020, 08:30
- Location: Belarus, Gomel
- Contact:
Functions in rules. For example, ABS.
I need an ABS function in the rules. I need to execute a block based on the difference between two temperatures (regardless of which direction) How can you do this?
Andy.
Re: Functions in rules. For example, ABS.
Right now we don't have an abs call, but you could store the result in a variable and simply check to see if it is negative.
If it is negative you can multiply its value by -1.
Or just check the 2 values you want to subtract.
If A > B do A-B else B-A.
If it is negative you can multiply its value by -1.
Or just check the 2 values you want to subtract.
If A > B do A-B else B-A.
- Andrew Mamohin
- Normal user
- Posts: 95
- Joined: 12 Jun 2020, 08:30
- Location: Belarus, Gomel
- Contact:
Re: Functions in rules. For example, ABS.
Well, it's ass-backwards!
Thanks for the help, I did:
Code: Select all
on T_1#T do
if [T_1#T] > [T_2#T]
TaskValueSet 12,3,[T_1#T]-[T_2#T]
else
TaskValueSet 12,3,[T_2#T]-[T_1#T]
endif
endon
on T_2#T do
if [T_1#T] > [T_2#T]
TaskValueSet 12,3,[T_1#T]-[T_2#T]
else
TaskValueSet 12,3,[T_2#T]-[T_1#T]
endif
endon
Andy.
Re: Functions in rules. For example, ABS.
or...
[Device#Value]^2^.5
for ABS.
[Device#Value]^2^.5
for ABS.
- Andrew Mamohin
- Normal user
- Posts: 95
- Joined: 12 Jun 2020, 08:30
- Location: Belarus, Gomel
- Contact:
Re: Functions in rules. For example, ABS.
User defined events are the substitute for subroutines:Andrew Mamohin wrote: ↑22 Sep 2020, 17:57 How can I do it in one block? There are no subroutines in the rules.
Code: Select all
on T_1#T do
event,CalcAbsDiff
endon
on T_2#T do
event,CalcAbsDiff
endon
on CalcAbsDiff do
if [T_1#T] > [T_2#T]
TaskValueSet 12,3,[T_1#T]-[T_2#T]
else
TaskValueSet 12,3,[T_2#T]-[T_1#T]
endif
endon
Last edited by Ath on 23 Sep 2020, 11:24, edited 1 time in total.
/Ton (PayPal.me)
- Andrew Mamohin
- Normal user
- Posts: 95
- Joined: 12 Jun 2020, 08:30
- Location: Belarus, Gomel
- Contact:
Re: Functions in rules. For example, ABS.
Thank! I did this.
You got a typo:
on T_2#T do
event,CalcAbsDiff
enddo
need endon
Andy.
Who is online
Users browsing this forum: No registered users and 87 guests