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.
-
trekopedia
- Regular
- Posts: 25
- Joined: Thu Sep 14, 2017 11:38 pm
- Location: Toronto, Canada
-
Contact:
#1
Post
by trekopedia » Sat Oct 21, 2017 8:11 pm
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?
-
PyTom
- Ren'Py Creator
- Posts: 15893
- 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:
#2
Post
by PyTom » Sun Oct 22, 2017 12:04 am
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
"Silly and fun things are important." - Elon Musk
Software > Drama •
https://www.patreon.com/renpytom
-
trekopedia
- Regular
- Posts: 25
- Joined: Thu Sep 14, 2017 11:38 pm
- Location: Toronto, Canada
-
Contact:
#3
Post
by trekopedia » Sun Oct 22, 2017 7:30 am
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.
-
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:
#4
Post
by Remix » Sun Oct 22, 2017 8:47 am
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.
-
trekopedia
- Regular
- Posts: 25
- Joined: Thu Sep 14, 2017 11:38 pm
- Location: Toronto, Canada
-
Contact:
#5
Post
by trekopedia » Sun Oct 22, 2017 10:46 am
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.

-
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:
#6
Post
by Remix » Sun Oct 22, 2017 10:53 am
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

-
trekopedia
- Regular
- Posts: 25
- Joined: Thu Sep 14, 2017 11:38 pm
- Location: Toronto, Canada
-
Contact:
#7
Post
by trekopedia » Sun Oct 22, 2017 11:11 am
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!
Users browsing this forum: Bing [Bot], Google [Bot]