Automated hyperlinks?

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
Mithrilda
Regular
Posts: 26
Joined: Mon Oct 13, 2014 2:01 pm
Contact:

Automated hyperlinks?

#1 Post by Mithrilda » Fri Oct 31, 2014 12:18 am

Is there anyway I can set something up so that every time a specific word is said, it turns into a hyperlink so the player can see the definition of it?

User avatar
Milkymalk
Miko-Class Veteran
Posts: 752
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Automated hyperlinks?

#2 Post by Milkymalk » Fri Oct 31, 2014 1:38 am

In theory yes, by rewriting the "say" screen and parsing the "what" argument before actually printing it. I'm not good with rewriting built-in stuff, though...

But be warned that it would probably get on the player's nerves to be still given the hyperlink after the tenth time... ;-)
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
Mithrilda
Regular
Posts: 26
Joined: Mon Oct 13, 2014 2:01 pm
Contact:

Re: Automated hyperlinks?

#3 Post by Mithrilda » Fri Oct 31, 2014 5:32 pm

Milkymalk wrote:In theory yes, by rewriting the "say" screen and parsing the "what" argument before actually printing it. I'm not good with rewriting built-in stuff, though...

But be warned that it would probably get on the player's nerves to be still given the hyperlink after the tenth time... ;-)
Thanks for the answer! I'm sort of new to this so I'm not sure exactly what you mean... Is there any way you could give an example?

User avatar
Milkymalk
Miko-Class Veteran
Posts: 752
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Automated hyperlinks?

#4 Post by Milkymalk » Fri Oct 31, 2014 6:10 pm

The text box you see when a character says something is a screen that is built-in. It's defined on top of screens.rpy:

Code: Select all

screen say:

    # Defaults for side_image and two_window
    default side_image = None
    default two_window = False

    # Decide if we want to use the one-window or two-window variant.
    if not two_window:

        # The one window variant.
        window:
            id "window"

            has vbox:
                style "say_vbox"

            if who:
                text who id "who"

            text what id "what"

    else:

        # The two window variant.
        vbox:
            style "say_two_window_vbox"

            if who:
                window:
                    style "say_who_window"

                    text who:
                        id "who"

            window:
                id "window"

                has vbox:
                    style "say_vbox"

                text what id "what"

    # If there's a side image, display it above the text.
    if side_image:
        add side_image
    else:
        add SideImage() xalign 0.0 yalign 1.0

    # Use the quick menu.
    use quick_menu
Because it's just normal screen language code, you can change this however you want. The important thing here is the argument "what" that is given to the screen. It contains the text to be displayed as speech.

What you need to do is string manipulation: Exchange every instance of a given word inside "what" with the same word embedded in hyperlink tags. This is a simple thing to do in Python, just look up string manipulation functions from the Python documentation.

What I don't know though is how to implement it into the screen because screens are quite odd: They don't execute when shown, but essentially ALL THE TIME. So if you replace a word with the same word and a tag, it will get replaced again and again.

I guess you could mark the word so the code knows if it has been replaced already; by using "+word+" instead of "word", so the code replaces it only then.
Example:
"This is a +sample+ sentence."
-> replace "+sample+" with "{a=labelname_to_call}sample{/a}"
Becomes: "This is a {a=labelname_to_call}sample{/a} sentence."

Code for this:

Code: Select all

$ what.replace("+sample+", "{a="labelname_to_call_in_new_context"}sample{/a}"
Add this line as the first line of the screen code, it MIGHT work. As I said, I'm not very good with this stuff, but the general method is like I said.
Anybody who knows better than me feel free to throw me out and show us how it's really done ;-)
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
Mithrilda
Regular
Posts: 26
Joined: Mon Oct 13, 2014 2:01 pm
Contact:

Re: Automated hyperlinks?

#5 Post by Mithrilda » Fri Oct 31, 2014 10:18 pm

Milkymalk wrote:The text box you see when a character says something is a screen that is built-in. It's defined on top of screens.rpy:

Code: Select all

screen say:

    # Defaults for side_image and two_window
    default side_image = None
    default two_window = False

    # Decide if we want to use the one-window or two-window variant.
    if not two_window:

        # The one window variant.
        window:
            id "window"

            has vbox:
                style "say_vbox"

            if who:
                text who id "who"

            text what id "what"

    else:

        # The two window variant.
        vbox:
            style "say_two_window_vbox"

            if who:
                window:
                    style "say_who_window"

                    text who:
                        id "who"

            window:
                id "window"

                has vbox:
                    style "say_vbox"

                text what id "what"

    # If there's a side image, display it above the text.
    if side_image:
        add side_image
    else:
        add SideImage() xalign 0.0 yalign 1.0

    # Use the quick menu.
    use quick_menu
Because it's just normal screen language code, you can change this however you want. The important thing here is the argument "what" that is given to the screen. It contains the text to be displayed as speech.

What you need to do is string manipulation: Exchange every instance of a given word inside "what" with the same word embedded in hyperlink tags. This is a simple thing to do in Python, just look up string manipulation functions from the Python documentation.

What I don't know though is how to implement it into the screen because screens are quite odd: They don't execute when shown, but essentially ALL THE TIME. So if you replace a word with the same word and a tag, it will get replaced again and again.

I guess you could mark the word so the code knows if it has been replaced already; by using "+word+" instead of "word", so the code replaces it only then.
Example:
"This is a +sample+ sentence."
-> replace "+sample+" with "{a=labelname_to_call}sample{/a}"
Becomes: "This is a {a=labelname_to_call}sample{/a} sentence."

Code for this:

Code: Select all

$ what.replace("+sample+", "{a="labelname_to_call_in_new_context"}sample{/a}"
Add this line as the first line of the screen code, it MIGHT work. As I said, I'm not very good with this stuff, but the general method is like I said.
Anybody who knows better than me feel free to throw me out and show us how it's really done ;-)
Hmm, I tried it, but it says that it's not terminated with a new line and to check strings and parenthesis. I've been searching for the documentation on this, but I either can't find it or can't understand what it's saying well enough...

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

Re: Automated hyperlinks?

#6 Post by Alex » Sat Nov 01, 2014 8:32 am


User avatar
Milkymalk
Miko-Class Veteran
Posts: 752
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Automated hyperlinks?

#7 Post by Milkymalk » Sat Nov 01, 2014 10:24 am

Mithrilda wrote:
Code for this:

Code: Select all

$ what.replace("+sample+", "{a=labelname_to_call_in_new_context}sample{/a}"
Hmm, I tried it, but it says that it's not terminated with a new line and to check strings and parenthesis. I've been searching for the documentation on this, but I either can't find it or can't understand what it's saying well enough...
Sorry, I missed a closing parenthesis und used quotation marks where no belong:

Code: Select all

$ what.replace("+sample+", "{a=labelname_to_call_in_new_context}sample{/a}")
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

Post Reply

Who is online

Users browsing this forum: Google [Bot]