快速登录:  

Forum: General Discussion

话题: Scripting: & vs &&
RanikiPRO InfinityMember since 2018
Scripting query here...... I'm trying to better understand the difference between "&" + "&&" in scripting.

In the VDJScript page it says:
Quote :
When chained commands are used in queries, the result depends on the state of the 1st action. E.g. play & loop will return true if the deck is playing (regardless if the deck is looped or not).
If && is used instead of &, to chain commands in queries, the query returns true only if both chained commands return true.
E.g. play && loop query will return true only if both commands return true (deck is playing and is looped) and false in all other cases.Some


So my questions:
1) Why would you ever use a multiple string query with "&" if only the result of the first action queried is relevant?
2) I notice that in some examples "&&" is used not only in queries, but also in actions that are chained commands. Why would you do that when a string of commands separated simply by "&" executes all the commands?

Many thanks for any pointers..... :-)
 

发表时间 Sun 11 Apr 21 @ 10:01 am
For validation purposes
So of instance if you put this on a custom button or pad page pad:
effect_slider 'echo' 1 50% & effect_active 'echo'
it will set set the strength for echo to 50% and turn the effect on - and the button/led will also light up, visually telling you that it's on
If you then click it again it will reset the strength for echo to 50% (which won't change anything), but then turn the effect off - so act like an effect toggle
That is what you will normally want - but the bad part: The button/led will still be on when the effect is off
Why? Because the first part (effect_slider 'echo' 1 50%) is still true - that is the current value of the echo effect first slider/knob
If you instead put in:
effect_slider 'echo' 1 50% && effect_active 'echo'
it will act exactly the same when it comes to the audio - but the button/LED will turn off when the effect is toggled off (the second click).
Why? Because then both parts of the statement are validated, and the second part if false when the effect is toggled off
It can get a lot more complicated than that, but that is just a simple example
 

发表时间 Sun 11 Apr 21 @ 1:35 pm
RanikiPRO InfinityMember since 2018
Thanks Klausmogensen.

I can see that, as you say, it can get a lot more complicated - so I will ponder on it and see if I can get my head around it!
 

发表时间 Sun 11 Apr 21 @ 7:18 pm
locoDogPRO InfinityModeratorMember since 2013
the && is mostly used in skins and button leds, but also has use in action script [but still in a query type of use]
consider this,
say I want one thing to happen only if 3 things are true, but something else if that is not the case
it would be kind of horrible

first thing ? second thing ? third thing ? all true, do the true thing : 3rd not true : 2nd not true : first not true

we can do this

param_equal `automix && deck 1 play && deck 2 loaded ? false : true` 1 ? all true : something false
 

发表时间 Sun 11 Apr 21 @ 8:15 pm
NicotuxHome userMember since 2014
in these boolean conditions of use (other exist when out of query mode)
&& can be see as a logical and
& as simple action separator

but constructs such as
first thing && second thing && third thing ? all true, do the true thing : 3rd not true
prevent the other "kind of horrible" possibilities to do things " : 2nd not true " and " : first not true " are both missing and thus are only suitable ONLY for logical tests for buttons or in queries (backquoted or not)

first thing && second thing && third thing ? action1 : action2
is equivalent (in result value) to
first thing ? second thing ? third thing ? action1 : action2 : nothing : nothing
or more exactly will return the same as
first thing ? second thing ? third thing ? action1 : action2 : false : false

the difference is appending actions
in first script they will be executed when 3rd not true
in second script they will be executed when 1st not true

with && no action can be performed as long as 3rd test is not reached and script immediately stop with current result

trust tables: x= any 0= false 1= true r = result

321 r generic example action1=action1 action2=action2
xx0 0 (status of 1st)
x01 0 (status of 2nd)
011 x (action2 result state) can even be float, int, text, percent, color, time... actions can follow up to end
111 x (action1 result state) can even be float, int, text, percent, color, time... actions can follow up to next ":"

321 r specific example: action1='false" action2="true"
xx0 0 (status of 1st)
x01 0 (status of 2nd)
011 1 (specified action true) actions can follow up to end
111 0 (specified action false) actions can follow up to next ":"

this in NOT POSSIBLE in VDJSCRIPT:
(first thing && second thing && third thing) ? all true, do the true thing : not true, do false thing...
 

发表时间 Sun 11 Apr 21 @ 10:13 pm
RanikiPRO InfinityMember since 2018
Thanks Locodog and Nicotux......

So would you ever use just '&' in a query (as suggested in the VDJPEDIA Script page):
Quote :
"When chained commands are used in queries, the result depends on the state of the 1st action. E.g. play & loop will return true if the deck is playing (regardless if the deck is looped or not)."


What would be the point of that?

 

发表时间 Mon 12 Apr 21 @ 7:47 am
Tato100PRO InfinityMember since 2017
I need your help

I would like to increase the "vocal" effect % when I apply the vocal stem, something like this...
only_stem "Vocal" & eq_mid 70%

But I need to return to 50% "vocal" later. How can I do it.

Thank you

 

发表时间 Wed 22 Sep 21 @ 9:42 pm
NicotuxHome userMember since 2014
only_stem "Vocal" & stem "Vocal" 70%
 

发表时间 Wed 22 Sep 21 @ 10:46 pm
I just found this interesting thread.

Thank you Nicotux for the explanation of && and &

Nicotux wrote :
first thing && second thing && third thing ? action1 : action2
is equivalent (in result value) to
first thing ? second thing ? third thing ? action1 : action2 : nothing : nothing
or more exactly will return the same as
first thing ? second thing ? third thing ? action1 : action2 : false : false


I wanted to ask so I understand,
If one wanted to have:

action1 if all 3 things were true
and
action2 if any of them was not true.

one would write:

first thing ? second thing ? third thing ? action1 : action2 : action2 : action2

right ?



which you are saying is not the same as:

first thing && second thing && third thing ? action1 : action2
 

发表时间 Thu 23 Sep 21 @ 5:22 am
NicotuxHome userMember since 2014
No, and do not take it in consideration !!
================================

Historically actions were only executed when both first and second things and more were all true, script ending otherwise

action1 if all were true, action2 if first and second ... were true and third (last) one was false

actions only being executed depending on third (last) thing only
no action otherwise


But this is apparently not really stable between versions:

Since b6604 everything changed and does not ends the script anymore

by the way display does not reflect the whole test but only first one

first thing && second thing ? action1 : action2
0 0 will display '?' and execute action 2
0 1 will display '?' and execute action1
1 0 will display 'on' and execute action2
11 will display 'on' and execute action1
^__ ignored as a test, only one as a display

This is the not what is wanted :
&& does not act as a grouping action anymore and is exactly like a &
it doesn't take care of anything else but last test
it doesn't take care about anything else but first for display

There were some fix afterward :
as on today b6646 :
display was somehow fixed and now reflects the correct state, only 'on' when everything is true

but still only take last test in consideration whatever the result of the other precedent ones can be
&& currently a grouping for display, not for test in scripts where it is similar to &


badly this topic was started during behavior changed (or maybe it's a bug)
better wait for a correct explanation from team devs !!!
 

发表时间 Thu 23 Sep 21 @ 7:28 am