Passing control to a label via hyperlink?

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
FamuFamu
Regular
Posts: 111
Joined: Thu Oct 11, 2012 4:52 pm
Contact:

Passing control to a label via hyperlink?

#1 Post by FamuFamu » Sat May 09, 2015 11:45 pm

What the topic says. I'm trying to pass control of the game to another label after clicking a hyperlink. I found this old thread where they tried to do that, and the first solution works like a charm, but it also makes hyperlinks lose their style (You can still click them, but they look just like any other text).

So my question is of course: Is there any way to make control of the game pass to another label after clicking a hyperlink (Instead of getting back to the place where it was clicked in the first place after reaching a return statement)? Or at the very least how to use the code in that old thread without the hyperlink style changing?

Thanks in advance.

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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: Passing control to a label via hyperlink?

#2 Post by PyTom » Sun May 10, 2015 12:00 am

Check out:

http://www.renpy.org/doc/html/style_pro ... properties

You can have the clicked function handle jumping.
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

User avatar
FamuFamu
Regular
Posts: 111
Joined: Thu Oct 11, 2012 4:52 pm
Contact:

Re: Passing control to a label via hyperlink?

#3 Post by FamuFamu » Sun May 10, 2015 12:19 am

Sorry but, is there any function/value that would help me achieve that already included? Or do I need to create a special function for it?

User avatar
PyTom
Ren'Py Creator
Posts: 15893
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: Passing control to a label via hyperlink?

#4 Post by PyTom » Sun May 10, 2015 12:52 am

You'd have to create a special function. Something like:

Code: Select all

init python:
    def hyperlink_styler(anchor):
        return style.hyperlink
    def hyperlink_clicked(anchor):
        renpy.jump(anchor)
    def hyperlink_hovered(anchor):
        return None

style default:
    hyperlink_functions (hyperlink_styler, hyperlink_clicked, hyperlink_hovered)
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

User avatar
FamuFamu
Regular
Posts: 111
Joined: Thu Oct 11, 2012 4:52 pm
Contact:

Re: Passing control to a label via hyperlink?

#5 Post by FamuFamu » Sun May 10, 2015 2:16 am

Worked perfectly, thanks!

An addition for anyone looking at this topic, the styling is pretty simple. Following the example given before you'd only need to either name a style "hyperlink" or replace "hyperlink" in return style.hyperlink with whatever you need.

Code: Select all

init python:
    style.hyperlink = Style(style.default)
    style.hyperlink.color = "#f00"
    style.hyperlink.size = 42
    def hyperlink_styler(anchor):
        return hyperlink
    def hyperlink_clicked(anchor):
        renpy.jump(anchor)
    def hyperlink_hovered(anchor):
        return None

style default:
    hyperlink_functions (hyperlink_styler, hyperlink_clicked, False)
This way the links would look like big red words.

Thanks again!

User avatar
octacon100
Regular
Posts: 163
Joined: Thu Sep 12, 2013 11:23 pm
Projects: Regeria Hope
Organization: Golden Game Barn
IRC Nick: Octacon100
Location: Boston, MA
Contact:

Re: Passing control to a label via hyperlink?

#6 Post by octacon100 » Thu Aug 25, 2016 10:50 pm

Thanks for that, it's a really big help!

Also, if anyone wants to just apply it to text in a certain screen, like the nvl screen, you can do something like this:

Code: Select all

## Need to set up the hyperlink style first.
init -1 python:
    style.hyperlink = Style(style.nvl_dialogue)
    style.hyperlink.color = "#c33"
    style.hyperlink.hover_color = "#c66"
    style.hyperlink.underline = True
    #style.hyperlink.size = 42
    def hyperlink_styler(anchor):
        return style.hyperlink
    def hyperlink_clicked(anchor):
        renpy.jump(anchor)
    def hyperlink_hovered(anchor):
        return None

-snip til you get to the text you want to change the hyperlink functions for-

                text what id what_id hyperlink_functions (hyperlink_styler,  hyperlink_clicked, False)

That code also shows how to have the text change color when you hover over it. Hope that helps someone.
Image
Current Digital Projects -
Image
Regiera Hope Completed Game Forum Post

Post Reply

Who is online

Users browsing this forum: Bing [Bot], zyric