[Suggestion] Timed menu tutorial in documentation?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
SuperbowserX
Veteran
Posts: 270
Joined: Sat Jan 07, 2017 3:09 pm
Contact:

[Suggestion] Timed menu tutorial in documentation?

#1 Post by SuperbowserX »

Shouldn't there be a tutorial for timed menu in the documentation (i.e. for in-game menus)? I mean I was able to find some stuff online but since it's a big part of modern VNs I think it is worthy of going into the documentation for newcomers.

Also, side question. I am using https://www.renpy.org/wiki/renpy/doc/co ... imed_menus for timed menus, but is there anyway I can default the action that happens if you click nothing to a different dialogue choice? I am nesting of all of a menu's choices into the block right under that choice and it's a bit annoying to have to make new labels for each one.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: [Suggestion] Timed menu tutorial in documentation?

#2 Post by Imperf3kt »

From that screen:

Code: Select all

# time = the time the timer takes to count down to 0.
# timer_range = a number matching time (bar only)
# timer_jump = the label to jump to when time runs out

label menu1:
    $ time = 5
    $ timer_range = 5
    $ timer_jump = 'menu1_slow'
    show screen countdown
    menu:
        "Choice 1":
            hide screen countdown
            e "You chose 'Choice 1'"
            jump menu1_end
        "Choice 2":
            hide screen countdown
            e "You chose 'Choice 2'"
            jump menu1_end
   
label menu1_slow:
    e "You didn't choose anything."
    
label menu1_end:
    e "Anyway, let's do something else."
According to this, if you select nothing before the timer runs out, Eileen says "You didn't select anything."
So... just put a new menu there. Or change the jump so a different action is performed.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
SuperbowserX
Veteran
Posts: 270
Joined: Sat Jan 07, 2017 3:09 pm
Contact:

Re: [Suggestion] Timed menu tutorial in documentation?

#3 Post by SuperbowserX »

The timer I'm getting using that cookbook article:

Code: Select all

transform alpha_dissolve:
    alpha 0.0
    linear 0.5 alpha 1.0
    on hide:
        linear 0.5 alpha 0
    # This is to fade the bar in and out, and is only required once in your script

screen countdown:
    timer 0.01 repeat True action If(time > 0, true=SetVariable('time', time - 0.01), false=[Hide('countdown'), Jump(timer_jump)])
    bar value time range timer_range xalign 0.5 yalign 0.9 xmaximum 300 at alpha_dissolve # This is the timer bar.

label menu1:
    $ time = 5 ##Where time and timer_range are both the same amount; an amount equal to the amount of seconds I want the timer to be in
    $ timer_range = 5
    $ timer_jump = 'menu1_slow'
    show screen countdown
The timing here is rather inacurrate. It's longer than I'm putting it in for. I put it in for 4 seconds it seems to last around 7 etc.. Anyone have any idea why?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2404
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: [Suggestion] Timed menu tutorial in documentation?

#4 Post by Ocelot »

In short you are calling timer too often. When timer is loopint, each iteration takes slightly more time than specified: time specified in timer passes, timer fires, timer actions are executed (this takes time), interactive displayables are reevaluated (this takes time), screens are redrawn (this takes time), interation is restarted (this takes time), and, finally, timer is scheduled to run again in specified amount of time.
As you can see, error is accumulated quite fast for short timers.

The solution is to not assume that exactly specified amount of time has passed, but request actual time:

Code: Select all

init python:
    # Need it to manipulate time
    import time

screen countdown(timer_range, timer_jump):
    default end_time = time.time() + timer_range
    default current_time = time.time()
    timer 0.05 repeat True action If(
        current_time < end_time, 
        true=SetScreenVariable('current_time', time.time()), 
        false=[Hide('countdown'), Jump(timer_jump)]
    )
    # We have default dissolve in and dissolve out transform
    bar value (end_time-current_time)*100 range timer_range*100 xalign 0.5 yalign 0.9 xmaximum 300 at notify_appear 

label menu1_slow:
    'too slow'
    jump menu2
label menu2_slow:
    'tooooooo slow'
    return

label start:
    "Hello, world."
    show screen countdown(timer_range=5, timer_jump='menu1_slow')
    menu:
        '1':
            hide screen countdown
            '111'
        '2':
            hide screen countdown
            '222'
label menu2:
    show screen countdown(timer_range=12, timer_jump='menu2_slow')
    menu:
        '3':
            hide screen countdown
            '333'
        '4':
            hide screen countdown
            '444'
    'Bye'
    return
< < insert Rick Cook quote here > >

User avatar
SuperbowserX
Veteran
Posts: 270
Joined: Sat Jan 07, 2017 3:09 pm
Contact:

Re: [Suggestion] Timed menu tutorial in documentation?

#5 Post by SuperbowserX »

Thank you! that is both more accurate and cleaner to implement! <3

philat
Eileen-Class Veteran
Posts: 1912
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: [Suggestion] Timed menu tutorial in documentation?

#6 Post by philat »

As far as I know, the actual issue is that running timer every 0.01 seconds is bad. I don't know that switching to calling actual time would make a difference. The real difference is likely that Ocelot changed the timer to run every 0.05 seconds -- the original code is also (mostly) on time if you do that.

I like my tweak better (AnimatedValue is smoother than the bar updating at 0.05 seconds), but then, don't we all like our own tweaks better. ;) viewtopic.php?f=8&t=33120#p379109

User avatar
SuperbowserX
Veteran
Posts: 270
Joined: Sat Jan 07, 2017 3:09 pm
Contact:

Re: [Suggestion] Timed menu tutorial in documentation?

#7 Post by SuperbowserX »

philat wrote:As far as I know, the actual issue is that running timer every 0.01 seconds is bad. I don't know that switching to calling actual time would make a difference. The real difference is likely that Ocelot changed the timer to run every 0.05 seconds -- the original code is also (mostly) on time if you do that.

I like my tweak better (AnimatedValue is smoother than the bar updating at 0.05 seconds), but then, don't we all like our own tweaks better. ;) viewtopic.php?f=8&t=33120#p379109
That's nicer and cleaner. Anyway I can make your bar appear at the bottom, and only cover the central 2/3s of the screen rather than the whole screen? And perhaps make it a little bit less bright?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2404
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: [Suggestion] Timed menu tutorial in documentation?

#8 Post by Ocelot »

philat wrote:As far as I know, the actual issue is that running timer every 0.01 seconds is bad. I don't know that switching to calling actual time would make a difference. The real difference is likely that Ocelot changed the timer to run every 0.05 seconds -- the original code is also (mostly) on time if you do that.
Changing timer to 0.05 second was the first thing I tried, and it was still noticeably off. Version with calculating actual time works fine even with period 0.01.

However AnimatedValue is way better. I didn't used bars much, so I missed it. I should probably play with it some more.
SuperbowserX wrote: I can make your bar appear at the bottom, and only cover the central 2/3s of the screen rather than the whole screen? And perhaps make it a little bit less bright?
You can add any properties to your bar, as you did before:

Code: Select all

bar value AnimatedValue(0, time, time, time) xalign 0.5 yalign 0.9 xmaximum 300 at alpha_dissolve 
< < insert Rick Cook quote here > >

User avatar
SuperbowserX
Veteran
Posts: 270
Joined: Sat Jan 07, 2017 3:09 pm
Contact:

Re: [Suggestion] Timed menu tutorial in documentation?

#9 Post by SuperbowserX »

Anyone know anything about changing the bar's color?

Post Reply

Who is online

Users browsing this forum: Google [Bot], henne, Ocelot