Page 1 of 1

[solved]persistent Counter

Posted: Tue Mar 28, 2017 3:17 pm
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?

Re: persistent Counter

Posted: Tue Mar 28, 2017 7:57 pm
by indoneko
How about using a screen with zorder value set to 1000 ?

Re: persistent Counter

Posted: Wed Mar 29, 2017 5:51 pm
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

Re: persistent Counter

Posted: Wed Mar 29, 2017 10:30 pm
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

Re: persistent Counter

Posted: Thu Mar 30, 2017 1:08 am
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 ^_^