How to get a "number" as a "number of certain type of objects"

Lukas Vizek shared this question 3 months ago
Answered

Dear all,

There are two figures on my little applet: 'point' and 'line'. When you click on 'point' (or 'line'), you are allowed to construct one point (or line). Then the tool is automatically switch to "move". You have to (can) click on the figure again (i.e. select the tool) to continue. See https://www.geogebra.org/m/ewgmzsu3 and its script.

The problem is this: I'd like to allow the user to construct only, for example 3 points and 2 lines. So I want the figure 'point' disappear if 3 point are constructed (similarly for the figure 'line'). I have this idea: I'd like to create the number named (for ex.) 'p', which is equal to the number of already constructed points. Then the figure 'point' will be visible according to the Condition to Show Object in Advanced setting, I put 'p<4' there.

I don't know how to create the number equal to the number of created points (or lines). I know about 'getObjectNumber()' but I don't know hot to use it in this case. What do I have to write to the script?

I look forward to your help.

Lukas

Comments (5)

photo
1

perhaps listaobjetos in this work can be a help for you

listaobjetos is updated by ggboninit-script

photo
1

Hi mathmagic,

thanks for your note and file. I can help me. However, it is not the answer to my question.

Any other ideas?

Lukas

photo
1

creo que no has entendido mi idea en profundidad en parte porque sé poco inglés

mi idea es que a partir de la lista de todo se pueda saber qué y qué no se ha construido en algún momento y por tanto se puede saber cuáles y cuántos puntos se han construido, incluso si se han usado para hacer un polígono u otro objeto y si se ha seguido un orden deseado en los pasos de una construcción

por ejemplo se puede crear un script que borre cualquier punto creado después de un tercero pero hay que tener en cuenta que por ejemplo la herramienta circle() puede crear puntos y la decisión de si quieres que esos puntos también sean borrados o no es del creador del trabajo y ese eres tú

intenta construir puntos en el adjunto, a ver si eso te da una pista

Files: foro.ggb
photo
2

attached 2 possibilities:

objCount01 a general solution based on the ideas of mathmagic

objCount02 a specific, simple solution (all in JS)

photo
1

Dear rami,

this is very interesting! I'm applying it to my applet. It seems to me it will work!

Best,

Lukas

© 2021 International GeoGebra Institute