Trouble with timers and self.time/game.time

JH4musicJH4music Member, PRO Posts: 23

I have a scene with tiles that move left/right when you swipe. This works perfectly, but I would like to limit the swiping to only be possible every 1 second. The reason for this: there is an actor that fades in over the course of 1 second every time a new tile slides into the camera view... If you swipe too fast the actor gets "stuck" in it's on state when you swipe to the next tile. The swiping is controlled by an actor that is separate from the tiles, and keeps track of the current swipe position. As soon as I try to use self.time or game.time in the swipe actor, the game locks up and won't run. Are these features broken? I'm doing something like this:
When self.time > self.Last Swipe +1, allow the swipe behaviors to occur.
Change attribute self.Last Swipe to self.time

I also tried using a timer, where it works like this:
When self.ok_to_swipe = 0, allow the swipe behaviors to occur.
At the end of this, I put the following:
change attribute self.ok_to_swipe to 1
Timer: after 1 second, change attribute self.ok_to_swipe to 0

I also tried a variant of the timer like this:
When self.ok_to_swipe = 0, allow the swipe behaviors to occur.
Timer: for 1 second, change attribute self.ok_to_swipe to 1

As soon as I put any kind of timer or reference to self.time in this actor, the game gets stuck when I try to do anything related to the part that allows swiping.

Is there something I am missing? This seems like it should be pretty straight forward.

Comments

  • NNterprisesNNterprises Member, PRO Posts: 387
    edited May 2016

    I always do things like this using a game boolean attribute.

    For example, when boolean is FALSE you can only swipe and spawn. When you swipe or whatever it will spawn AND turn boolean to true, therefore you cannot spawn anything again.

    Then use a timer or something to say After 1 second turn boolean to false again... good luck

    EDIT: Yea I read over your things you did and that's pretty much what I'm saying besides I use booleans... I had issues before with using numbers instead but booleans have been fine. Put a DISPLAY TEXT in the middle of your screen to test/see what your attribute is doing during the game to see if it is working and resetting properly

  • ka822ka822 Member, PRO Posts: 40

    When self.ok_to_swipe = 0, allow the swipe behaviors to occur.
    At the end of this, I put the following:
    change attribute self.ok_to_swipe to 1
    Timer: after 1 second, change attribute self.ok_to_swipe to 0

    For this function, did you put the timer function inside the rule "Swipe =0'"?

    Remember to put this timer in a rule, under "when self.ok_to_sipe =1".

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

    @JH4music said:
    I have a scene with tiles that move left/right when you swipe. This works perfectly, but I would like to limit the swiping to only be possible every 1 second. The reason for this: there is an actor that fades in over the course of 1 second every time a new tile slides into the camera view...

    I'd just use some version of

    When self.colour.alpha=1
    --Swipe rules.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    @Socks said:

    @JH4music said:
    I have a scene with tiles that move left/right when you swipe. This works perfectly, but I would like to limit the swiping to only be possible every 1 second. The reason for this: there is an actor that fades in over the course of 1 second every time a new tile slides into the camera view...

    I'd just use some version of

    When self.colour.alpha=1
    --Swipe rules.

    You can also just slow the velocity of the swipe. If you're using the traditional swipe method, you can adjust the multiplier to slow the speed of the swipe.

  • JH4musicJH4music Member, PRO Posts: 23
    edited May 2016

    @Socks said:

    @JH4music said:
    I have a scene with tiles that move left/right when you swipe. This works perfectly, but I would like to limit the swiping to only be possible every 1 second. The reason for this: there is an actor that fades in over the course of 1 second every time a new tile slides into the camera view...

    I'd just use some version of

    When self.colour.alpha=1
    --Swipe rules.

    I got this working, to the point that I have an actor displaying text telling me when the game attribute controlled by alpha is true or false. This part of it works flawlessly, you can see after any swipe when it becomes true after the alpha reaches 1. The problem I have now: If I put a rule around my swipe behaviors saying only to allow them to happen if this boolean is true, the screen swipes every time the alpha reaches 1. I don't understand why, I haven't removed any of the rules that were put in place to make the swipe behavior happen. It's as if the conditions are set to "any" instead of "all", but they are definitely set to "all"

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    @JH4music said:

    @Socks said:

    @JH4music said:
    I have a scene with tiles that move left/right when you swipe. This works perfectly, but I would like to limit the swiping to only be possible every 1 second. The reason for this: there is an actor that fades in over the course of 1 second every time a new tile slides into the camera view...

    I'd just use some version of

    When self.colour.alpha=1
    --Swipe rules.

    I got this working, to the point that I have an actor displaying text telling me when the game attribute controlled by alpha is true or false. This part of it works flawlessly, you can see after any swipe when it becomes true after the alpha reaches 1. The problem I have now: If I put a rule around my swipe behaviors saying only to allow them to happen if this boolean is true, the screen swipes every time the alpha reaches 1. I don't understand why, I haven't removed any of the rules that were put in place to make the swipe behavior happen. It's as if the conditions are set to "any" instead of "all", but they are definitely set to "all"

    Show a screen shot of the rule

  • SocksSocks London, UK.Member Posts: 12,822
    edited May 2016

    //

  • JH4musicJH4music Member, PRO Posts: 23

    This is how my swipe behaviors work. You can swipe left/right, and it adds or subtracts an attribute that determines which tile to slide into the screen. The "Swipe Left" behavior isn't shown, but it's basically an inverted version of the swipe right. It works perfectly, if I turn off this set of rules, the swiping doesn't work, as you would expect. So there is nothing else in the game telling the tiles to swipe indefinitely.

  • JH4musicJH4music Member, PRO Posts: 23

    Now, I have the attribute game.ReadytoSwipe set up to change to 1 after the alpha of a certain actor reaches 1. This also works perfectly. I also did a version of this with a boolean and got perfect results. I made a temporary actor that starts out red and turns green once this attribute has changed from 0 to 1 (or false to true) I can see it change after every swipe using the "display text" behavior. Again, everything works perfectly up to this point.

  • JH4musicJH4music Member, PRO Posts: 23

    The problem is, when I do this:

    The swipe behavior just keeps swiping indefinitely, it never stops. I don't understand why.

  • JH4musicJH4music Member, PRO Posts: 23

    My assumption as a programmer is "If game.readytoswipe is NOT 1(Or "True" if I use boolean), DO NOT do anything with any of the rules/behaviors contained within this rule."

    Basically, this rule should have the same effect as turning off the rules (which does indeed stop swiping from happening). What on earth am I doing wrong?

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    I don't see where the encapsulating rule ever cuts off the code inside it. As a touch is released is a permanent condition once you release. So the code inside the touch is released rule will stay active. I don't do swipe that way so not sure. I'd need to see the code inside those expressions and the code inside the actor controlling the camera.

Sign In or Register to comment.