JavaScript - Get "this" name

projetmbc2 shared this question 1 month ago
Answered

Hello.


I use the click tab of scripts. I would like to automatically have the name of the object where the script is used. I am looking for a kind of this.name functionality to get the name of the object. How can I do that?

polyname = "test";

thiscol = ggbApplet.getColor(polyname);

if (thiscol == "#000000") {
ggbApplet.setColor(polyname, 255, 255, 255);
} else {
ggbApplet.setColor(polyname, 0, 0, 0);
};

Comments (17)

photo
1

My idea is to build a grid with clickable squares: clicking on the square will toggle its face color (black <--> white).

photo
2

The "Me" ("this") object exist only in GGB-Script (with the name: %0)

Depending on what you want to achieve, there are shure better solutions.

For further support it is advantageous if you describe the problem (over all) to be solved.

----------------------------------------

sorry I see your description of the problem (in your last post) too late (time overlap)

Shortly I will send a solution without JS.

photo
1

seems to have settled with the following post (?)

photo
1

Great.


I can't see your post before... o_O


That's great and easy to understand. I will play more between GGB-Script and JS in the future.


Thanks a lot !

photo
1

Yes, it is. I will see why.

photo
photo
2

If you use the spreadsheet then you can make it quite efficiently eg https://www.geogebra.org/m/KwXttZ87

photo
1

It is another solution but I really prefer the solution of rami with one function managing all cases.

Maybe that is just a matter of taste.

photo
1

Both solutions just use one script for everything. However using the spreadsheet gives you a big advantage if you want a grid eg

SetValue[row, Row[%0]]
SetValue[column, Column[%0]]
RunClickScript[toggle]

Also you shouldn't need to use JavaScript for this

photo
1

Yes but I need JS to analyze the grid to obtain some coding of the grid for a pedagogical exercice. See the PDF attached.

photo
photo
1

All most done...

I update texts from JS but the back returns are not automatically printed.

See the file joined where I need to double click on each text to see the back returns.


Can this be fixed?

photo
1

You are using clasic version 5.0.581.0

50b161fb459c6aca0b279d7888ae46e0


This is a very old version that I cannot reproduce.

With my system (classic version 5.0.620 Windows10) I can't find the described error with your file. The different codecs are updated continuously.

Install version 5.0.620 and test again.

If the error still occurs: Describe your system environment (e.g. Windows 10 64 bit, ggb version 5.0.620.0-d Java 1.8.0_161-32bit). You can find the information in the menu Help/About License.

photo
1

The problem is still there. Here is my config.

  • GGB Classic version 5.0.620.0-d Java 1.8.0_201-64bit
  • Mac OS Catalina 10.15.7

photo
photo
1

If I understand you correctly:

The update of the 6 objects basicbincol, basicbin, chessc0ordwhite, chesscoord, faxlikecol and faxcol is executed only after another click on one (same?) cell. In other words: the display lags one click cycle behind (?).

I can't test it because I don't have a MAC. So I guess:

try:

write after the last line: ggbApplet.evalCommand('UpdateConstruction()')

If unsuccessful: use inside evalCommand('.....') the SetValue() method instead of the assignment with "=".

photo
1

check also with the version 6.0-WEB: https://www.geogebra.org/classic

In my environment I see no errors when I do this with firefox or chrome. The 6 textfields are updated synchrone with click.

When you have no errors with 6.0-WEB then the possibility of an GGB-bug is big.

What is also possible: I see not the error or you see a error where there is none (what is very difficult to "find")

photo
1

I have tried all your propositions. I have also try under Mint using VirtualBox without any success. I think the problem is related to Unix.


What is the best way to indicate this problem?

photo
2

Reduce the size of the application as much as possible so that it only contains the error,

Describe the way to create the error (step by step)

Describe what you get and what you expect with the above way (also step by step)

Make the application independent of the system environment. Use an activity in the resources (geogebra tube) for this purpose

Use GGB 6 instead of GGB 5

Optional but advantageous: Use GGB scripts instead of Java scripts

With the above documents create an new topic as "Problem" in this Forum

photo
1

This problem is not really a bug. I was blinded by the \r. The solution is given in this post.

I join a less ugly working code.

photo
© 2021 International GeoGebra Institute