Results 1 to 3 of 3

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

  1. #1
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    3
    Platforms
    Windows

    Default Why doesn't Math.random() work when animation starts again?

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why doesn't Math.random() work when animation starts again?

    Quote Originally Posted by Yonetici View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2012
    Posts
    26
    Thanks
    3
    Platforms
    Windows

    Default Re: Why doesn't Math.random() work when animation starts again?

    Quote Originally Posted by wysota View Post
    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

Similar Threads

  1. QStateMachine doesn't starts :(
    By nudels in forum Qt Programming
    Replies: 1
    Last Post: 24th January 2012, 01:16
  2. Replies: 1
    Last Post: 7th April 2010, 17:26
  3. QProgressBar starts at random position
    By kodiak in forum Qt Programming
    Replies: 0
    Last Post: 8th September 2008, 11:59
  4. setWindowModality doesn't work
    By dude in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2008, 15:11
  5. setWindowOpacity doesn't work!
    By nupul in forum Qt Programming
    Replies: 5
    Last Post: 21st April 2006, 19:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.