Troubleshooting
why are these not the same?
Started by oldgearguy on .
Sign in or create an account to join the conversation.
Original post edited -- I typed too quickly...
script attached to a switch, set for On Expression, x, any
(x == 1) ? doIt(1) : doIt(0);
never triggers the true case
if (x == 1)
doIt(1);
else
doIt(0);
works as designed
script attached to a switch, set for On Expression, x, any
(x == 1) ? doIt(1) : doIt(0);
never triggers the true case
if (x == 1)
doIt(1);
else
doIt(0);
works as designed
Shouldn't it be
(x == 1) ? doIt(1) : doIt(0);
Or am I confusing this with a different formula?
(x == 1) ? doIt(1) : doIt(0);
Or am I confusing this with a different formula?
I think Mr Corba nailed it!
I edited the original -- typed too quickly. Yes, the '?' is/was in the statement in my code.
I attached a simple test script here to demonstrate.
test.jzml
I attached a simple test script here to demonstrate.
test.jzml
and while I'm here ranting,
why does this work -
setattribute(Monitor, 'label', 1); // use 1 to show name, 0 to hide it
and this does not????
setattribute(Monitor, 'name', 'New Name');
why does this work -
setattribute(Monitor, 'label', 1); // use 1 to show name, 0 to hide it
and this does not????
setattribute(Monitor, 'name', 'New Name');
I think I found a fix for your first problem, don't know exactly why but this does seem to work:
doIt( (x == 1) ? 1 : 0);
doIt( (x == 1) ? 1 : 0);
Yup the doIt part doesnt work although I think I agree it should. mr Corba's syntax is indeed more elegant, but still I cant find why:
(x==1)? doIt(1) : doIt(0);
shouldnt work. Perhaps the a?b:c syntax comes from the old days of one line scripting of Lemur and as such, wasnt designed to "call" custom functions? Dont have a clue
As for the name attribute, I dont know if its by design, but I just noticed that in the Lemur user guide, the description for the name attribute says:
get object name.
Perhaps this attribute is only meant to be "read" and not changed? Not sure! I have never tried to rename an object via scripting before.
(x==1)? doIt(1) : doIt(0);
shouldnt work. Perhaps the a?b:c syntax comes from the old days of one line scripting of Lemur and as such, wasnt designed to "call" custom functions? Dont have a clue
As for the name attribute, I dont know if its by design, but I just noticed that in the Lemur user guide, the description for the name attribute says:
get object name.
Perhaps this attribute is only meant to be "read" and not changed? Not sure! I have never tried to rename an object via scripting before.
Thanks for confirming I'm not going crazy. I also tried assigning the result to a dummy variable (dummy = (test) ? choice(A) : choice (B);) to see if forcing it to store the result would have an effect, but that didn't change the behavior.
I agree, the test embedded in the functional call is more elegant and that is what I'm generally going to do. It get a little less clear when the 'stuff' being evaluated to the left of the question mark and the choices on the right are more complex expressions than the example, but it's good to know it works.
Since scripts have size limits, any way to conserve characters is welcome.
I agree, the test embedded in the functional call is more elegant and that is what I'm generally going to do. It get a little less clear when the 'stuff' being evaluated to the left of the question mark and the choices on the right are more complex expressions than the example, but it's good to know it works.
Since scripts have size limits, any way to conserve characters is welcome.
The main reason for it was to use a single Monitor object as a general debug display module. Assign the name as the name of the object being moved and then display the value on the second line. That way I could encapsulate a "setattribute() and Monitor.value =" combo in a script and call it from wherever I needed to see what was going on.Softcore wrote:Yup the doIt part doesnt work although I think I agree it should. mr Corba's syntax is indeed more elegant, but still I cant find why:
(x==1)? doIt(1) : doIt(0);
shouldnt work. Perhaps the a?b:c syntax comes from the old days of one line scripting of Lemur and as such, wasnt designed to "call" custom functions? Dont have a clue
As for the name attribute, I dont know if its by design, but I just noticed that in the Lemur user guide, the description for the name attribute says:
get object name.
Perhaps this attribute is only meant to be "read" and not changed? Not sure! I have never tried to rename an object via scripting before.