Renpy - Any way to reset ui.timer?

Slinky87

New Member
Jul 19, 2017
5
0
So, I'm putting together a flinching system in battle. I want to reset the timer every time the target gets hit.

I've been using ui.timer, but it hasn't been resetting every interaction. Is there any way to reset the function every time?

I'm pretty new to coding, so my understanding of what's going on under the hood when I approach these tools is pretty surface level.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,192
I've been using ui.timer, [...]
Why, and how ?
Ren'py don't need ui since the introduction of its screen language in 2015. Either you're using , and the st/at parameters of the event method are a better replacement, or you aren't using one, and it's the screen statement that is to use.

Therefore, without the code you use, it will be difficult to answer.
 

the66

beware, the germans are cumming
Modder
Donor
Respected User
Jan 27, 2017
7,808
24,388
assign your timer to a variable and change it's state to not started.

Python:
screen timer_test():
   
    timer 10 as tmr:
        action Return()

    textbutton "Reset":
        action SetField(tmr.state, 'started', False) align (.5,.5)
ui.timer is just a wrapper for the Timer class like the screen language statement timer.
 

Slinky87

New Member
Jul 19, 2017
5
0
Why, and how ?
Ren'py don't need ui since the introduction of its screen language in 2015. Either you're using , and the st/at parameters of the event method are a better replacement, or you aren't using one, and it's the screen statement that is to use.

Therefore, without the code you use, it will be difficult to answer.
Thanks for the response! Like I said, I'm pretty new to this, and my understanding of the actual mechanics of the code I use is limited.

I used ui.timer because it was a timer that worked within a function, whereas the simple 'timer' only worked for a screen.

I'll explain my situation in further detail:

I'm working on a battle element within my game, and I was putting together the mechanics of what happens during an attack, with the condition that if a flinch occurs, the fighter is flinched for 0.5 seconds.

It's a real time battle setting, which is designed for some rapid fire button pressing gameplay. So the attack is to be repeated, basically, as fast as you can press the spacebar. I wanted to make it so that every time the opposing fighter is hit and a flinch occurs (a characteristic of a specific attack), the timer resets. That way if you switch targets, or cease attacking that target for whatever reason, that enemy is flinched for .5 seconds.

As it is now, the timer starts, runs to completion no matter how many new hits occur, and only resets if the target is hit again after the .5 seconds is already over.

I was considering playing around with calling an invisible screen that has more flexible use of the 'timer' function, but I have a feeling that'll just be overly complicated and inefficient (a good description for most of my code).
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,192
[...] whereas the simple 'timer' only worked for a screen.
Which isn't at all a problem, a screen don't necessarily need to display something.


It's a real time battle setting, which is designed for some rapid fire button pressing gameplay. So the attack is to be repeated, basically, as fast as you can press the spacebar. I wanted to make it so that every time the opposing fighter is hit and a flinch occurs (a characteristic of a specific attack), the timer resets.
It would have been better with an effective piece of code, since I could have explained it in a more practical way, but well :

Code:
screen mainTimer():
    timer 1.0 action [ WHATEVER YOU NEED TO DO, Hide( "mainTimer" ) ]

label combatStart:
    show screen mainTimer
    [...]

label hit:
     [...]
     if flinch happen:
         hide screen mainTimer
         show screen mainTimer
     [...]

I was considering playing around with calling an invisible screen that has more flexible use of the 'timer' function, but I have a feeling that'll just be overly complicated and inefficient (a good description for most of my code).
It can't be more complicated or inefficient than using a screen object (what ui.timer is) into a function that at no time would display something.

There's also , but the main point in its documentation is the "around 20Hz" ; it need less than a minute to be totally out of sync, while timer stay put to its synchronization.
 
  • Like
Reactions: Slinky87

Slinky87

New Member
Jul 19, 2017
5
0
Which isn't at all a problem, a screen don't necessarily need to display something.




It would have been better with an effective piece of code, since I could have explained it in a more practical way, but well :

Code:
screen mainTimer():
    timer 1.0 action [ WHATEVER YOU NEED TO DO, Hide( "mainTimer" ) ]

label combatStart:
    show screen mainTimer
    [...]

label hit:
     [...]
     if flinch happen:
         hide screen mainTimer
         show screen mainTimer
     [...]



It can't be more complicated or inefficient than using a screen object (what ui.timer is) into a function that at no time would display something.

There's also , but the main point in its documentation is the "around 20Hz" ; it need less than a minute to be totally out of sync, while timer stay put to its synchronization.

Thanks a lot, I appreciate it. Like I said, I'm sort of fumbling around figuring out how to make my code work.

The reason I used ui.timer was because I searching for a solution for how to make my timer work in a function in the first place, and I was just plugging things in seeing if they would work, ui.timer was the thing that worked. Tbh, I don't really know why or even what it is, it's a bit beyond me at this point in my coding education.

Anyway, thanks for taking the time to help.