A quick Question
-
Just a quick query.
First i make a custom attribute and put it equal to randbetween(10,20) for example. If i then put lenx/x/whatever equal to this custom attribute it doesnt take the same value as the custom attribute.
My guess is that in putting the attribute equal to the custom attribute its actually taking on the randbetween formula, rather than the value of the custom attribute.
Is their any particular reason for this? it seems like a rather strange way of doing things to me.
p.s. see the file for an example of what i mean.
-
RAND() is a built in function and shouldn't be used as an attribute?
Edit: No, that's not it.
-
I think that every cell gets re-calculated on the redraw() command. That would be multiple re-evaluations of a random number. Here is a breakdown of how I think redraw is working:
Redraw() ---> Simultaneously evaluates the following operations
1st - The actual Length for x ---> Looks to "LenX" ---> Looks at "Rand" and is assigned a random value (ie 15)
2nd - The value for Lenx ---> Gets sent to "Rand" for a random value (ie 27)
3rd - The value for Rnd ---> assigns itself a random value (ie 19)So the length of X actually in the model comes from the first function above. This value is not displayed anyhwhere, just evaluated and applied to the model. The displayed value in "LenX" is from the 2nd operation. The value displayed for "Rand" is worked out in the 3rd operation. So that is how we are seeing three different values where it seems like we should only be seeing one. But it is really the very first evaluation that is being applied to the model.
Is that a possible explanation for what we're seeing? That almost seems like a ReDraw() bug. Seems like that sort of makes it unuseable in certain ways.
Instead of using a redraw() function, use this in the onclick cell:
set("rand",(randbetween(10,30)))
Now on the onclick event, the entire model is not being re-evaluated. Just the random number gets re-evaulated. Then all other cells get updated based on the new random number.
I hope that makes sense. And It might take an explanation from Scott or someone to verify if that is anywhere near correct.
Chris
-
So essentially what you think is happening is rand is being evaluated several times and giving several different values?
Seems to fit the evidence, it'll be interesting to hear what the official line is.
Cheers for the working code btw
-
@remus said:
So essentially what you think is happening is rand is being evaluated several times and giving several different values?
Seems to fit the evidence, it'll be interesting to hear what the official line is.
Remus,
This is exactly what is happening. Whenever a reference to a "randomized" cell is made, the random function is refired. I'm happy to hear opinions on whether this behavior is "right" or not.
-
Personally i dont think it's 'right' as it makes it very hard to make more than one attribute dependant on a random variable.
I.e. if i make the material dependant on something random, i cant make anything dependant on the material as it gets re-evaluated and so isnt random.
-
You can randomize another attribute, then have everything refer to that value. Then they won't all be calling the random function each time. But you will have the attribute with the random function and the attribute holding your randomized value displaying different values, which is confusing.
Chris
EDIT: For people reading this in the future, this is not true. At least not at this point. Hopefully DC's will get this randomize kink worked out. But for now, this is bad information, as Remus points out below.
-
That doesnt always work chris, especially if you start using the redraw function.
Nice avatar by the way, ive never noticed it before
-
Hey, I missed your response here Remus, sorry about that. I only looked this thread up because I am seeing some unsurmountable issues with the way that random is setup.
The solution I posted above only works when you are using the OnClick. So for all the rest of the times that you don't want to use onclick, you are stuck not being able to get a random value and send it to multiple attributes.
Hey Scott, where are you? This probably is not the right behavior. What are the alternatives?
I think my thought is that a cell that contains a random should only be evaluated once until a refresh, or on a copy being created (so copies can have thier own random properties). On a refresh, the "random" should be re-evaluated and assign the value to the cell somehow. That value should then be the only thing passed on to other attributes that call back to it. It should not be re-evaluated. I think that makes sense and explains what I am expecting to happen.
Chris
Thanks on the avatar. I painted it at Crissy Field which is a park at the base of the Golden Gate Bridge.
-
I think my problem is related to this discussion.
I have three children items and I would like only one to be shown at a time. I thought I could do this:
Parent
randthing=randbetween(1,3)Child1
hidden=if(parent!randthing=1,0,1)
Child2
hidden=if(parent!randthing=2,0,1)
Child3
hidden=if(parent!randthing=3,0,1)But it looks as if each child refires its own value for randthing, making the hidden value not mutually exclusive as I would like.
I could have sworn that I successfully did this before. Not sure if there was a hack or not, but if anyone has any ideas it would be appreciated.
I am getting some crazy ideas to concatenate a string and the random value and then stripping out the value once again... just to keep it from changing.
FRUSTRATION EDIT
I thought I could outsmart the problem by doing this:
Parent
randthing=randbetween(1,3)
randhack="x"&randthingChild1
hidden=if(parent!randthing="x1",0,1)
Child2
hidden=if(parent!randthing="x2",0,1)
Child3
hidden=if(parent!randthing="x3",0,1)But that failed too. It looks like the randbetween() function gets re-fired no matter how far back or indirectly it is linked. Cripes.
-
@matthew.robert said:
It looks like the randbetween() function gets re-fired no matter how far back or indirectly it is linked. Cripes.
That is correct. Even if you link and link and link back to it, it still refires each time its refered to. There is no way to make the value stick, unfortunately.
Though, I think it is still possible to do what you want to do. I'll see if I can find an example that randomly shooses which component to show when they are generated.
Chris
-
Aha, I found the example I was thinking of. This is from PITRAK on the PushpullbarII forum in this thread:
http://www.pushpullbar.com/forums/sketchup/10076-dynamic-components-test.html
See if that one helps. I don't remember what id does differently or how it works, but it randonly chooses between 3 different options.
Chris
Advertisement