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.
-
Regis
- Newbie
- Posts: 16
- Joined: Tue Jan 10, 2017 6:31 pm
-
Contact:
#1
Post
by Regis » Sun Feb 26, 2017 3:48 pm
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.
-
xavimat
- Eileen-Class Veteran
- Posts: 1458
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love, unknown
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
-
Contact:
#2
Post
by xavimat » Sun Feb 26, 2017 6:44 pm
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.
-
Regis
- Newbie
- Posts: 16
- Joined: Tue Jan 10, 2017 6:31 pm
-
Contact:
#3
Post
by Regis » Mon Feb 27, 2017 10:39 pm
xavimat, thanks! That worked.
I was not aware that it's permitted to use python statements in screens.
-
xavimat
- Eileen-Class Veteran
- Posts: 1458
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love, unknown
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
-
Contact:
#4
Post
by xavimat » Fri Mar 03, 2017 7:19 am
Regis wrote:I was not aware that it's permitted to use python statements in screens.
Ren'Py's Magic...

Users browsing this forum: Bing [Bot], Google [Bot]