Return directly back to the game?

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
nanashi
Regular
Posts: 78
Joined: Tue Aug 09, 2011 12:54 am
Contact:

Return directly back to the game?

#1 Post by nanashi » Thu Dec 08, 2011 12:53 pm

My game has a lot of hyperlinks (for technical vocabularies)
I know we can click anywhere to end the hyperlink screen.

My question is, can we make a button instead that will end the hyperlink screen? (to return back to the game)
My game looks like this.
http://www.youtube.com/watch?v=VNzdVcli0zI

Players doesn't know they can click anywhere outside the button to return back to the game.
So I want a button that will return back instead.

It would be great if the button is a screen or another hyperlink (like a{Return})

User avatar
PyTom
Ren'Py Creator
Posts: 15502
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Return directly back to the game?

#2 Post by PyTom » Thu Dec 08, 2011 11:45 pm

Let's break it down a bit.

A hyperlink is just a call to a label (in a new context), so a return from the label will bring you back from the hyperlink. To the hyperlink, it doesn't matter what you do inside the label's block, as long as you eventually make it to a return statement. So let's put a call to a screen inside a label, and add a return button to that screen.

Code: Select all

screen definition:
    frame:
        has vbox
        text body 
        textbutton "Return" action Return(True)

Code: Select all

label define_trebuchet:
     call screen definition(body="A siege weapon that uses a weight to pull a lever arm.")
     return
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

nanashi
Regular
Posts: 78
Joined: Tue Aug 09, 2011 12:54 am
Contact:

Re: Return directly back to the game?

#3 Post by nanashi » Fri Dec 09, 2011 11:39 am

Thanks. I tried.
It's working. But I still need some adjustment.

Let's say I hyperlinked label vocabulary01 -> vocabulary_list -> vocabulary02 -> vocabulary_list -> vocabulary03.

When I return on "vocabulary 03", it goes back to vocabulary02. return again and it goes back to vocabulary01.
The game is returning back to every labels I've went through.

This is something I don't want.
I'd like to go directly back to the game with one click (without passing past labels)
Is there a way for this?

Like this one on 00:20.
I can't go back to game with a click.

http://www.youtube.com/watch?v=-f8ddXMO0J8

User avatar
Alex
Lemma-Class Veteran
Posts: 2537
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Return directly back to the game?

#4 Post by Alex » Sat Dec 10, 2011 5:01 pm

You could try to show screens instead of call them, and make return button to hide all those screens.

Code: Select all

init python:
    def hide_scr():      # this function will hide 100 screens named "voc1", "voc2", "voc3" etc.
        for i in range (1,101):
            renpy.hide_screen("voc%s" %i)
        renpy.restart_interaction()

image scr_bg:
    "#000"
    alpha 0.5
    
screen voc1:
    modal True    # this forces player to interact only with this screen
    zorder 70
    frame:
        xalign 0.5 yalign 0.5
        xminimum 400 xmaximum 400 yminimum 200 ymaximum 200
        background Frame ("scr_bg", 10, 10)

        vbox:
            xalign 0.5
            textbutton "Voc 2" action [Hide("voc2"),Show("voc2")]    # will hide the screen and show it again at the top if it is neccessary
            textbutton "Voc 3" action [Hide("voc3"),Show("voc3")]
            null height 30
            textbutton "Return" action hide_scr  # or [Hide("voc1"), Hide("voc2"), Hide("voc3")] etc. to hide all screens at once
        
screen voc2:
    modal True
    zorder 70
    frame:
        xalign 0.7 yalign 0.3
        xminimum 400 xmaximum 400 yminimum 200 ymaximum 200
        background Frame ("scr_bg", 10, 10)

        vbox:
            xalign 0.5
            textbutton "Voc 1" action [Hide("voc1"),Show("voc1")]
            textbutton "Voc 3" action [Hide("voc3"),Show("voc3")]
            null height 30
            textbutton "Return" action hide_scr
            
screen voc3:
    modal True
    zorder 70
    frame:
        xalign 0.3 yalign 0.6
        xminimum 400 xmaximum 400 yminimum 200 ymaximum 200
        background Frame ("scr_bg", 10, 10)

        vbox:
            xalign 0.5
            textbutton "Voc 1" action [Hide("voc1"),Show("voc1")]
            textbutton "Voc 2" action [Hide("voc2"),Show("voc2")]
            null height 30
            textbutton "Return" action hide_scr 

# The game starts here.
label start:

    "Test screens"
    show screen voc1
    "let's continue the game"

nanashi
Regular
Posts: 78
Joined: Tue Aug 09, 2011 12:54 am
Contact:

Re: Return directly back to the game?

#5 Post by nanashi » Sun Dec 11, 2011 12:09 pm

Thanks Alex.
It's amazing. working great!

Would you mind if I ask few more questions?
I made the button into grips.
I'd like to know how to align the buttons at right.


This is how my game looks for now.
screenshot0014.png
I'd like to make it like this.
screenshot0014b.png
Here's my code right now.

Code: Select all

screen voc1:
    modal True    # this forces player to interact only with this screen
    zorder 99
    
    frame:
        xalign 0.5 yalign 0.5
        xminimum 925 xmaximum 925 yminimum 550 ymaximum 550
        background Frame ("scr_bg", 10, 10)

        vbox:
            text "\n   001:Vocabulary 01"
            frame:
                    grid 5 1:
                        transpose True
                        xfill True           
                        textbutton "Return" action hide_scr
                        textbutton "Chapters" action Jump("solve_screen_return")            
                        textbutton "List" action Jump("chigo_solve_return")
                        textbutton "Title Screen" action [hide_scr,Jump("after_custom")]
                        textbutton "Check Online" action Jump("chigo_sol005")

User avatar
Alex
Lemma-Class Veteran
Posts: 2537
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Return directly back to the game?

#6 Post by Alex » Sun Dec 11, 2011 12:37 pm

You shouldn't use "grid" in this case, 'cause it makes all the cells the same size (http://www.renpy.org/doc/html/screens.html#grid). Just use <hbox> instead, like

Code: Select all

screen voc1:
    modal True
    zorder 70
    frame:
        xalign 0.5 yalign 0.5
        xminimum 400 xmaximum 400 yminimum 200 ymaximum 200
        background Frame ("scr_bg", 10, 10)

        vbox:
            xfill True
            vbox:
                xalign 0.5
                textbutton "Voc 2" action [Hide("voc2"),Show("voc2")]
                textbutton "Voc 3" action [Hide("voc3"),Show("voc3")]
                null height 30
                textbutton "Return" action hide_scr# [Hide("voc1"), Hide("voc2"), Hide("voc3")]
                null height 30
                
            hbox:
                    xalign 1.0
                    text "Text1" size 10
                    text "/ or textbutton" size 10
                    text "/ or smth." size 10

nanashi
Regular
Posts: 78
Joined: Tue Aug 09, 2011 12:54 am
Contact:

Re: Return directly back to the game?

#7 Post by nanashi » Mon Dec 12, 2011 11:48 am

Thanks!

Um, can I ask just few more things?
I've been trying to solve it myself for hours but I coudn't.

I'm using hyperlink to open vocabularies up.
Is there a way to open screen with a hyperlink?

I tried this method, but I don't like how it pauses the game for a click.

Code: Select all

   john "You know what{a=la_voc1}Vocabulary01{/a} is?"

label la_voc1:
   show screen voc1
   $ renpy.pause(hard=False)
   return

User avatar
Alex
Lemma-Class Veteran
Posts: 2537
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Return directly back to the game?

#8 Post by Alex » Mon Dec 12, 2011 1:27 pm

Is there a way to open screen with a hyperlink?
I don't know, lol.
I tried this method, but I don't like how it pauses the game for a click.
Just use pause with time parameter short enough to be not noticed, like

Code: Select all

$ renpy.pause(0.001)

User avatar
PyTom
Ren'Py Creator
Posts: 15502
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Return directly back to the game?

#9 Post by PyTom » Mon Dec 12, 2011 4:21 pm

nanashi wrote:Is there a way to open screen with a hyperlink?
Yeah, we can do that, by customizing the hyperlink_functions style property.

Code: Select all


screen definition:
    frame:
        has vbox

        text "Now defining [link]."
        textbutton "Hide" action Hide("definition")

init python:

    def hyperlink_styler(link):
        return style.hyperlink_text

    def hyperlink_clicked(link):
         renpy.show_screen("definition", link=link)

    def hyperlink_hovered(link):
         return None
    
    style.default.hyperlink_functions = (hyperlink_styler, hyperlink_clicked, hyperlink_hovered)

label start:
    "Let's define: {a=foo}foo{/a}"
    return
Code not tested.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Google [Bot]