How can I speed up a timer that spawns an actor?
I have a timer in the instance of two actors (a wall on each side of the screen, they are instances because they spawn the same actor in "opposite" directions). Every second each one spawns an actor that moves across the screen to the adjacent wall. I would like to speed up the timer every time the player earns a point. I have tried making a real attribute and changing it to a smaller number every time the player scores a point, but nothing happens (the timer appears to remain the same). Am I missing something? Why cant I make a smaller and smaller attribute and use it as my timer? (any help greatly appreciated)
Best Answer
-
Socks London, UK.Posts: 12,822
You could also do it like this:
Make a real game attribute ('X') set it to 1.
. . . . . .
Timer: After X seconds
--Spawn Actor (whatever the actor is you want to spawn)
--Destroy
--Spawn Actor: the Spawner Actor. . . . . .
Rule: When the player scores a point
--Change X to X-0.2. . . . . .
Answers
What's your timer attribute? Real?
If your score attribute is an int, so you have this problem.
dapion.de
[https://twitter.com/dapionde?]
I"m not sure why that doesn't work but you could use a workaround.
Create a local attribute as an integer. Call it "timerInt" and set it to 0.
Create a local attri as a real number and call it "time".
Creat a local attribute as a real number and call it "timeDiv".
You will change "time" to change how long the timer is.
Make sure that whatever you set to "time", that it is divisible by "timeDiv". You can't change timeDiv during runtime so plan what numbers you will change "time"
This means that if I want "self.time" to start out as being every .5 seconds, then every 1 second, then every 1.5 seconds, i would have to set "self.timeDiv" to .5, because each value of "self.time" is divisible by that.
Okay, now this is what the timer will look like.
timer: Every (self.timeDiv) seconds (check the run to completion checkbox)
........change attribute (self.timeInt) to (self.timeInt + 1)
........ rule: IF attribute (self.timeInt) = (self.time/self.timeDiv):{
................(timer statements go here).
................change attribute (self.timeInt) to (0);
By doing it like this you should be able to change "self.time" to be whatever value you want whenever you want (as long "self.time" is divisible by the "self.timeDiv") and that rule will trigger then.
Did that make any sense? It's hard to type the programming out.
I have a question tho, how would the Spawner actor spawn another one of itself after it's been destroyed? Would it work?
sorry, just checked, works beautifully. If you're okay with resetting the self attributes I would go with socks solutions.
It is not destroyed until the next 'cycle'.
Of course !
Check out "Spawn Time Changer" here:
http://armelline.com/snippets.html
Nice simple, effective way of doing it.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
Thank you all so much for the support. Greatly appreciated. I will let you know if I have any other problems
triangularitygames.com
This is basically what I did. And the timer never seemed to go faster.
triangularitygames.com
I am going to guess that your 'X' attribute is an integer rather than a real attribute ?
nope. x was real and equal to 1. I put into the timer and then it never even spawned anything.
triangularitygames.com
So how are you able to tell that the timer didn't increase in speed ?
Could you upload a quick screenshot of your rule ?
well...i cant even get that far because now the spawner doesnt even spawn the actor every second.
triangularitygames.com
Can you upload a screenshot of this rule ?
im kinda new to this...so i dont know how
triangularitygames.com
in the instance of a wall it says timer every 1 second (not even an attribute) spawn actor (actor) in direction 0 relative to actor at position -15, random(125, 425) relative to scene...this worked before and then i started changing things and now it doesnt work anymore
triangularitygames.com
I thought you were referring to the code I suggested above ? The code you mention here is nothing like that ! Try the code I posted above, it works just fine.
P.S . . . -15 / relative to scene places your spawned actor 15 pixels off the lefthand side of the screen.
yeah i know its supposed to fly from off screen through the scene to the other side and when it hits the wall on the adjacent side, its destroys itself
triangularitygames.com
Oh, I see, yes that makes sense then.
what im confused about, is i reverted everything back to what it was (it was kinda working but not perfectly) and now it doesnt even work, so idk if im missing something or if i changed something and forgot about it
triangularitygames.com
so i got it back to what it was, but with your method the timer doesnt speed up
triangularitygames.com
the attribute "X" gets smaller, but the timer doesnt speed up (meaning x doesnt update in the time)
triangularitygames.com
Each time the player scores a point the attribute X is reduced by 0.2 - so the timer will speed up by a fifth of a second each time.
The length of time is defined by X, so if X gets smaller, then the timer's interval gets smaller (i.e. it speeds up).
Honestly it works fine ! I've used this method dozens of times, it works perfectly, you've probably made a small error somewhere in your application of it (which is why it'd be useful to see a screenshot of your rule, just to double check).
how can i send you a screenshot?
triangularitygames.com
I GOT IT!!!! OMG THANK YOU SO MUCH!!! THIS HAS BEEN BUGGING ME ALL DAY. I have it working on one side, but i need it to spawn in the opposite direction on the other side, but you cant spawn an instance from and instance, so the prototype only allows for the spawning in one direction
triangularitygames.com
The easier way would be to . . .
1) First grab a screenshot of the rule you are having an issue with (I'm not on a PC, I'm on a Mac, but I think it's alt+Print Screen on a PC?)
2) Then go to any image hosting site like http://postimage.org - upload the image there, it will produce a URL for you
3) Post the URL here
You can spawn anywhere on the screen (or even off the screen) with a spawner, there shouldn't be any limitations in this respect.
i don't think i need to thanks. I'm just going to make 2 separate actors for each direction. You have been the greatest help, and I thank you so much for your time and patience.
triangularitygames.com
its not where i need to spawn them, but the direction i need them to face when they spawn (so they move in opposite directions) kinda hard to explain sorry
triangularitygames.com
stephenriska123 said: in the instance of a wall it says timer every 1 second (not even an attribute) spawn actor (actor) in direction 0 relative to actor at position -15, random(125, 425) relative to scene...this worked before and then i started changing things and now it doesnt work anymore