Timed Menus[SOLVED]

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
AsHLeX
Miko-Class Veteran
Posts: 534
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Timed Menus[SOLVED]

#1 Post by AsHLeX » Tue Jul 14, 2015 7:36 am

I got the code from here:
http://www.renpy.org/wiki/renpy/doc/coo ... imed_menus

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.

init:
    $ timer_range = 0
    $ timer_jump = 0

# 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 start:
    $ 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."
So my question is... When I use the menus here, the text for the options doesn't change color when it's hovered or idle.
Eg.

Code: Select all

menu:
      " Pick one."
      "Choice 1":
              pass
      " Choice 2":
              pass
Normally, "choice 1" and "choice 2" text is usually grey when idle and black when hovered.
But using this code, the "choice 1" and "choice 2" text is always grey regardless of whether its hovered or idle.
How do I fix this?

Also, how do I change the color of the bar...? (Without changing the theme) Thanks you ^_^
Last edited by AsHLeX on Tue Jul 14, 2015 10:34 am, edited 2 times in total.
Image

User avatar
Donmai
Eileen-Class Veteran
Posts: 1919
Joined: Sun Jun 10, 2012 1:45 am
Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
Projects: Slumberland
Location: Brazil
Contact:

Re: Timed Menus

#2 Post by Donmai » Tue Jul 14, 2015 7:55 am

Where did you put your start label? Normally this code won't even run without that label. I've tested it with a

Code: Select all

label start:
line before the menu, and it worked.
Image
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)

User avatar
AsHLeX
Miko-Class Veteran
Posts: 534
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Timed Menus

#3 Post by AsHLeX » Tue Jul 14, 2015 7:59 am

Sorry. I changed the menu1 to start.
Image

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Timed Menus

#4 Post by SinnyROM » Tue Jul 14, 2015 8:20 am

The hover and idle states aren't showing because Ren'Py is too busy painting the timer bar screen. I suggest setting the timer to a higher number for a delay between repaints. Then compensate by increasing the time variables as well.

Code: Select all

screen countdown:
    # changed from 0.01
    timer 0.05 repeat True action If(time > 0, true=SetVariable('time', time - 0.05), false=[Hide('countdown'), Jump(timer_jump)])

Code: Select all

label menu1:
    # changed from 5
    $ time = 25
    $ timer_range = 25
You can change the bar colour using the bar style properties: http://www.renpy.org/doc/html/style_pro ... properties
Example of using the left_bar, but you can use styles too:

Code: Select all

    bar value time range timer_range xalign 0.5 yalign 0.9 xmaximum 300 left_bar Solid("#f00") at alpha_dissolve # This is the timer bar.

User avatar
AsHLeX
Miko-Class Veteran
Posts: 534
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Timed Menus

#5 Post by AsHLeX » Tue Jul 14, 2015 10:34 am

Thanks SinnyROM!!!! It worked. :D I'm so happy now~~~

And thanks Donmai!! :D
Image

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

Re: Timed Menus[SOLVED]

#6 Post by philat » Tue Jul 14, 2015 3:14 pm

...that's odd, because I've never had an issue with hover and idle states using that code.

But anyway, since this came up, it reminded me that I took the code on the wiki and rejiggered it a bit for my own reasons. I think this is more user-friendly, so I thought I'd share. As a disclaimer, I may be missing something by changing it this way, but I've had no problems with it. *shrug*

The adjustments are basically to address two things: 1) Setting up the timer every time is a hassle with THREE lines of python required. I don't know about y'all, but I hate typing the $ sign unless I have to. 2) I found that having the timer repeat every 0.01 or 0.05 seconds was a pretty surefire way to get lag, even on my (I like to think) perfectly capable laptop. Specifically, using 0.01, I found that setting the time to 5 seconds would actually take closer to 8 seconds or so to actually run on my laptop, which isn't the end of the world, but it obviously becomes a bigger problem if others have more or less powerful rigs that experience the lag differently. The lag becomes less of an issue at 0.05, but then the animation starts to get kind of choppy.

Code: Select all

screen countdown(timer_jump, time=5): # I set a default reaction time of 5 seconds
    timer time repeat False action [ Hide('countdown'), Jump(timer_jump) ]
    bar value AnimatedValue(0, time, time, time) at alpha_dissolve # assuming you're using the alpha_dissolve transform from the wiki

label start:
    "start test"
    show screen countdown("jump_label") # This uses the default time of 5.
#    show screen countdown("jump_label", 10) # This line, uncommented, will take 10 rather than 5 seconds.
    menu:
        "Choice 1":
            hide screen countdown
        "Choice 2":
            hide screen countdown

label jump_label:
    "You didn't choose anything."
With this code, it's much simpler to use the timed choices, and AnimatedValue is more efficient than the repeated timer, in my experience.
Last edited by philat on Tue Jul 14, 2015 6:27 pm, edited 1 time in total.

User avatar
SinnyROM
Regular
Posts: 166
Joined: Mon Jul 08, 2013 12:25 am
Projects: Blue Birth
Organization: Cosmic Static Games
Contact:

Re: Timed Menus[SOLVED]

#7 Post by SinnyROM » Tue Jul 14, 2015 6:04 pm

That does look a lot neater. I haven't had the chance to try AnimatedValue but it looks like something for me to experiment with in the near future, especially if it's better performance-wise. Thanks philat!

User avatar
AsHLeX
Miko-Class Veteran
Posts: 534
Joined: Wed Dec 25, 2013 1:09 pm
Completed: Starlight Dreamers, Mysterious Melody, Town of Memories, Marked, To Fly, The Change, Him From The Past, A Forgotten Memory
Projects: Cafe Mysteria
Location: Malaysia
Contact:

Re: Timed Menus[SOLVED]

#8 Post by AsHLeX » Tue Jul 14, 2015 10:22 pm

Woah, that looks neat!!! Thanks a lot, philat!!! :D
Image

Post Reply

Who is online

Users browsing this forum: Ocelot