Page 1 of 1

[SOLVED] Execute function on custom tags

Posted: Tue Dec 06, 2022 8:17 pm
by cimokudo
I have read about custom_tags and how to use it.
But instead of styling the tagged text, i want to make a function work while clicking a tagged text, like what anchor / {a=}{/a} tag work.

From the example given in Custom Text Tags section, in Ren'Py Documentation, it just show how to use custom_tags for styling use.

I want to show modal screen contains information from argument of the tagged text.

for example :

Code: Select all

 cimo "What? I can't believe you love {pop='It is a Japanese genre of erotic video game.'}eroge{/pop} so much." 
While "eroge" clicked, it will pop modal screen showing the argument as content.

Code: Select all

init python:
    def popinfo(tag, argument, contents):
        Show("alert",title=contents,text=argument)()
        
    config.custom_text_tags["pop"] = popinfo

screen alert(title, text):
    modal True
    zorder 200
    style_prefix "confirm"
    add "gui/overlay/confirm.png"
    frame:
        vbox:
            xalign .5
            yalign .5
            spacing 15
            text "{size=30}[title]{/size}"
            text "{size=15}[text]{/size}"
            hbox:
                xalign 0.5
                textbutton "OK" action Hide("alert")
Sorry if the code above error, im not on my working pc right now.

Re: Execute function on custom tags

Posted: Tue Dec 06, 2022 8:35 pm
by Ocelot
You can use {a} tag for that.

Code: Select all

init python:
    def handle_alert_with_parameters(arg):
        param = arg.split('|')
        renpy.show_screen("alert", *param)

    config.hyperlink_handlers['alert'] = handle_alert_with_parameters

# . . . 

cimo "What? I can't believe you love {a=alert:eroge|It is a Japanese genre of erotic video game.}eroge{/a} so much." 

Re: Execute function on custom tags

Posted: Tue Dec 06, 2022 8:47 pm
by cimokudo
Ocelot wrote: Tue Dec 06, 2022 8:35 pm You can use {a} tag for that.

Code: Select all

init python:
    def handle_alert_with_parameters(arg):
        param = arg.split('|')
        renpy.show_screen("alert", *param)

    config.hyperlink_handlers['alert'] = handle_alert_with_parameters

# . . . 

cimo "What? I can't believe you love {a=alert:eroge|It is a Japanese genre of erotic video game.}eroge{/a} so much." 
Sweet!, i'll try it later. Thanks !