Python - renpy.render(?) for Screen Add functionality

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
awonderL
Newbie
Posts: 6
Joined: Sun Nov 28, 2021 1:29 am
Contact:

Python - renpy.render(?) for Screen Add functionality

#1 Post by awonderL »

Apologies because I'm still very new to Ren'py and python.

I'm trying to dynamically add an everchanging amount of images to my screen through an everchanging ATL argument transform.

How many images is based off an integer that changes.

In this integer case I'd use a while loop, but I think range() is needed inside a screen, right? The problem for me is my dynamically changing ATL argument.

Code: Select all

for i in range(int):
	add "myimage" at myATLtransform(number_needed_here)
	$ number_needed_here += 1
That last line is where my problem occurs, I think because it's inside a screen and variables can go crazy due to screen refreshes? I tried using a screen variable substituted above but that didn't work either—I'm probably doing something wrong.

So how can I get around this? Inside the screen would be my preference, but if it must be through a function/python, what is the simplest way to render images in a function? I can't seem to wrap my head around the documentation surrounding this, because mostly it's about creating a class to render? Which in this case, is overkill for my purposes.

Is there just one line of code that mimics the "add" functionality of screens that I can use inside a function?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Python - renpy.render(?) for Screen Add functionality

#2 Post by Ocelot »

You never reset number_needed_here varaiable to what ever value it should have in the beginning.
YOu can do:

Code: Select all

$ number_needed_here = 0 # 1, 10, 42, whatever you want
for i in range(amount_of_item_in_list):
	add "myimage" at myATLtransform(number_needed_here)
	$ number_needed_here += 1
or even combine loop counter with needed number:

Code: Select all

for i in range(<start_value>, <start_value> + <amount_of_item_in_list>):
	add "myimage" at myATLtransform( i )
< < insert Rick Cook quote here > >

awonderL
Newbie
Posts: 6
Joined: Sun Nov 28, 2021 1:29 am
Contact:

Re: Python - renpy.render(?) for Screen Add functionality

#3 Post by awonderL »

Ocelot wrote: Fri Jan 28, 2022 5:10 am You never reset number_needed_here varaiable to what ever value it should have in the beginning.
YOu can do:

Code: Select all

$ number_needed_here = 0 # 1, 10, 42, whatever you want
for i in range(amount_of_item_in_list):
	add "myimage" at myATLtransform(number_needed_here)
	$ number_needed_here += 1
or even combine loop counter with needed number:

Code: Select all

for i in range(<start_value>, <start_value> + <amount_of_item_in_list>):
	add "myimage" at myATLtransform( i )
I didn't know about the start/step arguments of range, that's nice. I appreciate the info! Unfortunately my ATL transform needs floats, which I don't think works in this case, right?

What about the pythonic way of screen "add" - there must be a simple way to do something like that... I have to be missing something obvious.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Python - renpy.render(?) for Screen Add functionality

#4 Post by Ocelot »

What exactly is that everchanging number in transforms?
add is a proper way to add arbitrary displayables without defined behavior to the screen, but if you are using transforms to position elements, you might want to look at screen containers, like vbox
< < insert Rick Cook quote here > >

awonderL
Newbie
Posts: 6
Joined: Sun Nov 28, 2021 1:29 am
Contact:

Re: Python - renpy.render(?) for Screen Add functionality

#5 Post by awonderL »

Ocelot wrote: Fri Jan 28, 2022 5:51 am What exactly is that everchanging number in transforms?
add is a proper way to add arbitrary displayables without defined behavior to the screen, but if you are using transforms to position elements, you might want to look at screen containers, like vbox
So I'm using like fifty different vboxes/hboxes in my other scripts/screens, and it never occured to me to use one in this case - which with some modifications, will suit my needs.

Still, my original question and reason for posting this topic remains.

I know "add" is the proper way to add arbitrary displayables to the screen, that's exactly what I'm wanting to do within a python function. I want the "add" functionality/simplicity or something close in functionality/simplicity to use within a function. I assume something close to that is possible, I just don't know of it.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Python - renpy.render(?) for Screen Add functionality

#6 Post by Ocelot »

1) Create a Creator-Defined Displayable, which will take images as children, wrap them in either Transform or At, and the blit them into own canvas in desired positions.

2) Similar to (1), but don't create a displayable. Let your function return a list of Displayables: your images with transform applied. Then you can simply do:

Code: Select all

def get_displayable_list:
    result = []
    result.append( At("iamge1.png", my_cool_transform) )
    # . . .
    return resilt

# . . .
screen some_screen():
    # . . .

    # Maybe populate list outside of screen...
    $ displayable_list = get_displayable_list()
    for disp in displayable_list:
        add disp
3) Define screen directly in Python. Not recommended, deprecated, might be removed in future versions.
https://www.renpy.org/doc/html/screen_python.html
< < insert Rick Cook quote here > >

awonderL
Newbie
Posts: 6
Joined: Sun Nov 28, 2021 1:29 am
Contact:

Re: Python - renpy.render(?) for Screen Add functionality

#7 Post by awonderL »

So I figured it out, finally.

I just fussed with renpy.show in like 20 different ways and finally managed to get it to work.

layer='screens' was needed over layer='master', because I thought master was above all other layers and I had a screen showing at the time. I'm an idiot!

Post Reply

Who is online

Users browsing this forum: No registered users