Call screen accepting conditional arguments? (What's the best way to do this?)

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
LeonDaydreamer
Veteran
Posts: 335
Joined: Sun Feb 22, 2015 1:20 am
Projects: A Near Dawn, Put A Sock In It!, Ghosts Are Good Hosts
Contact:

Call screen accepting conditional arguments? (What's the best way to do this?)

#1 Post by LeonDaydreamer »

Hey guys, I'm having an efficiency issue - in that my code would be a lot more efficient if I knew Python better :/
Can someone tell me what's the best way to put together a 'call screen' statement with conditional arguments?

Let's say a screen accepts multiple arguments, but depending on your progress in the story you would only be sending certain ones to it. So in my head, where things work with the power of magic and happiness, it looks like something like this:

Code: Select all

$ renpy.call (MYSCREEN, "arg1, arg2" + if abc (", arg3, arg4") + if xyz (", arg5, arg6"))
.... I'm sure it would need to be written with the arguments list as a string that gets interpreted by the call statement, in which certain arguments are added or omitted or something of the sort, but I have no idea what the proper way to execute that would be. Can anyone shed some light on this issue?

** Right now my solution is:

Code: Select all

if xyz:
   call screen MYSCREEN (arg1,arg2,arg3,arg4,arg5,arg6)
elif abc:
   call screen MYSCREEN (arg1,arg2,arg3,arg4)
else:
   call screen MYSCREEN (arg1,arg2)
And it's just not a very efficient way of handling this issue...
ImageImageImageImage

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: Call screen accepting conditional arguments? (What's the best way to do this?)

#2 Post by Remix »

If you can build/manage a list, you can pass in that as parts of the *args special parameter... sample

Code: Select all

screen vari_args( *args ):
    vbox:
        area (0.8, 0.0, 0.2, 0.2)
        text "{0}".format( args )
        for arg in args:
            text "{0}".format( arg )

label start:
    # just a random list of [ 0, 1, 2 .... 7 ] for testing
    # refresh restart a few times
    $ args = [k for k in range( renpy.random.randint(3, 8) )]
    show screen vari_args( *args )
    "Words"
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], snotwurm