Timed choices without jumping to a label?

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
ketskari
Veteran
Posts: 290
Joined: Tue Dec 21, 2010 6:22 pm
Completed: Asher, Sunrise, Tell a Demon
Projects: Asher Remake, TEoA
Organization: Sun Labyrinth
Tumblr: sunlabyrinth
Deviantart: sunlabyrinth
itch: sunlabyrinth
Contact:

Timed choices without jumping to a label?

#1 Post by ketskari » Wed Dec 02, 2015 10:01 pm

Jumping to a label from a timed menu messes with my called labels. Being able to somehow call the label would be nice.

Unfortunately, this causes the first line of dialogue to repeat itself in the called label.

Code: Select all

screen countdown:
    modal False
    timer 0.01 repeat True action If(time > 0, true=SetVariable("time", time - 0.01), false=[Hide("countdown"), SetVariable("losttime", True), Function(renpy.call, label=timer_call)])
    bar value time range timer_range xalign 0.5 yalign 0.9 xmaximum 300 at alpha_dissolve
This does nothing, just shows the menu again.

Code: Select all

screen countdown:
    modal False
    timer 0.01 repeat True action If(time > 0, true=SetVariable("time", time - 0.01), false=[Hide("countdown"), SetVariable("losttime", True), Function(renpy.call_in_new_context, label=timer_call)])
    bar value time range timer_range xalign 0.5 yalign 0.9 xmaximum 300 at alpha_dissolve
This just plain doesn't work, even though it works in a different screen with much the same purpose.

Code: Select all

screen countdown:
    modal False
    timer 0.01 repeat True action If(time > 0, true=SetVariable("time", time - 0.01), false=[Hide("countdown"), Return("lost")])
    bar value time range timer_range xalign 0.5 yalign 0.9 xmaximum 300 at alpha_dissolve
The last one gives me this:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 636, in script call
    call Jul1 from _call_Jul1
  File "game/jul.rpy", line 367, in script
    menu:
TypeError: list indices must be integers, not str

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 636, in script call
    call Jul1 from _call_Jul1
  File "game/jul.rpy", line 367, in script
    menu:
  File "\Desktop\renpy-6.99.7-sdk\renpy-6.99.6-sdk\renpy\ast.py", line 1453, in execute
    next_node(self.items[choice][2][0])
TypeError: list indices must be integers, not str
Or anything else I can try? Or fix in the above? Thanks.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Timed choices without jumping to a label?

#2 Post by xela » Thu Dec 03, 2015 4:57 am

ketskari wrote:Or anything else I can try? Or fix in the above? Thanks.
Fixing the above may no even be reasonable.

You could (should) try implementing something similar into the menu screen itself, you can even put timer and bar on menu screen as well (obviously conditioned off a preset menu choice name)! For action, you can plainly use the original menu action and create dynamic menus that do what you please. I am using a very similar system in my game, it should work out for you perfectly.

===
Alternately, your way may work as it is but you'll have to write a Function action without renpy.restart_interaction (more like copy/paste/rename than write one), but only if that is what causing the line to repeat itself and if calling a label from a screen works without messing stuff up.
Like what we're doing? Support us at:
Image

User avatar
ketskari
Veteran
Posts: 290
Joined: Tue Dec 21, 2010 6:22 pm
Completed: Asher, Sunrise, Tell a Demon
Projects: Asher Remake, TEoA
Organization: Sun Labyrinth
Tumblr: sunlabyrinth
Deviantart: sunlabyrinth
itch: sunlabyrinth
Contact:

Re: Timed choices without jumping to a label?

#3 Post by ketskari » Thu Dec 03, 2015 6:32 pm

Thank you, xela. I would prefer to edit the menu screen. I started pulling a test game together to try it:

In script.rpy:

Code: Select all

init:
    if not persistent.timedchoices:
        $persistent.timedchoices = True

# The game starts here.
label start:
    $time = 5
    $timer_range = 5
    $timer_call = "test3"
    "testing"
    menu:
        "Test":
            "Test text"
        "Test2":
            "test2 text"
        "test3":
            call test3
    "All done."
    return

label test3:
    "test3 text"
    return

In screens.rpy:

Code: Select all

screen choice(items):

    default lost_tm = False
    if persistent.timedchoices:
        vbox:
            xalign .5 yalign .2
            timer 0.01 repeat True action If(time > 0, true=SetVariable("time", time - 0.01), false=[SetScreenVariable("lost_tm", True)])
            bar value time range timer_range xalign 0.5 yalign 0.9 xmaximum 300 at alpha_dissolve 

    window:
        style "menu_window"
        xalign 0.5
        yalign 0.5


        vbox:
            style "menu"
            spacing 2
            showif lost_tm == False or persistent.timedchoices == False:
                for caption, action, chosen in items:

                    if action:
                        
                            button:
                                action action
                                style "menu_choice_button"
                                text caption style "menu_choice"
                    
                    else:
                        text caption style "menu_caption"

            else:
                on "show" action [Hide("choice"), Function(renpy.call, label=timer_call)]
However, it will still repeat the text. It seems to be grabbing text from the final choice when the timer goes off, actually, rather than repeating the text in label test3, because if I replace "call test3" with the text "test4" in the script, it will first call test3, then give me "test4", then continue on. Is there a solution for this?

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Timed choices without jumping to a label?

#4 Post by xela » Fri Dec 04, 2015 3:32 am

ketskari wrote:Is there a solution for this?
These are both solutions:
xela wrote:You could (should) try implementing something similar into the menu screen itself, you can even put timer and bar on menu screen as well (obviously conditioned off a preset menu choice name)! For action, you can plainly use the original menu action and create dynamic menus that do what you please. I am using a very similar system in my game, it should work out for you perfectly.
xela wrote: Alternately, your way may work as it is but you'll have to write a Function action without renpy.restart_interaction (more like copy/paste/rename than write one), but only if that is what causing the line to repeat itself and if calling a label from a screen works without messing stuff up.
I know that first suggestion will work perfectly and without glitches but that is not what you did. Second proposed solution should also work but that is more an educated guess than a fact.

What you did is meaningless since the code works in almost exactly the same way as your previous setup. You could try the second siggestion:

Code: Select all

Function(renpy.call, label=timer_call, _update_screens=False)
in your (previus) code or make a new Function Action that does not restart interaction. This might work but the first solution is better and more powerful but is prolly harder to code initially.
Like what we're doing? Support us at:
Image

User avatar
ketskari
Veteran
Posts: 290
Joined: Tue Dec 21, 2010 6:22 pm
Completed: Asher, Sunrise, Tell a Demon
Projects: Asher Remake, TEoA
Organization: Sun Labyrinth
Tumblr: sunlabyrinth
Deviantart: sunlabyrinth
itch: sunlabyrinth
Contact:

Re: Timed choices without jumping to a label?

#5 Post by ketskari » Fri Dec 04, 2015 3:38 am

Without examples, I have no idea what you're talking about. I thought you meant just to put the code in the menu screen itself.

Anyway, I'll just do it with a new screen, since I can get it to work the way I want with Return("label"). Thanks anyway.

Post Reply

Who is online

Users browsing this forum: Google [Bot]