{a=call:label} with parameters?

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
trekopedia
Regular
Posts: 25
Joined: Thu Sep 14, 2017 11:38 pm
Location: Toronto, Canada
Contact:

{a=call:label} with parameters?

#1 Post by trekopedia »

The new '{a=call:label}' hyperlink feature opens up some really interesting possibilities. I'm trying to make use of it in my current project but am unclear on how to pass parameters as part of the hyperlink.

For example, I have the following test code (which works):

Code: Select all

label start:

    $ myStr = "This is a {a=call:test}link{/a} without parameters."
    "[myStr]"
  
    call test("This direct call with parameters works!")

    return


label test(param='undefined'):

    "Parameter: [param]"

    return
How would I modify the hyperlink to support parameters (a string in this particular case) in the hyperlink's 'call' command, the same way that I was able to pass a parameter in the subsequent standard 'call' statement?

User avatar
PyTom
Ren'Py Creator
Posts: 16088
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: {a=call:label} with parameters?

#2 Post by PyTom »

It doesn't support parameters directly, but you can define your own scheme that lets you do what you want.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
trekopedia
Regular
Posts: 25
Joined: Thu Sep 14, 2017 11:38 pm
Location: Toronto, Canada
Contact:

Re: {a=call:label} with parameters?

#3 Post by trekopedia »

Hi PyTom - thanks for the response.

I am guessing that creating my own scheme would involve implementing a custom 'creator-defined protocol handler', as mentioned in the changelog. Is that correct?

Is there any documentation on what's involved in doing that or, ideally, some working examples I could study?

Thanks in advance.

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: {a=call:label} with parameters?

#4 Post by Remix »

Guesswork (from changelog sleuthing) so will likely need debugging...

Code: Select all

init python:
    def handle_call_with_args( value ):
        # value here is just the string after : >> "b( 12, 'string', var_val )"
        
        label, args = value, []
        
        if value.find( '(' ) > -1:
        
            label = value[ : value.find( '(' ) ] 
            
            # we py_eval the args into a list for *args to get variable values interpreted
            args = renpy.python.py_eval( "[{0}]".format( value[ value.find( '(' ) : -1 ] ) )
            
        renpy.call( label, *args )

define config.hyperlink_handlers = { 'call_args' : handle_call_with_args }

default var_val = 'a value'

label a:
    "{a=call_args:b( 12, 'string', var_val )} call b {/a}"

label b( i=0, s=0, v=0 ):
    "i=[i], s=[s], v=[v]"
Last edited by Remix on Sun Oct 22, 2017 10:54 am, edited 2 times in total.
Frameworks & Scriptlets:

User avatar
trekopedia
Regular
Posts: 25
Joined: Thu Sep 14, 2017 11:38 pm
Location: Toronto, Canada
Contact:

Re: {a=call:label} with parameters?

#5 Post by trekopedia »

Thanks, Remix -- that was exactly what I was looking for!

As you noted, it needed some minor debugging (missing closing quote in 'label a' plus an inadvertent indent on the config.hyperlink_handlers line).

For anyone else who learns best from studying code examples, here is the tweaked version. I switched 'label a:' to 'label start:' so that this example is ready-to-test.

Code: Select all

init python:
    def handle_call_with_args( value ):
        label, args = value.split('?')
        # we py_eval the args into a list for *args using eval to get variable values interpreted
        renpy.call( label, *renpy.python.py_eval( "[{0}]".format( args ) ) )

define config.hyperlink_handlers = { 'call_args' : handle_call_with_args }

default var_val = 'a value'

label start:
    "{a=call_args:b?12,'string',var_val}jump b{/a}"

label b( i, s, v ):
    "i=[i], s=[s], v=[v]"
 
Again, thank you very much for taking the time to create this example. You've made my day. :D

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: {a=call:label} with parameters?

#6 Post by Remix »

Just edited my 'non working' concept to be a bit nicer format and support { a=call_args : label( string of params ) } with the () parenthesis rather than url style ?
... and fixed the *cough* typos you mentioned ;)
Frameworks & Scriptlets:

User avatar
trekopedia
Regular
Posts: 25
Joined: Thu Sep 14, 2017 11:38 pm
Location: Toronto, Canada
Contact:

Re: {a=call:label} with parameters?

#7 Post by trekopedia »

Nice! I will study that version as well.

This functionality enables me to add a major improvement in the functionality of my current project -- thanks again!

Post Reply

Who is online

Users browsing this forum: Google [Bot]