[Q] Setting DC attributes randomly from ruby script
-
I'm trying to randomly within a range set attributes but don't know how to get it to work.
The attributes A and B should randomly set a value from a dropdown list of strings like a1, a2... b1, b2... in the DC.
The attibute CWidth should be set randomly between a min and max value. Integers will do fine.cinst.set_attribute("dynamic_attributes", "A", "a1") #rand(1..11) cinst.set_attribute("dynamic_attributes", "B", "b1") #rand(1..5) cinst.set_attribute("dynamic_attributes", "CWidth", rand(300..500))
-
I've tried with this but it doesn't seem to work either. I'm not getting any errors in the console though.
Right after this I redraw the DC but it still has the default attributes set.
Any ideas what to do?a_array = ["a1", "a2", "a3", "a4", "a5"] b_array = ["b1", "b2", "b3", "b4", "b5"] a_rand = a_array.sample b_rand = b_array.sample cinst.set_attribute("dynamic_attributes", "A", a_rand) cinst.set_attribute("dynamic_attributes", "B", b_rand) cinst.set_attribute("dynamic_attributes", "C", rand(300..500)) #Redraw to update the DC dcs = $dc_observers.get_latest_class dcs.redraw_with_undo(cinst)
-
For anyone interested I managed to solve it by myself.
I had to set the attributes on the definition and transverse down one step like this:cdef.entities.first.set_attribute("dynamic_attributes", "A", a_rand)
Advertisement