[SOLVED] Can text hyperlinks take arguments?

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
qirien
Miko-Class Veteran
Posts: 541
Joined: Thu Jul 31, 2003 10:06 pm
Organization: Metasepia Games
Deviantart: qirien
Github: qirien
itch: qirien
Location: New Mexico, USA
Discord: qirien
Contact:

[SOLVED] Can text hyperlinks take arguments?

#1 Post by qirien »

Hey, I was looking for documentation on the text hyperlinks, but so far the only thing I've found is in the Changelog. I would like to pass arguments to a screen using hyperlinks, but that doesn't seem to be working.

I have a contact list screen that takes the name of the person to show, so I'd like to be able to link from one bio to another using text tags.
screenshot0079.png
The screen I have goes through all the people and displays their names on the left, and displays the bio of whoever is selected on the right. So I was thinking that if you clicked on a text tag, it would call the screen with the name of new person to display.

Here's the screen code:

Code: Select all

screen biographies(name):
    modal True
    zorder 1
    style_prefix "bio"
    on "show" action SetVariable("show_person", name)

    frame:
        xalign 0.5
        yalign 0.5
        vbox:
            hbox:
                label "Community Bios"
                textbutton "X" xalign 0.97 action Hide("biographies", irisin) xfill False
            hbox:
                null width 30

                vpgrid:
                    cols 1
                    xsize LEFT_COLUMN_WIDTH-50
                    draggable True
                    mousewheel True
                    scrollbars "vertical"
                    for person in bios:
                        $ name = person.getName()
                        $ fname = person.getFullName()
                        $ read = person.getRead()
                        hbox:
                            showif (not read):
                                text " {b}!{/b} " xalign 1.0 yalign 0.0 style "alert_text" at tiny_bounce
                            else:
                                text "" xalign 0.0
                            textbutton fname action SetVariable("show_person", name)

                null width 5
                vbox:
                    xsize MIDDLE_COLUMN_WIDTH-32
                    yalign 0.0                    
                    label bios.getFullName(show_person) 
                    text  bios.getBio(show_person) 
And here's the text with the text tag I'm trying to use:

Code: Select all

"...She and her husband {a=show:biographies(\"Thuc\")}Thuc{/a} have 9 really polite kids (including Joanna, Miranda, and Van) and 1 little stinker (Gardenia)."
Am I doing this wrong or is this just not possible?
Last edited by qirien on Thu Sep 17, 2020 12:54 pm, edited 1 time in total.
Finished games:
Image
Image
Image

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Can text hyperlinks take arguments?

#2 Post by hell_oh_world »

Try this. A simple all purpose action handler I made. You can use any actions stated in here https://www.renpy.org/doc/html/screen_a ... -functions.

Code: Select all

init python:
    def actionHyperlinkHandler(action_string):
        return renpy.python.py_eval("renpy.run({})".format(action_string))

    config.hyperlink_handlers.update({"action": actionHyperlinkHandler})

label start:
  "{a=action:Show('biographies', None, 'Thuc')}Thuc{/a}"
  
  # example using multiple actions
  "{a=action:[Show('biographies', None, 'Thuc'), SetVariable('something', 1)]}Thuc{/a}"

User avatar
qirien
Miko-Class Veteran
Posts: 541
Joined: Thu Jul 31, 2003 10:06 pm
Organization: Metasepia Games
Deviantart: qirien
Github: qirien
itch: qirien
Location: New Mexico, USA
Discord: qirien
Contact:

Re: Can text hyperlinks take arguments?

#3 Post by qirien »

Thank you, this is exactly what I wanted!

I did have to change the action to be changing the screen variable that the screen uses to decide which person to display instead of showing the screen directly, but then it worked perfectly.
Finished games:
Image
Image
Image

evetaell
Newbie
Posts: 2
Joined: Mon Apr 05, 2021 11:50 am
Contact:

Re: [SOLVED] Can text hyperlinks take arguments?

#4 Post by evetaell »

I have error with my hyperlink: Show('more_text', None, 'test') ' is not defined.

Code: Select all

screen more_text(tx):
        vbox:
            text tx

"text {a=action:[ Show('more_text', None, '123') ]}link{/a}."
Please, help me.

User avatar
qirien
Miko-Class Veteran
Posts: 541
Joined: Thu Jul 31, 2003 10:06 pm
Organization: Metasepia Games
Deviantart: qirien
Github: qirien
itch: qirien
Location: New Mexico, USA
Discord: qirien
Contact:

Re: [SOLVED] Can text hyperlinks take arguments?

#5 Post by qirien »

Hey, if you want to use that, you'll need to paste in the python block from hell_oh_world. That's the code that tells Ren'py to pass interpret actions in hyperlinks as Ren'Py code. Is this what you want, or do you just want a regular hyperlink?
Finished games:
Image
Image
Image

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Ocelot