how to pass arguments to label?

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
span4ev
Regular
Posts: 77
Joined: Fri Jul 08, 2022 9:29 pm
itch: rpymc
Contact:

how to pass arguments to label?

#1 Post by span4ev » Sat Aug 20, 2022 10:16 pm

I tried but nothing worked. Can I even pass arguments to the label via a button?

Code: Select all

screen nav:
    imagebutton:
        action Jump('test', x)

label test(x):

User avatar
enaielei
Regular
Posts: 114
Joined: Fri Sep 17, 2021 2:09 am
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: how to pass arguments to label?

#2 Post by enaielei » Sat Aug 20, 2022 11:37 pm

You can't through Jump (no *args/**kwargs) action but can through Call action.
Either use Call action instead or maybe try this workaround.

Code: Select all

init python:
  _Jump = Jump
  def jump(label, *args, **kwargs):
    store.args = args
    store.kwargs = kwargs
    renpy.jump(label)
    
  def Jump(label, *args, **kwargs):
    return Function(jump, *args, **kwargs)

default args = ()
default kwargs = {}

screen nav:
    imagebutton:
        action Jump('test', 1, abc=123)

label test:
  $ x = args[0] # 1
  $ abc = kwargs["abc"] # 123

Post Reply

Who is online

Users browsing this forum: Bing [Bot]