# More compatibility between GeoGebra and JavaScript

a.zampa shared this idea 10 years ago
Under Consideration

GeoGebra is a great software, however it lacks compatibility to JavaScript with respect to some crucial aspects. It is not easy to pass objects from GeoGebra to JavaScript and conversely. For example, to retrieve the values of a list one has to use a very cumbersome precedure, e.g.

for (index = 1; index <length+1; i++ ) {

ggbApplet.evalCommand("i=1");

ggbApplet.evalCommand("a=Element[list, i]");

a = ggbApplet.getValue("a");

// use the value of a

}

It would be desirable to access GeoGebra objects as JavaScript objects: ggbApplet.getValue() returns only the double value associated to the object (e.g. the length of a segment).

Why not introduce a new function Object ggbApplet.getObject(String name) which returns the entire object?

To set the value of a list is even worse: you need to do something like

ggbApplet.evalCommand("SetValue[list,"+index+","+val+"]");

but this time, due to a design choice, this solution is not correct because there is a syntax incompatibility between GeoGebra and JavaScript concerning scientific notation: if val = 0.000000001 then JavaScript puts "1e-9" in place of val, but GeoGebra interprets this as "1*e - 9" where "e" is the base of the natural logarithm.

To correct the problem one should use the following kind of code:

a = "[list,"+index+","+val+"]";

ggbApplet.evalCommand("SetValue"+a.replace(/e/g,"E"));

Therefore, I propose to introduce a new function void ggb.setObject(String name, Object value) which sets a new value to the existing object name or creates a new object with the given name and value if it does not exist.

Is all of this useful? It's your turn!

1

Please try the new commands set/getListValue() in GeoGebra 4.2:

http://wiki.geogebra.org/en...

2

Wonderful! And now a little step further :wink: : what if one stores segments into a list? Or if the elements of a list are lists themselves? This is the reason why I ask for a full object instead of simple floating numbers: more generality means more power!

Now, I do not need to uncover the internal structure of GeoGebra objects, nor did I put my hands into the source files, so I really don't know how you pass values from GeoGebra to JavaScript and viceversa, i.e. I'm not aware of the technical difficulties insit in what I am proposing, but concerning values one could define a user object structure for any kind of GeoGebra object, without the necessity of conveying methods to the user object.

E.g. each object could have a type field whose value is "number", or "boolean", or "point", or "segment", ... as you do for the ggbApplet.getObjectType() command, and a set of corresponding values: for numbers a field value which is a float, for points a field value.x for the x coordinate and a field value.y for the y coordinate, for lists a field value which is an array of objects, and so on.

Of course, :smiley_cat: , before embarking on such an undertaking one has to understand how many users will use all of this power, or to decide that it should be part of the project even if nobody will ever use it. I promise to use it :exclamation: :laughing:

(A little question: how many users of GeoGebra you expect will ever use JavaScript inside a construction? The average one?)

Thanks

Alessandro

1

Hi Alessandro,

(A little question: how many users of GeoGebra you expect will ever use JavaScript inside a construction? The average one?)

Free mathematics software for learning and teaching
and
From elementary school to university level

I teach maths at pre-university level in the UK and have been using GeoGebra since 2008. We have about 700 students aged 16-19 studying maths with us, of whom maybe 20 will know any JavaScript. I hope that many of these students will use GeoGebra to assist their learning of mathematics. None of our 11 maths teachers knows any JavaScript, and so far I have not needed to use it in my GeoGebra applets. With 9 years of compulsory maths education in the UK, then only a third of each cohort going on to study maths aged 16, and even fewer going on to university level maths, the proportion of learners needing to use JavaScript when they use GeoGebra must be minute. And I do consider young children able to use GeoGebra for themselves - my 5 year old grandson has done so. (Not just using pre-created applets.)

There are a few occasions when I appreciate using a highly polished complex applet, but much of the value of GeoGebra to me is the accessibility of the program and the way that constructions can be easily followed, so students can more easily grasp the mathematics.

I am not writing as one who is ignorant in the computer programming field - before I started teaching maths I did a substantial amount of programming, in high-level languages. And I am determined to learn to use Python, through GeoGebra, so I can better teach such topics as the use of algorithms in Decision/Discrete Maths.

I spent 3 hours yesterday evening familiarising myself with the Raspberry Pi, http://www.raspberrypi.org/about with the aim of running a project using it in college. This computer was developed because in the creators' words:

We want to see it being used by kids all over the world to learn programming.
Yet I was sad to note that at the event I attended I was the only educator, and virtually everyone else was there for purely personal interest.

I know many of the regular contributors on the GeoGebra forum are committed educators, and do use scripting to some extent, but I hope that GeoGebra will maintain its purpose in mathematics education.

Just one view, from one maths teacher, who uses GeoGebra on a daily basis in the classroom!

Kathryn

1

Dear Kathryn,

it seems that you have been misled by my little question! Just to assure you, I am a teacher of mathematics as well, at high school level, and I use Geogebra on an everyday basis too, so you are "knoking down an open door", as we say in Italy...

The fact is, however, that I need scripting in order to be able to do some simulations (e.g. of a string to introduce goniometric functions, ...) so I'm asking for features I need to use with students! The question I ended my last replay with was meant to make understand that a feature should be added even if its users will be very few, as for the case of scripting that developers chose to implement.

I hope to have fully explained my intents, now.

Bye

Alessandro

1

May be the new Python-Scripting will help you ... but like Kathryn ... I use more the simple tools.

Or .. what's about using the log, to avoid the problems with too big or small numbers.

May be, there will be a solution inside of GeoGebra. Even with the simple tools, you can do very much ;-)

If you tell us more about your simulation-problem, we can help a bit better.

Grüße, Birgit

1

IMHO, most users of GG are educators and students who will use neither Javascript nor Python-scripts. Speaking for myself, I have a limited knowledge of Javascript, I teach Java, but have no knowledge of Python...I do use GeoGebraScript extensively.

I do want those who know Javascript and Python to be able to work their magic, but over 80% {probably a low estimate} of the users are casual users who use GG much like a graphing calculator on steroids. Most will never write serious applets, but with the appropriate scripting technology tools many teachers and students will benefit. Most of the users of GG scripting are probably members of this forum.

For example, the TI-Nspire system has a scripting language called lua, I would say less than 2% of the Nspire users will ever program using it. However, many students and teachers will benefit from those who use the script.

Tony

2

ggbApplet.evalCommand("list=Sequence(RandomBetween(-10, 10),i,1,RandomBetween(2,10))");

ggbApplet.evalCommand("n=Length[list]");

var n= ggbApplet.getValue("n");

var aA= new Array();

for (var i = 1; i <=n; i++ ){

ggbApplet.evalCommand("a=Element[list,"+ i+"]");

a = ggbApplet.getValue("a");

aA.push(a);

}