Button Command (ggb script or JS script) for action on selected objects)

lewws shared this question 2 years ago
Answered

Hi,

Need help with this.

See https://www.geogebra.org/m/wzg2ryp7


I want student to mouse select a disc (object is a circle). Then click on button(s)

(a) delete the selected disc (1, -1, x, -x discs)

(b) replace with another disc of opposite sign .

Can't find solution to implement using Geogebra script.

2nd problem : I have generated new discs using counters for each type of discs

d1n, dneg1n, dxn,, dnegxn numerical variables to generate unique discs for (1, -1, x, and -x)

But after deletion the acccumulated values of d1n, dneg1n, dxn,, dnegxn are not reduced.

Can possible help me solve how to delete the unwanted numbers?

Use lists for d1n, dneg1n, dxn,, dnegxn?


Thanks in advance.

lewws

Comments (15)

photo
1

Questions about the understanding:

1) When 1 disc is created, 1 disc is always erased. Correct?

2) If 1) = Correct: then the number of discs always remains == 4

and only the sign in the caption changes. Correct?

2b) Then why does it need a sequence number as a suffix to the disc?

3) If 1) not correct: The number of discs increases, a sequence number is required as suffix. Correct?

4) If 3) = Correct: should it be possible to delete discs by the user?

5) If 3) = Correct: where should the new (additional) discs be placed?

6) If the sign changes then the color changes as well. Correct?

7) Is a solution possible where the disc is clicked instead of the buttons?

8) The 4 pictures are created with the definition of the buttons, otherwise they are not needed. Correct?

photo
1

Dear rami,

Thank you for looking into my request. To answer your queries :

Some of your queries have been addressed with the newer version.

Same online location at https://www.geogebra.org/m/wzg2ryp7


1) No. If I need to create one dics, the existing should not be deleted (Found error in script, corrected)

2) 1) after amendment, the number of discs can be any number (space limitation) including no disc (if reset)

captions should not change for each type of disc

2b) Needed every disc to be uniquely named, so that it can be new free object. Suffix for each type of disc is

now improved to prevent previous error of sudden change due to wrong naming of variable name.

3) Number of discs increases, new sequence number is required as suffix.

4) Discs can now be deleted or added (naming with suffix hidden from user, however deletion does not change

the "counters" d1n, dneg1n, dxn, dnegxn until RESET ALL is clicked

5) In my online amended file I have placed the discs so that they don't overlap exactly on the same position

(download to see the geogebra code I used in the "disc" buttons)

6) "+" discs are to be blue and "-" discs are to be red

7) As discs are dynamically created by clicking the disc buttons, it is at the moment impossible to generate

code script inside the disc objects.

8) Yes the four pictures were there, to show what happens when each button was clicked.

They should have been erased before uploading.


Need your help to suggest an approach how we can "flip" a single disc or a few discs which are clicked and selected. Use buttons?

A flip means that if the original disc has unit 1 (and blue) , the disc when flipped must become negative 1 unit and red in colour.


Best regards,

lewws

photo
photo
1

Is it possible that the properties of a selected disc can be changed by clicking on it , but with the script not written inside of the object's "OnClick" properties?

This is the main difficulty with the activity I am working on above.


lewws

photo
1

I intend to realize the following technical Interface functionalities:

Clicking on a disc changes its color to green. Additionally a dropdown list with the 4 possible values appears. The selection in the dropdown list is embedded in the (green) disc in the latex string. Then the color of disc is set depending on sign and the drop down list disappears. If possible: all other actions are disabled as long as the drop down list is visible.

If possible: alternative to the drop down list: the 4 buttons for creating a new disc: temporarily get the functionality of update green disc.

For this I have coded an (simple, incomplete) feasibility study (see Attachment)

Note: it is intended to use the onClick listener so that no scripts have to be generated in the (generated) objects. And if possible, all external properties (Atxt, Acol, etc) should be in a list or in the spreadsheet (together with Apnt and Adsc).

photo
photo
1

I think I have understood the task (as follows)

  1. It should be possible to create as many discs as a user like, each one is one of 4 types (4 buttons). Each new disc is always created at the same position.
  2. The discs should be movable with mouse. (with grid/point list ?)
  3. Two disks can't occupy the same position(?), except "create position"
  4. The type of a certain disc should be changeable (1 ev 2 possibilities [flip sgn, flip value])
  5. The type includes one of 4 texts {x, -x, 1, -1} as disc label
  6. The color of the disc depends on the text content: Red if with "-" otherwise blue
  7. It should be possible to erase a specific disc
  8. It should be possible to erase all discs (button)
  9. The number of existing discs can be 0
  10. If 2) with point list: Limit the number of discs to the number of points in the list.

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

If necessary, please make corrections and/or deletions/additions to the above text.

Point 4 is the one with your most interest

I am absent today (20.12.03) I will probably have a solution tomorrow.

photo
1

Yes all your points essentially my design intent.

Point 4 is hard for me to achieve due to objects being created on the fly.

Unless design is based on hard coding, allowing pre built discs (50 each, all with scripting in their OnClick tab).


Thanks for following me on this.

photo
1

See flipping disk using javascript at https://www.geogebra.org/m/wv3muayy


If objects can be free copied together with their Onclick properties, it would solve what I need.

photo
1

The problem with this solution: Each disc must become a generated script. This is possible only via XML and expensive.

photo
1

Yes, very labour intensive and time consuming.

photo
photo
1

My solution in the attachment.

Not so nice for you because all is new. But I think it is the only reasonable way.

The basic difference: The properties are own objects. That means: you can query and change them and they can have mutual dependencies to all other objects (!). This makes it possible to get along without scripts in generated objects, which seems to me to be the most important point.

I used JS as less as possible. The generated objects have no scripts. But the listeners Remove and Click exist. The index is the same for all disc types.

photo
1

Hi rami,

I think your solution is more workable.

I will use your approach, maybe not green buttons :)

Many thanks.

photo
1

green was the simplest RGB code :smile:

For example, it would be possible to gray out the unselected discs.

Change in scrCre_5-> ....If(modusUpdate && %1 != clickedObjNdx , {0, 0, 0,0.1},.....

And by the way: The flip button with the GGB script would be more readable , if it were written in JS (no problem with ' and ")

photo
1

Aha! Many thanks again.

photo
1

See attachment buttonUpdFlipSgn & buttonUpdFlipVal

photo
1

Hi rami,

Now implemented your methods, with some decoration and modification at

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


But many thanks for your main ideas and methods which make it work!

photo
© 2023 International GeoGebra Institute