Javascript will not run after the update

Ladislav Průdek shared this question 2 years ago
Answered

Hallo,

I have defined 3 variables in geogebra ... ZC, C1, C2.

Using the InputBox(ZC), I change the value of the ZC variable from the keyboard. In the InputBox settings, I will run javascript after the update:

{ ggbApplet.setValue("C1", ggbApplet.getValue("ZC")); }

After changing the value of the variable ZC, the value C1 will also change.

I want to run another javascript in the properties of variable C1 after updating this variable. However, it will not start. It only starts when I change the value from the keyboard in the InputBox (C1).

I found the RunUpdateScript () command in the manual, but it probably only works with geogebra scripts, not with java scripts.

Can anyone advise me please?


Thank you

Comments (10)

photo
1

Please post your .ggb file

photo
1

Hi Michael,

the applet is simple so far. I wanted to test whether the Palindromic number could be examined using scripts. I haven't entered the iteration counter there yet.

Would you find a solution?


Thank you

Ladislav

photo
photo
1

Why are you using JavaScript? I think it will be much easier using GeoGebra commands, eg to reverse a string

UnicodeToText(Reverse(TextToUnicode("hello")))

photo
1

Geogebra script is simple and also very limited. Cannot work with conditional structures, loops, etc.

Plus, I work with numbers, not texts, so it should be

SetValue(C2,TextToUnicode(Reverse(UnicodeToText(C1))))

but it doesn't work

photo
1

ParseToNumber(C2,UnicodeToText(Reverse(TextToUnicode(Text(C1)))))

photo
1

conditional structures -> If()


loops -> Sequence()

photo
photo
1

un cambio de valor de una variable mediante/dentro de un script o javascript no pone en marcha el on update script de esa variable para evitar bucles infinitos

el usuario debe forzar su ejecución con un RunUpdateScript( <Object> ) dentro del script que cambia el valor de la variable. Dentro del script se puede comprobar si la variable ha cambiado mediante su almacenamiento en otra variable de uso temporal

photo
1

¿Y está seguro de que el comando GetUpdateScript (Objeto) funciona tanto para gegebra-script como para java-script?

Cuando escribo en GetUdateScript ("C1"), GGB imprime un error de referencia (función no definida).

Cuando escribo ggbApplet.GetUdateScript ("C1") en el script, imprime un error de JavaScript GGB (no una función).

¿Esta función no solo funciona para ggb-script?

photo
1

Lamento haber tenido el GetUpdateScript() incorrecto y debería ser RunUpdateScript(). Desafortunadamente, todavía no funciona y los mensajes de error son los mismos

photo
photo
3

runupdatescript() es un comando de GG no es java

si tu quieres usar un comando GG desde java debes escribir

ggbApplet.evalCommand('RunUpdateScript( "C1" )') o algo similar

pero insisto como Michael,¿Por qué hacer con java o con script algo que se puede hacer desde GG con facilidad?

mi experiencia me dice que casi nunca es necesario un script y mucho menos javascript y que cuando se usa sin ser necesario todo se vuelve un problema

© 2023 International GeoGebra Institute