Timer Question
dank1028
Member Posts: 5
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?
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
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?
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.