[Resolved] Functions in screens

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
Regis
Newbie
Posts: 16
Joined: Tue Jan 10, 2017 6:31 pm
Contact:

[Resolved] Functions in screens

#1 Post by Regis »

I have a screen that has a part like this:

Code: Select all

screen my_screen(param1):
        if param1 == 1:
            add "img1" rotate -90 xzoom -1 xpos 1.02 ypos -0.5
        elif param1 == 2:
            add "img1" xalign 0.2
        elif param1 == 3:
            add "img1" xalign 0.4
        else:
            add "img1" xalign 0.1 xzoom -1
I would like move this if/else logic to a separate function and make calculations more complex. Like compute xalign using one of provided screen parameters as input. How to do that?
Last edited by Regis on Tue Feb 28, 2017 4:40 pm, edited 1 time in total.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Functions in screens

#2 Post by xavimat »

Code: Select all

init python:    
    def crazy_computing(v, w, x, y, z):
        # Some crazy computing that produces:
        return rotate, xzoom, yzoom, xalign, yalign
        
screen my_screen(v, w, x, y, z):    
    $ v1, v2, v3, v4, v5 = crazy_computing(v, w, x, y, z)
    add "img1" rotate v1 xzoom v2 yzoom v3 xalign v4 yalign v5
        
label start:
    show screen my_screen(v, w, x, y, z)
    #...
Be careful and don't mix "align" with "pos". Infact, "align" sets the "pos" and the "anchor" at the same time.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Regis
Newbie
Posts: 16
Joined: Tue Jan 10, 2017 6:31 pm
Contact:

Re: Functions in screens

#3 Post by Regis »

xavimat, thanks! That worked.
I was not aware that it's permitted to use python statements in screens.

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Functions in screens

#4 Post by xavimat »

Regis wrote:I was not aware that it's permitted to use python statements in screens.
Ren'Py's Magic... 8)
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

Post Reply

Who is online

Users browsing this forum: Exabot [Bot]