[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)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better đź’—
Register LoginAdvertisement