2 weeks ago
I am creating an algorithm for graphically adding/subtracting elements of an array (dim_xy[ ][ ]) using hotspots (from the hot_mnu[ ] array).
It seems to me that adding new elements to the dim_xy[ ][ ] array works OK:
😊
But removing elements from the dim_xy[ ][ ] array unfortunately does not work properly because the last removed element of the array is restored:
😕😕😕
I noticed that for removing an element from the dim_xy[ ][ ] array to work, I have to click a hotspot not related to the hotspots hot_mnu[ ] before removing, i.e. remove in two stages:
😎😕
Where is the error? Can someone help?
I am attaching HotspotMenuGsm.zip (Ac27)
Solved! Go to Solution.
2 weeks ago - last edited 2 weeks ago
the GLOB_MODPAR_NAME is the problem
when changing the value it thinks the script runs, but it runs this happens
step 1
step 2-remove point 3
step3 remove another point, i selected new point 4
because another parameter isn't actually modified, the script does not fully run (the parameter operation does not run and inject the values back to the library part parameters, only the temporary used variables are modified), and the ghost points stay.
this problem happens normally with editable hotspots, as you can edit parameters without going to the settings dialog box.
if you edit a variable other than the subtraction node then the script runs correctly (the parameters are injected back to the library part parameters) and the nodes are correctly set after this.
https://gdl.graphisoft.com/gdl-style-guide/script-type-dependent-recommendations
"Even if the user changed the parameter specified in an if GLOB_MODPAR_NAME
condition, the else branch will be evaluated"
this is what happens for the 2d output.
(but the parameter script commands are not evaluated for the instance where the parameter is not the subtraction parameter, so no update to library part parameters)
when you open the settings dialogue box, the parameters part of the script is run and then the ghost points are deleted, so everything appears to have worked.
A classic "Schrödinger's Cat"
the answer is quiet simple and elegant:
you just add a second add/subtract field, that you then evaluate on alternate loops
hot_mnu_1 and hot_mnu_2, so you can do the same without having to have the "Click again" value
and you set a variable toggle to switch between them in 2d, solves the problem of the "GLOB_MODPAR_NAME" not eqaul to....
...sorry, i was working on the original library part.
you could also just do a VALUES "hot_mnu" range[-total_count,100] so you could add up to 100 new objects
2 weeks ago
@AllanP, thanks for giving me hope back, although my language barrier and lack of experience with gdl make it difficult for me to understand your explanations and achieve my goal...😟
2 weeks ago
Do not worry, gaba. It is hard for me too to understand what experts suggest.
Anyway I got a good hint from AllanP:
"you just add a second add/subtract field, that you then evaluate on alternate loops"
I'm not sure if I understood it right but...
The idea is use two parameters ("add_remove" and "_add_remove" ) for producing new points and switch between them by "valve" parameter.
It works like 4 stroke combustion engine. When the "add_remove" parameter is working then the parameter "_add_remove" is resetting. Valve controls which parameter is in use.
So every time You have a clean parameter array to mark the edited point.
There must be a restriction for loops, we need to run this only once. Therefore next lines are added:
2 weeks ago
@AllanP and Pertti Paasky, Thank you very much for digging into the topic! 😉
quickly: before I just added hot_mnu2 and in the 2d script I drag hot_mnu and hot_mnu2 (and the user doesn't see the difference etc.), and in the code I compare the changes of hot_mnu with hot_mnu2... And something already works OK for me when adding new dim_xy elements.
I will soon decipher the removal of dim_xy elements, but ... Pertti Paasky, you anticipated my efforts ! I will soon test HotspotMenu_2!
I once practiced this mechanism of comparing the new and previous values in other library objects, but in a two-column table as abs(hot_mnu[1][1]-hot_mnu[1][2])>.001 and it worked for me in the object parameters window.
Hmmmm, instead of struggling with how to show dynamically created elements in the UI (prism etc..) 😬, it would be better to simply provide the user with basic functions in the project in the 2D/3D window (change material etc.) in the cursor context menu.
After all, hotspots could have some extra BIT (e.g. +2048, 4096... ) that would allow you to easily connect the cursor context menu with the VALUES{2,3,4...} options to the hotspot. Then there would be no need to drag the cursor to select the value 1,2,3...
2 weeks ago
Try VALUES{2}
You can connect text type array to integer array.
2 weeks ago
that's what I'll do eventually, and for now I have to switch my old way of understanding gdl to a new one after seeing e.g.:
n = APPLICATION_QUERY ("parameter_script", "firstoccasion_in_progress", isFirstRun)
if isFirstRun then...
"A man learns his whole life and still dies stupid..."
2 weeks ago - last edited 2 weeks ago
What a twist! 😃
@Pertti Paasky, I've slimmed down your code and I think it works OK.
1. I've integrated repeatable operations (when using "add_remove" or "_add_remove").
2. At the end I've added reset/update of the "add_remove" a nd "_add_remove" arrays when they're no longer used.
😊😉😄
Now I'll get down to connecting INTEGER Values{2}...
a week ago - last edited a week ago
planned goal achieved ! 😃
1 - identification of a dragged hotspot
2 - sample menu of VALUES{2} options connected to the hotspots
(and I also switched the hotmenu tables REAL>INTEGER and changed the names of variables according to my own concept; while dragging hotspots you just have to be careful to "hit" the INTEGER values 1,2,3,-1,-5 etc, because this algorithm is more focused on using the hotmenu than regular dragging)
Thank you very much AllanP and Pertti Paasky for your interest in the subject and substantive help 😃
😃😃😃😃😃😃
────────────────────────
Edit:
for the sake of order and to finish the topic I am attaching the source object developed by Pertti in which it is easy to add new hotspots (drag to the right) and remove hotspots (drag to the left); this object operates with add_remove[] and _add_remove[] arrays and REAL values.
────────────────────────
Edit 2:
In order not to forget the whole idea of the hotspot menu (because I have to leave this fun for later and focus on architecture), I prepared a template for practical use of the hotspot menu, so that it works like LEGO blocks.
This is an example of a library object with two groups of figures - circles and rectangles.
Both groups use their own data tables without any restrictions on the number of figures in the group.
Both groups can use a common universal subroutine (GOSUB "HotSpotMenu") to share the hotspot menu.
The CIRCLES group allows you to perform basic operations using the hotspot menu: moving/adding/removing circles.
The RECTANGLES group is more advanced, it also allows you to copy/paste using the hotspot menu: sizes/pen/rotation.
Of course, there can be more similar groups of "2D/3D figures" with specific properties that can be quickly controlled via the Hotspot menu (without opening the object settings window and wondering which figure I want to grab e.g. dimensions from and paste to another figure). Each group works with several parameters/variables, e.g.:
dim_rect_geom[][] — geometry (position, size of rectangle)
hot_rect_mnu[] — hotspot menu (VALUES{2}...)
hot_rect_mnu2[] — hotspot twin menu (VALUES{2}...)
hot_rect_mnu_id — INT returned number of the clicked hotspot
hot_rect_mnu_val — INT returned code (from VALUE{2}...) of the clicked hotspot
hot_rect_mnu_switch — menu switch 0/1 ..._mnu/..._mnu2
And rectangle properties:
hot_rect_rot[] — orientation angles of individual rectangles
hot_rect_pen[] — pens of individual rectangles
hot_rect_...[] — other rectangle properties
etc.
Of course, this is an object prototype and I understand that I ultimately need a GUI. But in this example I wanted to move some of the editing to where the "figures" are most visible (and accessible) - directly in the project. This is important, especially when there are more than a few "figures" in the library object.
By the way, I fixed some minor bugs in the previous objects (HotspotMenu_Pertti.gsm, HotspotMenu.gsm).