We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2022-03-10 12:29 PM
Hello,
I am creating a 2D "person" object and I would like the clothes to be randomised using an array. I currently have it working as such:
top_random = rnd(vardim1(top_colour))
pen top_colour[top_random]
The user is able to edit the current values of the array (to set the pens they want to randomise from) but I was wondering if there is any way that the user is able to add / remove lines of the array to reduce or increase potential pens as it is currently greyed out?
Many thanks
Solved! Go to Solution.
2022-03-11 01:38 PM - edited 2022-03-11 01:38 PM
Deleting rows is similar, but you'll need another temp structure.
Following your style:
dim EMPTYARRAY[]
!...
if GLOB_MODPAR_NAME = "del_top" then
if del_top then
dim temp[]
for i=1 to vardim1(top_colour)-1
temp[i] = top_color[i]
next i
! reset the array first
top_colour = EMPTYARRAY
top_colour = temp
del_top = 0
parameters \
del_top = del_top,
top_colour = top_colour
endif
endif
2022-03-10 03:14 PM
Yes, that is possible.
But you need an UI, tho. You are right, the user can't change the dimension of the array later on. Teh reason behind this is that the programmer needs to be in control of their data structure – everything else would invoke hazard sooner or later for sure.
If you have an UI you could script the adding and deleting. E.g. the old room stamp had something you could reuse (at least the german one had this feature):
You have to tie a function to the buttons basically.
Or, a completely different way I implemented in some of my objects, is to actually parse a string and populate the array afterwards.
The input could look like this "1,44, 6-17, 25, 3". A bit like printing pages from a PDF.
I also tried something totally ridiculous: Overlaying an ui_infield (to have the accurat color represenation) by an ui_pict_pushcheckbutton.... but that does not really work.
2022-03-11 12:00 PM
Thanks for your help. I added in a way to add rows to the array using a boolean and it seems to work well. I was wondering if you knew of a way to then reduce the rows using a similar method. I had a look in the Zone Stamp as that has a way of adding and removing but I found it rather confusing to follow!
if (glob_modpar_name = "add_top") then
if (add_top) then
num_top = vardim1(top_colour) + 1
top_colour[num_top] = 1
add_top = 0
parameters add_top=add_top
parameters top_colour=top_colour
endif
endif
2022-03-11 01:38 PM - edited 2022-03-11 01:38 PM
Deleting rows is similar, but you'll need another temp structure.
Following your style:
dim EMPTYARRAY[]
!...
if GLOB_MODPAR_NAME = "del_top" then
if del_top then
dim temp[]
for i=1 to vardim1(top_colour)-1
temp[i] = top_color[i]
next i
! reset the array first
top_colour = EMPTYARRAY
top_colour = temp
del_top = 0
parameters \
del_top = del_top,
top_colour = top_colour
endif
endif
2022-03-11 01:58 PM
You're a genius! Thank you so much for your help, that is working perfectly now.