how do I use the script function?

Adrian shared this question 1 year ago
Answered

Hello all!

I have two arbitrary points, Point A and Point B, on a sine curve, y=sin(x), that I would like to animate simultaneous using a button so that both points move along the sine curve. I tried using the StartAnimation command but to no avail. I have attached the .ggb file to this post.

Please, can someone guide me on how to script the button properly? Thanks in advance.

- Setoyaya

Best Answer
photo

Hi

As Michael and Simona said..

1) create a boolean start=true (in input bar)

1b8dcdb97b420e8b9a9c24a32dcf7dc2

2) create a button with start in caption

6d9ac215f23ea13b9dd0f0e9ddfea70f

3) in Scripting On Click of button, write this

(and don't forget clic on ok)


6651d2cbc8ca31d8c2b95e9c84cc55c2


(notice i changed also the button legend..)

Comments (6)

photo
1

Does this do what you want?

StartAnimation(a)

If not, please explain more what you want

photo
1

Hi Mr. Borcherds,

Thanks for your reply. I would like to create a button that both starts and stops the animations of point A and point B simultaneously. StartAnimation(a) and StartAnimation(b) only starts the animations of point A and B but doesn't stop it. How do I implement the stop function as well? Additionally, after pressing stop, I would like point A and point B to reset to it's least value on the sliders.

- Setoyaya

photo
1

This is an idea: create a Boolean

start=true
then the script for button to toggle animation on and off is

StartAnimation(a,start)
SetValue(start,!start)

photo
1

Hi Ms. Riva,

Do I create the boolean expression within the script of the button as well? I tried and the button does perform the on function but not off.

-Setoyaya

photo
1

Hi

As Michael and Simona said..

1) create a boolean start=true (in input bar)

1b8dcdb97b420e8b9a9c24a32dcf7dc2

2) create a button with start in caption

6d9ac215f23ea13b9dd0f0e9ddfea70f

3) in Scripting On Click of button, write this

(and don't forget clic on ok)


6651d2cbc8ca31d8c2b95e9c84cc55c2


(notice i changed also the button legend..)

photo
1

That did the trick!

Thanks for the help Mr. Borcherds and Ms. Riva! The clear and concise images were extremely helpful. Thanks, Jumera!

photo
© 2019 International GeoGebra Institute