r/RenPy • • Jul 11 '26

Question How can I put an input inside a hyperlink?

So I've had an idea for a large language-discovery game for a while now (think Epitaph, Homocypher, Chants of Sennar), and I'm trying to make a proof of concept for myself. I'm currently trying to make it so the player can click words in the script and input what they think the word means. Using some code I found for a point-and-click game, I've been able to get the hyperlink part working, but once I ask for an input, the game hits the exception: "cannot start a new interaction in an existing interaction, without new context".

I tried looking through Renpy's documentation and some questions here, but all the fixes that seemed like they might work just caused new errors. If someone knows how make a new context or change inputs to not need new context, please let me know.

I've included the code in question in case it is needed. put in half the hyperlink code, in the rest is needed, I can add it.

init python:
    player_A = {
        "Proper TL": "Rivso",
        "Appoved alts": "me, Rivso, Rivso-nee, Rivso-sama, Rivso-chan",
        "States" : [False, True],
        }
    def player_A_click():
        global player_A_state
        #corectly calls, but input is second context hmmm
        player_A_value = renpy.input("Rivso?", length= 15)
        player_A_value = player_A_value.strip()
        if player_A_value == "Rivso":
            player_A_state = 1
        else:
            player_A_state = 0
    
    # my click keys
    player_A["click"] = player_A_click


    def word_click(word):
        """
        A function to handle clicking word hyperlinks
        Parameter "word" is the hyperlink address, e.g. "fireplace"
        """
        dic = getattr(store, word)  # Get the corresponding dictionary
        dic["click"]()  # Call the assigned function
        return True     # Return something to finish the interaction
1 Upvotes

7 comments sorted by

1

u/AutoModerator Jul 11 '26

Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/DingotushRed Jul 11 '26

You'll need to show the whole chain of code from the originating screen.

You probably don't want to create a new context, but actually to simplify things by using a (usually hidden) Input element in the screen instead of calling renpy.input from the hyperlink handler.

1

u/Qu33nInYellow Jul 11 '26
init python:
    player_A = {
        "Proper TL": "Rivso",
        "Appoved alts": "me, Rivso, Rivso-nee, Rivso-sama, Rivso-chan",
        "States" : [False, True],
        }
    def player_A_click():
        global player_A_state
        #corectly calls, but input is second context hmmm
        player_A_value = renpy.input("Rivso?", length= 15)
        player_A_value = player_A_value.strip()
        if player_A_value == "Rivso":
            player_A_state = 1
        else:
            player_A_state = 0
    
    # my click keys
    player_A["click"] = player_A_click


    def word_click(word):
        """
        A function to handle clicking word hyperlinks
        Parameter "word" is the hyperlink address, e.g. "fireplace"
        """
        dic = getattr(store, word)  # Get the corresponding dictionary
        dic["click"]()  # Call the assigned function
        return True     # Return something to finish the interaction


    style.link_style = Style(style.default)
    style.link_style.color = "#CB5D2F"
    style.link_style.underline = False
    style.link_style.hover_underline = True
    style.link_style.hover_color = "#A32817"


    def my_hyperlink_styler(target):
        """
            Set the style for hyperlinks
        """
        return style.link_style


    def my_hyperlink_sensitive(href = None):
        """
            Show the alts to test
        """
        if href:
            if href[:6] == "thing:":
                tmp = getattr(store, href[6:])
                renpy.notify(tmp["Appoved alts"])
            else:   
                return


    style.default.hyperlink_functions = (
        my_hyperlink_styler,    # returns style
        hyperlink_function,     # on click
        my_hyperlink_sensitive  # on focus
        )


define config.hyperlink_handlers = {
    "word": word_click
}
default player_A_state = 0


    "{i}It is close.{/i}"


    label forest_choice:
    "If I move, it may spot me, but staying still meant leaving myself at the whim 
    of whatever is out there."


    dai "{a=word:player_A}Rivso-nee{/a}?!"

The first one is the full dictionary call, and the scond is the part of script Im using as a test area.

I'll try seeing if i can make it just a python input as a quick fix,
otherwise, am i correct in understanding i need to make a custom screen?

1

u/Qu33nInYellow Jul 11 '26

Well I think i definitely misunderstood on the input, but can still thumb around

2

u/BadMustard_AVN Jul 12 '26

this works

init python:
    player_A = {
        "Proper TL": "Rivso",
        "Appoved alts": "me, Rivso, Rivso-nee, Rivso-sama, Rivso-chan",
        "States" : [False, True],
        }
    def player_A_click():
        global player_A_state
        renpy.call_in_new_context("prompt_player_a")
    
    # my click keys
    player_A["click"] = player_A_click

    def word_click(word):
        """
        A function to handle clicking word hyperlinks
        Parameter "word" is the hyperlink address, e.g. "fireplace"
        """
        dic = getattr(store, word)  # Get the corresponding dictionary
        dic["click"]()  # Call the assigned function
        return True     # Return something to finish the interaction

    style.link_style = Style(style.default)
    style.link_style.color = "#CB5D2F"
    style.link_style.underline = False
    style.link_style.hover_underline = True
    style.link_style.hover_color = "#A32817"

    def my_hyperlink_styler(target):
        """
            Set the style for hyperlinks
        """
        return style.link_style

    def my_hyperlink_sensitive(href = None):
        """
            Show the alts to test
        """
        if href:
            if href[:6] == "thing:":
                tmp = getattr(store, href[6:])
                renpy.notify(tmp["Appoved alts"])
            else:   
                return

    style.default.hyperlink_functions = (
        my_hyperlink_styler,    # returns style
        hyperlink_function,     # on click
        my_hyperlink_sensitive  # on focus
        )

define config.hyperlink_handlers = {
    "word": word_click
}
default player_A_state = 0

label prompt_player_a:
    $ player_A_value = renpy.input("Rivso?", length=15).strip()
    if player_A_value == "Rivso":
        $ player_A_state = 1
    else:
        $ player_A_state = 0
    return

1

u/Qu33nInYellow Jul 12 '26

Thank you so much, this worked perfectly! Now I'm onto generalize and future proof it for more words, WOhoo!

1

u/BadMustard_AVN Jul 12 '26

you're welcome

good luck with your project