[not a bug] IsDefined and deleting object

matheod shared this problem 6 years ago
Answered

    GeoGebra 5.0.143.0-3D (21 August 2015)

    Java: 1.7.0_40


Hello


1) Create a point A

2) Create a variable test = IsDefined[A]

3) Delete A


Expected : test is false

What happend : test variable is deleted


Thanks !

Comments (5)

photo
1

Hi,


If you want to check if a point named "A" exists, you may do the following:


1) Create a point A

2) Create B=Object["A"]

3) Create a variable test = IsDefined[B]

4) Delete A


Cheers,

Mathieu

photo
1

Thanks it's work, but I think the IsDefined function could be improved.


I tested your code, it worked, but if I try to directly write exist = IsDefined[Object["A"]] there is some bug (I assume that's why you tell me to do t=Object["A"] and then to do existe = IsDefined[t]) :


- The code work without problem (it update when I delete or recreate the point A), but if I save the file and reopen it, the exist variable is set to false, even if the point A is still here, also deleting and recreating the point doesn't update the exist variable.


(I can provide a file of the bug if you can't reproduce it)

photo
1

Expected : test is false

What happend : test variable is deleted


That's expected, command is IsDefined[A] not doesExist[A]


What are you trying to do exactly? (I guess you will need to use JavaScript Scripting)

photo
1

I have a button that test if point are correctly placed. But before that, I want to be sure that the user created all points.

photo
1

Hi,


As workaround until IsExist[] is realised:


Copy the code below to Global-JavaScript in your application.

Then Save

Then Reopen


Now exist a new Object with name "ExistPointNames"

Instead IsExist[A] you can ask IndexOf["A", ExistPointNames]>0


The code to copy in Global-JavaScript:

(select any object, rightClick, properties, Script, GlobalJavaScript, delete exist script, copy the following)

    function ggbOnInit() {

    AddDelRen()

    ggbApplet.registerAddListener("AddDelRen")

    ggbApplet.registerRemoveListener("AddDelRen")

    ggbApplet.registerRenameListener("AddDelRen")

    }

    function AddDelRen(){

    swEPN=false

    Pnam= []

    ip=0

    for (i = 0; i < ggbApplet.getObjectNumber(); i++) {

    if (""+ggbApplet.getObjectName(i) == "ExistPointNames") {swEPN= true}

    if (""+ggbApplet.getObjectType(ggbApplet.getObjectName(i)) == "point") {

    Pnam[ip]=""+ggbApplet.getObjectName(i)

    ip=ip+1

    }

    }

    if(! swEPN){ggbApplet.evalCommand('ExistPointNames={}')}

    PnamS=""+Pnam

    PnamStr='{"'+PnamS.replace(/,/g,'","')+'"}'

    ggbApplet.evalCommand('SetValue[ExistPointNames, Sort['+PnamStr+']]')

    }


Raymond

https://ggbm.at/1714585

© 2021 International GeoGebra Institute