PDA

View Full Version : Why doesn't Math.random() work when animation starts again?



Yonetici
27th July 2012, 20:20
Hi guys,

I have an animation. When you press the button, animation starts and when some conditions are ok, it stops.

When you press again to the button, animation starts again but here is the problem: normally, in animation, there is a Math.floor(Math.random()) function. for first click to button, it works perfect. but then, when you press again the button, it doesn't work. Instead, it gets the previous value.

How can I generate new value when I click the button?

Note: I try to add a property int n: Math.floor(Math.random()*1500+600) as a condition when I press the button, and I think that when I press the button, it should change the value, but it doesn't work too.

I'm using QT Quick, any idea?

wysota
27th July 2012, 20:24
I'm using QT Quick, any idea?
Why are you posting in a wrong forum then?


As for your question -- QtQuick engine doesn't know that Math.random() returns a different result every time you call it and therefore it doesn't reevaluate the expression you are using because it would have to do that constantly over and over again. "n" is evaluated once and never again unless you bind a different expression to it.

Yonetici
27th July 2012, 20:52
Why are you posting in a wrong forum then?


As for your question -- QtQuick engine doesn't know that Math.random() returns a different result every time you call it and therefore it doesn't reevaluate the expression you are using because it would have to do that constantly over and over again. "n" is evaluated once and never again unless you bind a different expression to it.

sorry about wrong forum, I read some topics and I didn't realise it