Getting slider value in its On-Update-script then update other variables

Diaa shared this question 4 months ago
Answered

In the attached file, the slider RackDisplacement should accordingly update the positions of both RackRightJoint and RackLeftJoint.

So, what is missing to make it work?

Comments (12)

photo
1

Hm,


if do not use RackDisplacement in definition of RackRightJoint and RackLeftJoint then nothing will happen.

what work should be done?

what is the intention of the inputbox for slider RackRightJoint

photo
1

I am trying to build a simplified rack-and-pinion steering mechanism.

So, the rack displacement should affect the horizontal position of both right and left joints.

photo
1

then you have to add/subtract the rack displacement in the x-coordinate of both right and left joints

photo
1

Ups, I saw your script part later


  • Its not necessary to use script,
  • use slider in definition of RackLeftJoint=((-RackLength) / 2 + RackDisplacement , 0)

  • SetValue is used to set a value not a definition
  • Sets the double value of the object with the given name. Note: if the specified object is boolean, use a value of 1 to set it to true and any other value to set it to false. For any other object type, nothing is done.

  • SetValue expects the name of a variable, nothing else

  • access a point with
  • void setCoords(String objName, double x, double y)

  • RackLeftJoint, RackRightJoint are bounded variables, they have a definition dependent on other variable - you cannot overwrite bounded variables by script only free variables

photo
1

I am already using the definition

RackLeftJoint=((-RackLength) / 2 + RackDisplacement , 0)

in my main document but it takes a lot of processing time with the other objects (not shown in my minimal example here).

May I know why

app.setCoords("RackRightJoint" , RackLength/2 + RackDisplacement,0 );

doesn't work? or how to make it work?

I would be grateful if you could attach a file of your idea.

photo
1

See last addion of my last answer, but what should javascript change to processing time?

photo
1

I believed in what is written here https://wiki.geogebra.org/e... unless I didn't understand it correctly.

photo
1

Make Rack... to free variables


RackLeftJoint = (-327.5, 0)

RackRightJoint = (367.5, 0)


RackLength = app.getValue("RackLength");
RackDisplacement = app.getValue("RackDisplacement");
app.setCoords("RackRightJoint", RackLength / 2 + RackDisplacement, 0);
app.setCoords("RackLeftJoint", -RackLength / 2 + RackDisplacement, 0);


but this is redundant I do not do a job by script witch is better done by processing commands

photo
1

https://wiki.geogebra.org/e...

avoid scripting at all if possible

photo
1

@Michael which is self-contradictory to the following lines encouraging using JavaScript commands instead of normal assignment ones.

photo
1

No, it's not. Scripting = typed into script tabs

photo
1

@Michael So, do you mean I am encouraged to write down ggbApplet.setValue(a , c+b) in the input bar/field instead of a = c+b ?

photo
© 2021 International GeoGebra Institute