Can I Set Caption of added point with Point Tool using GlobalJavaScript?

Juan Carlos Ponce Campuzano shared this question 10 months ago
Answered

Hi everyone,

I am trying to make an applet using global Javascript that:


  1. Adds a point to a predefined list using the Tool Point. (solved).
  2. Change the caption of every added point. That is, instead of having the standard notation A, B,C, etc, to set the caption of each adde point as A1, A2, A3,... (not sure how to do it).

This is what I have done so far:

function ggbOnInit() {
 ev("Sx = {}");
 ev("ind = 0");
 ev("text1 = UnicodeToLetter(65)");
 ev("text2 = Text(ind)");
 ev("text3 = text1 + text2");
 ggbApplet.registerAddListener("listener");
}

function listener(obj) {
 if (ggbApplet.getObjectType(obj) == "point") {
 ev("SetValue(Sx, Length(Sx) + 1, " + obj + ")");
 ev("SetValue(ind, ind + 1)");
 ev("SetCaption(" + obj + ", text3)");
 }
}

function ev(x) {
  ggbApplet.evalCommand(x);
}
I could not find something related in the forum. Is this possible? Any help would be appreciated.

Thank you.

Comments (7)

photo
1

1) Have you tried simply renaming them?


2) Please always post your .ggb file

photo
1

Sorry, here is the file.

I thought that to rename the object I need to use the command SetCaption(). Is there a "rename" command?

photo
1

Oh, thanks, I will try it tomorrow.

photo
1

I tried the Rename command. It works nice in the desktop version, but the online version create a duplicate of every point.

https://www.geogebra.org/m/vqx8jajd

Maybe I am doing something wrong? Any advice would be appreciated. Thanks.

photo
1

It's just a display bug - do you need the Algebra View open?

photo
1

No really. I am just doing some tests. This is the result so far.

https://www.geogebra.org/m/vxztu2cu

I wanted to do it with Pen stroke but it does not work online, only on desktop:

https://www.geogebra.org/m/dpdjcxbf

Do you think is the same bug? Or it is just my applet? Thanks

photo
© 2021 International GeoGebra Institute