How can I speed up a timer that spawns an actor?

Triangularity GamesTriangularity Games Founder/OwnerMarylandMember Posts: 140
edited July 2015 in Working with GS (PC)

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) :smile:

Best Answer

  • SocksSocks London, UK.Posts: 12,822
    edited July 2015 Accepted Answer

    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

    . . . . . .

«1

Answers

  • dapiondapion Member, PRO Posts: 353

    What's your timer attribute? Real?
    If your score attribute is an int, so you have this problem.

  • muoch10muoch10 Member Posts: 112

    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.

  • muoch10muoch10 Member Posts: 112
    edited July 2015

    @Socks said:
    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

    . . . . . .

    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.

  • SocksSocks London, UK.Member Posts: 12,822

    @muoch10 said:
    I have a question tho, how would the Spawner actor spawn another one of itself after it's been destroyed?

    It is not destroyed until the next 'cycle'.

    @muoch10 said:
    Would it work?

    Of course !

  • ArmellineArmelline Member, PRO Posts: 5,366

    Check out "Spawn Time Changer" here:

    http://armelline.com/snippets.html

    Nice simple, effective way of doing it.

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    Thank you all so much for the support. Greatly appreciated. I will let you know if I have any other problems :blush:

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Socks said:
    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

    . . . . . .

    This is basically what I did. And the timer never seemed to go faster.

  • SocksSocks London, UK.Member Posts: 12,822

    @stephenriska123 said:
    This is basically what I did. And the timer never seemed to go faster.

    I am going to guess that your 'X' attribute is an integer rather than a real attribute ?

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Socks said:
    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.

  • SocksSocks London, UK.Member Posts: 12,822
    edited July 2015

    @stephenriska123 said:
    nope. x was real and equal to 1. I put into the timer and then it never even spawned anything.

    So how are you able to tell that the timer didn't increase in speed ?

    Could you upload a quick screenshot of your rule ?

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Socks said:
    So how are you able to tell that the timer didn't increase in speed ?

    well...i cant even get that far because now the spawner doesnt even spawn the actor every second.

  • SocksSocks London, UK.Member Posts: 12,822

    @stephenriska123 said:
    well...i cant even get that far because now the spawner doesnt even spawn the actor every second.

    Can you upload a screenshot of this rule ?

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    im kinda new to this...so i dont know how :/

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    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

  • SocksSocks London, UK.Member Posts: 12,822
    edited July 2015

    @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

    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. :smile:

    P.S . . . -15 / relative to scene places your spawned actor 15 pixels off the lefthand side of the screen.

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Socks said:

    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

  • SocksSocks London, UK.Member Posts: 12,822

    @stephenriska123 said:
    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

    Oh, I see, yes that makes sense then.

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Socks said:
    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 :/

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Socks said:
    Oh, I see, yes that makes sense then.

    so i got it back to what it was, but with your method the timer doesnt speed up

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Socks said:
    Oh, I see, yes that makes sense then.

    the attribute "X" gets smaller, but the timer doesnt speed up (meaning x doesnt update in the time)

  • SocksSocks London, UK.Member Posts: 12,822

    @stephenriska123 said:
    so i got it back to what it was, but with your method the timer doesnt speed up

    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.

  • SocksSocks London, UK.Member Posts: 12,822
    edited July 2015

    @stephenriska123 said:
    the attribute "X" gets smaller, but the timer doesnt speed up (meaning x doesnt update in the 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).

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Socks said:
    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?

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Socks said:
    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).

    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

  • SocksSocks London, UK.Member Posts: 12,822

    @stephenriska123 said:
    how can i send you a screenshot?

    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

  • SocksSocks London, UK.Member Posts: 12,822

    @stephenriska123 said:
    . . . . so the prototype only allows for the spawning in one direction

    You can spawn anywhere on the screen (or even off the screen) with a spawner, there shouldn't be any limitations in this respect.

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Socks said:
    3) Post the URL here

    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. :)

  • Triangularity GamesTriangularity Games Founder/Owner MarylandMember Posts: 140

    @Socks said:
    You can spawn anywhere on the screen (or even off the screen) with a spawner, there shouldn't be any limitations in this respect.

    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

  • SocksSocks London, UK.Member Posts: 12,822
    edited July 2015

    @stephenriska123 said:
    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

    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

Sign In or Register to comment.