[solved]persistent Counter

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
Cristiander
Regular
Posts: 33
Joined: Sat Mar 04, 2017 8:19 am
Contact:

[solved]persistent Counter

#1 Post by Cristiander »

I want to have a counter that can still be shown when I transition from one scene to another.

What I'm using right now is this script:
viewtopic.php?f=8&t=13381

Unfortunately in this script my counter is seen as an image, a DynamicDisplayable that is faded when I transition from one scene to another.

I need to find a way to make that displayable persist through scene transitions

Any help?
Last edited by Cristiander on Sun Apr 02, 2017 2:29 pm, edited 1 time in total.

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: persistent Counter

#2 Post by indoneko »

How about using a screen with zorder value set to 1000 ?
My avatar is courtesy of Mellanthe

Cristiander
Regular
Posts: 33
Joined: Sat Mar 04, 2017 8:19 am
Contact:

Re: persistent Counter

#3 Post by Cristiander »

indoneko wrote:How about using a screen with zorder value set to 1000 ?
That might work, but how do I make the timer go down?

I made this for the screen script:

Code: Select all

#This screen adds a counter that persist through scene transitions
screen countdown():
    zorder 100
    fixed:

        if timer_remaining > 45:
            text ("%.1f" % timer_remaining) color "#FFFFFF" size 72 xalign 0.5 yalign 0.6
        elif timer_remaining > 0:
            text Text("%.1f" % timer_remaining) color "#FF0000" size 72 xalign 0.5 yalign 0.6
but I can't find a way to make timer_remaining count down

User avatar
indoneko
Miko-Class Veteran
Posts: 528
Joined: Sat Sep 03, 2016 4:00 am
Contact:

Re: persistent Counter

#4 Post by indoneko »

Use timer in your screen. Here's an example :

Code: Select all

screen counterdisplay():
    zorder 100
    timer .1 repeat True action [If(time_remaining <= 0, 
        true=SetVariable("time_remaining", 0), 
        false=SetVariable("time_remaining", time_remaining -.1))]
    
    if time_remaining >= 5:
        text ("%.1f" % time_remaining) color "#00FF00" size 72 xalign 0.1 yalign 0.1
    else:
        text ("%.1f" % time_remaining) color "#FF0000" size 72 xalign 0.1 yalign 0.1
Then, assuming that you give 10 seconds to the player, here's how you use it in script.rpy :

Code: Select all

default time_remaining = 0
    
label start:
    "You reached the market district, and you decide to..."
    $time_remaining = 10
    show screen counterdisplay()
    $ ui.timer(10.0, ui.jumps("tooslow"))

    menu:
        "Follow Cristiander":
            jump cristiander
        "Follow Indoneko":
            jump indoneko
   
label tooslow:
    hide screen counterdisplay
    "You're too slow and you lost both of them!"
    return
   
label cristiander:
    hide screen counterdisplay
    "You follow cristiander to the church..."
    return

label indoneko:
    hide screen counterdisplay
    "You follow indoneko to the pet shop..."
    return
My avatar is courtesy of Mellanthe

Cristiander
Regular
Posts: 33
Joined: Sat Mar 04, 2017 8:19 am
Contact:

Re: persistent Counter

#5 Post by Cristiander »

indoneko wrote:Use timer in your screen. Here's an example :

Code: Select all

screen counterdisplay():
    zorder 100
    timer .1 repeat True action [If(time_remaining <= 0, 
        true=SetVariable("time_remaining", 0), 
        false=SetVariable("time_remaining", time_remaining -.1))]
    
    if time_remaining >= 5:
        text ("%.1f" % time_remaining) color "#00FF00" size 72 xalign 0.1 yalign 0.1
    else:
        text ("%.1f" % time_remaining) color "#FF0000" size 72 xalign 0.1 yalign 0.1
Then, assuming that you give 10 seconds to the player, here's how you use it in script.rpy :

Code: Select all

default time_remaining = 0
    
label start:
    "You reached the market district, and you decide to..."
    $time_remaining = 10
    show screen counterdisplay()
    $ ui.timer(10.0, ui.jumps("tooslow"))

    menu:
        "Follow Cristiander":
            jump cristiander
        "Follow Indoneko":
            jump indoneko
   
label tooslow:
    hide screen counterdisplay
    "You're too slow and you lost both of them!"
    return
   
label cristiander:
    hide screen counterdisplay
    "You follow cristiander to the church..."
    return

label indoneko:
    hide screen counterdisplay
    "You follow indoneko to the pet shop..."
    return

That should work perfectly! Thank you! ^_^

[Edit] Yup, it works! Thank you ^_^

Post Reply

Who is online

Users browsing this forum: Google [Bot]