Javascript and Geogebra interaction (race conditions?)
I was encountering some problems with Javascript: It seems that after sending a command to Geogebra the script doesn't always wait for changes in Geogebra objects to manifest, thus creating a race condition and potentially producing wrong results if the remaining script depends on those objects. Is this generally the expected behaviour (or possibly just undefined behaviour)? If yes, is there a standard way to make the script wait or should scripts simply not be used with such kind of interaction?
Here's a small example that illustrates this issue:
Upon changing of a value of n a script is called that tells Geogebra to generate the divisor list, then to get the length of the resulting list, then this length is copied to a JS variable. Turns out, the JS variable always gets the previous list size from before the list changed.
ggbApplet.evalCommand("DL = DivisorsList(nn)"); ggbApplet.evalCommand("DLsize = Length(DL)"); var listsize = ggbApplet.getValue("DLsize"); alert("listsize: " + listsize);
Interestingly, this problem doesn't occur if instead of the divisor list a sequence is created, even a long one that takes a few seconds to create. Which leads me to belief that the script is actually supposed to wait but something goes wrong in the first case.
Attached are the problematic version with the divisor list and the okay version with the sequence.
does it the same if you use ggbApplet.evalCommand("SetValue(DL , DivisorsList(nn)") instead ?
Comments have been locked on this page!