Ending based on time left?

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
teamace
Newbie
Posts: 10
Joined: Thu Oct 26, 2017 11:14 am
Contact:

Ending based on time left?

#1 Post by teamace »

I have a minigame on my VN that uses imagemaps (Find the missing object) wherein if the player finds the required item in less than 50s, it jumps to label scene1. Else, jumps to label scene2.

I'm still working on the timer before I continue working on the image map.
I'm not really good at coding but I get this error that says Invalid Syntax. I'm not really good at coding :cry:

init:
python:
def countdown(st, at, length=0.0):

remaining = length - st

if remaining >= 50.0:
return Text("%.1f" % remaining, color="#fff", size=72), .1
jump scene1
elif remaining < 50.0:
return Text("%.1f" % remaining, color="#f00", size=72), .1
jump scene2

# Show a countdown for 10 seconds.
image countdown = DynamicDisplayable(countdown, length=60.0)

label start:
"this is a text"
show countdown at Position(xalign=.1, yalign=.1)
"test"

label scene1:
"here"
label scene2:
"test"

User avatar
Empish
Veteran
Posts: 221
Joined: Thu Jan 14, 2016 9:52 pm
Projects: Efemural Hearts, It Ends With Graduation
itch: empish
Contact:

Re: Ending based on time left?

#2 Post by Empish »

Okay, so I think you're running into naming issues here. You have both a python function and an image named countdown. Try changing one of those names to be different. The second thing is, when you call a function you need to provide all the required parameters for it. It looks like you're just providing the length?

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Ending based on time left?

#3 Post by Remix »

A version that works... might get you moving again

Code: Select all

init python:
    def countdown(st, at, length=0.0):
        global remaining
        remaining = length - st
        
        if remaining >= 10.0:
            return Text("[remaining:.1f]", color="#fff", size=72), .1

        if remaining <= 0.0:
            renpy.hide_screen( 'test' )
            renpy.jump( 'fail' )
        
        return Text("[remaining:.1f]", color="#f00", size=72), .1
                   
# default remaining = 15.0

screen test():
    vbox:
        add DynamicDisplayable(countdown, length=15.0)

        textbutton "Found Me":
            action [ Function(renpy.hide_screen, 'test'), Jump('found_me') ]

label start:
    "this is a text"
    call screen test
    "test"

label found_me:
    if remaining >= 10.0:
        jump scene1
    jump scene2
    
label scene1:
    "success fast"
    return

label scene2:
    "success slow..."
    return

label fail:
    "Too slow"
    return
You could alternatively use a Timer or Bar with AnimatedValue which could automate the expired time action a bit
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]