3 weeks ago
Hi,
I am working on an object where I have values in an array parameter, and they are represented in 2D as points on a line. You can move them by hotspots, and if you move one over the other, the parameter script finds the duplicate values, and deletes one of them from the array.
This works mostly fine, except if i try to remove the last node (last item of the array) it doesn't get removed, it just sets itself to "0", and I have no idea why. It seems like a fairly simple setup, but I still cannot see what I am doing wrong.
Can someone tell me what am I missing?
! ----------
! 2D script:
! ----------
unID = 1
hotspot2 0, 0, unID : unID = unID + 1
for i = 1 to vardim1(dimArray) step 1
hotspot2 0, 0, unID, dimArray[i], 1 + 128 : unID = unID + 1
hotspot2 dimArray[i], 0, unID, dimArray[i], 2 : unID = unID + 1
hotspot2 -1, 0, unID, dimArray[i], 3 : unID = unID + 1
next i
line2 dimArray[1], -0.5, dimArray[1], 0.5
for i = 2 to vardim1(dimArray) step 1
line2 dimArray[i-1], 0, dimArray[i], 0
line2 dimArray[i], -0.5, dimArray[i], 0.5
next i
! -----------------
! Parameter script:
! -----------------
put dimArray[1]
for i=1 to (vardim1(dimArray) - 1) step 1
if dimArray[i] # dimArray[i+1] then
put dimArray[i+1]
endif
next i
dim _temp[]
for i = 1 to nsp step 1
_temp[i] = get(1)
next i
parameters dimArray = _temp
Thanks!
3 weeks ago - last edited 3 weeks ago
Hi
edit: closer but still not right
in your parameter script i added following line (13)
put dimArray[vardim1(dimArray)]
The corrected version below
@danielk schrieb:
! ---------- ! 2D script: ! ---------- unID = 1 hotspot2 0, 0, unID : unID = unID + 1 for i = 1 to vardim1(dimArray) step 1 hotspot2 0, 0, unID, dimArray[i], 1 + 128 : unID = unID + 1 hotspot2 dimArray[i], 0, unID, dimArray[i], 2 : unID = unID + 1 hotspot2 -1, 0, unID, dimArray[i], 3 : unID = unID + 1 next i line2 dimArray[1], -0.5, dimArray[1], 0.5 for i = 2 to vardim1(dimArray) step 1 line2 dimArray[i-1], 0, dimArray[i], 0 line2 dimArray[i], -0.5, dimArray[i], 0.5 next i ! ----------------- ! Parameter script: ! ----------------- put dimArray[1] for i=1 to (vardim1(dimArray) - 1) step 1 if dimArray[i] # dimArray[i+1] then put dimArray[i+1] endif next i put dimArray[vardim1(dimArray)] dim _temp[] for i = 1 to nsp step 1 _temp[i] = get(1) next i parameters dimArray = _temp
Thanks!
3 weeks ago
Hi,
My code is supposed to go through the array, and put each value into the buffer, except if 2 items are identical, and then in the next step, feed them into a temporary array, then assign the temporary array to the parameter.
So, if I had an array of 1,2,3,4,4, it would first put 1,2,3,4 into the buffer, then create a new array with these values, and assign that array back to the parameter, so it would also be 1,2,3,4.
I think what your addition would do is just grab the 4 from the end, and put it back into the temporary array, so at the end I would end up with 1,2,3,4,4? Or am I misunderstanding something?
Thanks!
3 weeks ago
Another thing is, it works perfectly fine if I just change the value in the Object settings dialog. It only does this, if I use the hotspots to change the value.
3 weeks ago - last edited 3 weeks ago
Is the parameter that your Hotspot modifies the one you are changing in the settings dialog? Or is the modification indirect? (eg. IF Dn < EPS then Hmax = Hmax - 1) Working in the settings dialogue and not with the Hotspots sounds like an inconsistency in the dependancy between two parameters.
Ling.
AC22-28 AUS 3110 | Help Those Help You - Add a Signature |
Self-taught, bend it till it breaks | Creating a Thread |
Win11 | i9 10850K | 64GB | RX6600 | Win11 | R5 2600 | 16GB | GTX1660 |
3 weeks ago
Nope, what you can see in the code above is all there is to it. you can find the sample object attached to the original post.
3 weeks ago - last edited 3 weeks ago
Have you tried to make the array one indice bigger than actually needed? I had a similar problem with an object inspired from https://community.graphisoft.com/t5/GDL/Dynamic-Polyline-base-code-object/m-p/198874 When removing the last point, it was set to zero, if the array's length was exactly the same as the number of points. I have no idea, why this happened though.