Hyperlink passing parameters to labels

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
Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Hyperlink passing parameters to labels

#1 Post by Asceai »

I have a label:

Code: Select all

label test_label(n=1):
  # do stuff
  return
and I can pass parameters to it with 'call' without having any problems.

Code: Select all

call test_label(5)
call test_label(n=3)
However, for some reason, when I try to do the same thing in a hyperlink:

Code: Select all

"Hyperlink test. {a=test_label(5)}click here{/a}"
or

Code: Select all

"Hyperlink test. {a=test_label(n=5)}click here{/a}"
I get something like:
ScriptError: could not find label 'test_label(5)'.
It works fine if I omit the parameter (and the default value of 1 is then used). The documentation doesn't detail the mechanism for parameter passing through hyperlinks. Do I need to reimplement the respective hyperlink functions to achieve this?

Tsapas
Regular
Posts: 69
Joined: Mon Oct 14, 2013 8:18 am
Contact:

Re: Hyperlink passing parameters to labels

#2 Post by Tsapas »

That is because the hyperlink treats everything set as "a" (the target) as text. So in the case of omitting the parameter it checks for a label named "test_label" which exists and everything works fine. On the other hand, there is no label named "test_label(5)" so it's expected to throw an exception.

To overcome this, you should probably define your own hyperlink callback. Something like

Code: Select all

init python:
    def hyperlink_callback(label(arg)):
        renpy.jump(label(arg))

    config.hyperlink_callback = hyperlink_callback
(of course the above is not bound to work, it's not even tested. It just serves as an example)

Asceai
Eileen-Class Veteran
Posts: 1258
Joined: Fri Sep 21, 2007 7:13 am
Projects: a battle engine
Contact:

Re: Hyperlink passing parameters to labels

#3 Post by Asceai »

Tsapas wrote:That is because the hyperlink treats everything set as "a" (the target) as text. So in the case of omitting the parameter it checks for a label named "test_label" which exists and everything works fine. On the other hand, there is no label named "test_label(5)" so it's expected to throw an exception.

To overcome this, you should probably define your own hyperlink callback. Something like

Code: Select all

init python:
    def hyperlink_callback(label(arg)):
        renpy.jump(label(arg))

    config.hyperlink_callback = hyperlink_callback
(of course the above is not bound to work, it's not even tested. It just serves as an example)
It looks like pulling the arguments out to pass to renpy.call_in_new_context requires renpy.parser.parse_arguments, which requires me to set up a Lexer which wants all this other state as well, so it seems like a thoroughly tiresome thing to try and implement.

I'll just implement this in a less general way by adding stuff to a hyperlink callback for each thing I want to use.

Post Reply

Who is online

Users browsing this forum: Google [Bot]