Timer Question

dank1028dank1028 Member Posts: 5
edited November -1 in Tech Support
Hey guys. Quick timer question...

I'm tying to make a simple timer to count down once a random number has been stored into it. I have other timers in an offscreen actor that working fine, but this one doesn't.

Basically I've set up an integer Attribute named random and I'm doing this in the actor located on the background:

If Attribute random = 0
Change Attribute to random (100,200)
otherwise
Constrain Attribute random = random-1

When I print the Attribute "random", it looks like it initializes to a random number properly, but the Rule never gets to the "otherwise" line.

Is this a problem with the new version? Can I init an Attribute and modify it in the same actor?

Comments

  • dank1028dank1028 Member Posts: 5
    Thanks tshirtbooth.

    I tried that, and it counts down from a random number to 0 only once. The Attribute game.random never gets set to the random (100,200) except for the first time the program runs. I've experimented a few different ways with this and still the same result. Thoughts?
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Well i've messed with this a couple different ways too. TSB way should work perfect. I've even tried moving some of the rules around to otherwise positions. I'm not sure why its not working. when it reaches 0 it should re-trigger the random.
  • dank1028dank1028 Member Posts: 5
    Agreed. I've even tried using constrain attribute when subtracting 1 from game.random. Still no go. It makes no sense. Is it a 0.9.1 update issue possibly?
  • dank1028dank1028 Member Posts: 5
    Thanks tenrdrmer.

    I played with it further and did get it working. For some reason this doesn't work:

    If Attribute game.random = 0
    Change Attribute game.random to random(100,200)
    If Attribute game.random > 0
    Constrain Attribute game.random to game.random-1

    Using the Timer isn't an issue. Apparently when the program runs the first time, game.random does get set to a random number. It counts down fine and reaches 0, but never gets reset to a new random number. Also, putting the "Constrain Attribute game.random to game.random-1" into the first OTHERWISE "if" test definitely doesn't work either, although I would think both methods should work. What does work is this:

    If Attribute game.random = 0
    Change Attribute game.random to random(100,200)

    If Attribute game.random > 1
    Constrain Attribute game.random to game.random-1
    Otherwise
    Change Attribute game.random to random(100,200)

    The code sets the random number the first time correctly if random = 0 when the program first is executed. After that it only works if game.random uses another trigger value (other then 0) to reset it to a new random number. Strange. Also, you can't move the "If Attribute game.random > 1" test into the Otherwise of the first "If" statement. They have to be executed separately to work. It looks like it's something about game.random being used as a trigger when 0 after the first time the GS interpreter clears it to 0 on a cold start.

    Hope this helps anyone else trying to set a variable to a random number over and over.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Glas you got it working but it seems crap that you cant trigger using 0 you should prob submit a bug report on that one.
Sign In or Register to comment.