Troubleshooting
Script syntax question
Started by Cumulonimbus on .
Sign in or create an account to join the conversation.
Hi,
New to Lemur. I'm trying to set the value of a bunch of Knobs whenever the interface loads. The knobs are inside a container object, which contains two tabs (each with different knobs). I attached the following script to the container object using "On Load" but I don't understand why I get a syntax error:
Thanks for your help.
New to Lemur. I'm trying to set the value of a bunch of Knobs whenever the interface loads. The knobs are inside a container object, which contains two tabs (each with different knobs). I attached the following script to the container object using "On Load" but I don't understand why I get a syntax error:
decl object;
object = getfirst(Knobs_Container);
while (object) {
object.x = 0.1;
object = getnext(Knobs_Container);
}
I tried this with "setattribute(object, 'x', 0.1)" but this doesn't work either.Thanks for your help.
setexpression(object, 'x', 0.1)
X is an expression, not an attribute!
X is an expression, not an attribute!
Thanks, I don't get a syntax error now, but the script doesn't work (knobs values are not reset at all). Any ideas?
Try is using a manual script. i.e. - create a pad. add a script to the pad. Have the pad script execute on expression x going from low to high (arrow pointing up).
in the pad script, try setting the controls to the value using setexpression.
The point is - initializing things directly in onload() scripts is weird. Sometimes some things work, other times not. I've had bizarre bugs because of what I was trying to do.
I've used other methods for initializing things. Let us know if you can get it to work properly via the manual button push method.
in the pad script, try setting the controls to the value using setexpression.
The point is - initializing things directly in onload() scripts is weird. Sometimes some things work, other times not. I've had bizarre bugs because of what I was trying to do.
I've used other methods for initializing things. Let us know if you can get it to work properly via the manual button push method.
Doesn't work either. Maybe it's my hierarchy? Let me simplify what I have here:
Project
-Interface1 (folder)
--Knobs_Container
---Tab1 (folder)
----Knob1
----Knob2
----Label1
----Label2
---Tab2 (folder)
----Knob3
----Knob4
----Label3
----Label4
--Pad with script
The script is the one in my first post with the modification given by Softcore. I assume labels would be ignored by the script's setexpression function, but maybe I'm wrong?
EDIT: I've created a test Container with no tabs or labels, and the script only sets the first knob in it. Somehow the getnext function isn't working (or I'm getting it wrong, more likely). It doesn't work even if I do this:
Project
-Interface1 (folder)
--Knobs_Container
---Tab1 (folder)
----Knob1
----Knob2
----Label1
----Label2
---Tab2 (folder)
----Knob3
----Knob4
----Label3
----Label4
--Pad with script
The script is the one in my first post with the modification given by Softcore. I assume labels would be ignored by the script's setexpression function, but maybe I'm wrong?
EDIT: I've created a test Container with no tabs or labels, and the script only sets the first knob in it. Somehow the getnext function isn't working (or I'm getting it wrong, more likely). It doesn't work even if I do this:
decl object;
object = getfirst(Container);
setexpression(object, 'x', 0.2);
object = getnext(Container);
setexpression(object, 'x', 0.2);
BTW the forum doesn't send email notifications on new replies even though I've checked that option. Sorry for the delay in response...it apparently doesn't work the way we think. Try this code instead:
(edit): and doing it in an onload() script seems to work (at least in a trivial template).
decl object;
object = getfirst(Container);
setexpression(object, 'x', 0.2);
object = getnext(object);
setexpression(object, 'x', 0.5);
object = getnext(object);
setexpression(object, 'x', 1.0);
The idea is similar to C code functions that basically walk a pointer through a list, so you use the last position as the next starting point(edit): and doing it in an onload() script seems to work (at least in a trivial template).
That's odd, I did exactly what you suggested, on a new template with just a container, two knobs and a pad to trigger the script, and it still doesn't work. If anyone has time, please have a look at the file (it's the new project with only the controls needed to illustrate my problem, not the entire thing).
Thanks.
KnobsScript.jzml
Thanks.
KnobsScript.jzml
I think you missed my change.
In the ResetKnob() script you say:
object = getfirst(Knobs_Container);
setexpression(object, 'x', 0.2);
object = getnext(Knobs_Container);
setexpression(object, 'x', 0.5);
The change was in the getnext() call. It should be:
object = getfirst(Knobs_Container);
setexpression(object, 'x', 0.2);
object = getnext(object);
setexpression(object, 'x', 0.5);
In other words, use getfirst(Container name) and save off the returned object. Then in calls to getnext(object), use the returned object from the previous call.
So with 3 objects, it would look like this:
object = getfirst(Container);
// do something with object
object = getnext(object);
// do something with 2nd object
object = getnext(object);
// do something with 3rd object
In the ResetKnob() script you say:
object = getfirst(Knobs_Container);
setexpression(object, 'x', 0.2);
object = getnext(Knobs_Container);
setexpression(object, 'x', 0.5);
The change was in the getnext() call. It should be:
object = getfirst(Knobs_Container);
setexpression(object, 'x', 0.2);
object = getnext(object);
setexpression(object, 'x', 0.5);
In other words, use getfirst(Container name) and save off the returned object. Then in calls to getnext(object), use the returned object from the previous call.
So with 3 objects, it would look like this:
object = getfirst(Container);
// do something with object
object = getnext(object);
// do something with 2nd object
object = getnext(object);
// do something with 3rd object
I did miss it. Thank you very much, it works now even with the while loop.
Just out of curiosity, because I don't get it:
object = getfirst(Container) gets the first object in the Container, which is a Knob object.
It seems to me that object = getnext(object) would then get the next object in the Knob, which isn't meaningful.
It works, but I don't see why...
Just out of curiosity, because I don't get it:
object = getfirst(Container) gets the first object in the Container, which is a Knob object.
It seems to me that object = getnext(object) would then get the next object in the Knob, which isn't meaningful.
It works, but I don't see why...
It really comes down to how Lemur stores the references to the objects internally. If you think of the objects in a Container as links of a chain, then what you do when you say getfirst(Container) is to return the whole chain, with your hand holding the first link. Getnext(object) starts where you are holding the chain and moves to the next link. If you say getnext(Container) you are saying give me the next link starting from Container, which is going to always return the first link only.Cumulonimbus wrote:I did miss it. Thank you very much, it works now even with the while loop.
Just out of curiosity, because I don't get it:
object = getfirst(Container) gets the first object in the Container, which is a Knob object.
It seems to me that object = getnext(object) would then get the next object in the Knob, which isn't meaningful.
It works, but I don't see why...
You can play around with it by creating another Container inside the first one between the knobs (change knob2 name to knob3 and create a container called knob2) and see what happens. If you print the object name out (create a Monitor object and insert: Monitor.value = getattribute(object, 'name'); after a getnext(object) call, you will see that in fact knob1 is returned first, then knob2 (which is a container), then knob 3. If you embed another object in the new container (say another knob inside your knob2 container), you can't get to it using getnext(). Conceptually, it's like another small chain hanging down from one of the middle links and you can only traverse one chain at a time. You would need to do a getfirst(knob2) to start walking through those links.
I don't see any obvious way to be able to distinguish between objects other than by some attribute you set (i.e. - compare name, color, position, etc), so either you have to construct the objects in the way you want or do lots of checking after every return from getnext().
to Cumunolimbus: If its any help to get the logic...
getnext(object) does not get the next object in the object....but the "next" object in the project window hierarchy...
So, when you have two knobs inside a container, Knob1 and Knob2 x
getnext(Knob1) will get you Knob2.
Also keep in mind here that, unfortunately "tabs" of containers are an exception to this rule: even though they are shown in the project window hierarchy, they are not part of it - as in, if you have a Container with two tabs and Knob1, Knob3 in the first one, Knob2, Knob4 in the second tab:
getnext(Knob1) will NOT get you Knob3, it will get you Knob2.

getnext(object) does not get the next object in the object....but the "next" object in the project window hierarchy...
So, when you have two knobs inside a container, Knob1 and Knob2 x
getnext(Knob1) will get you Knob2.
Also keep in mind here that, unfortunately "tabs" of containers are an exception to this rule: even though they are shown in the project window hierarchy, they are not part of it - as in, if you have a Container with two tabs and Knob1, Knob3 in the first one, Knob2, Knob4 in the second tab:
getnext(Knob1) will NOT get you Knob3, it will get you Knob2.
Thanks a lot to both of you for taking the time to explain this! I was thinking of Containers as arrays, not thinking about project hierarchy. Much clearer now 