[SOLVED] return Transform(self.path, size=(self.sizes)) + pos(self.x, self.y) ?

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

[SOLVED] return Transform(self.path, size=(self.sizes)) + pos(self.x, self.y) ?

#1 Post by span4ev » Sun Aug 14, 2022 11:31 pm

The documentation and lack of examples just kills me...

I sit and do not understand what syntax should be in case I want through a class
1. Display image
2. Apply Transform() to it
3. Apply pos() to it

(I removed redundant code from the example)

Code: Select all

class Hero:

    # Method for rendering an image through a class
    def draw(self):
        return Transform(self.path, size=(self.sizes))

    image hero.draw() 
Everything is working. But I need positioning, right? Because I will change it through class methods

Code: Select all

image hero.draw()       pos(hero.x, hero.y) # I add it in Renpy code
But I was able to use pos() in the class method itself. I tried different options

Code: Select all

def draw(self):
    return Transform(self.path, size=(self.sizes)) + pos(self.x, self.y)
and various other options, but I could not achieve the result

I thought you could use this:

Code: Select all

def draw(self):
    renpy.image(Transform(self.path, size=(self.sizes)), pos(self.x, self.y))
Naturally, this didn't work.

I tried searching on google. Not found. I looked in the documentation.
It seems that the documentation was created to troll people.
I have never found the answer I need there.

renpy.image(name, d)
Defines an image. This function is the Python equivalent of the image statement.

The name of the image to display, a string.
The displayable to associate with that image name.

They were too lazy to give a couple of lines with an example.
I don't even know how I can figure out how to put it into practice...

I have no idea what this means "d" is the path to the picture? Why is the name here?
It seems like the renpy.image() function should be like this:

Code: Select all

renpy.image(path_to_image, size)
# or perhaps something more powerful
renpy.image( "additional functions" (path_to_image, size))
renpy.image(Transform(path_to_image, size), pos(x, y)
but this function looks weird and weak
Then it was possible to use it in the functions and methods of the class.
A nightmare. Just a couple of lines of code with an example will solve the problem.
As usual, I hope for your knowledge and help, because I just do not know where and how to find a solution
Last edited by span4ev on Sat Oct 15, 2022 4:59 am, edited 1 time in total.

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

Re: return Transform(self.path, size=(self.sizes)) + pos(self.x, self.y) ?

#2 Post by enaielei » Mon Aug 15, 2022 1:44 am

Transform and any other Displayables all accepts the **properties parameter.
This parameter is commonly known as **kwargs (keyword arguments). **kwargs is just a dict, you can pass the dict through key1=value, key2=value or **dict syntax.
Now the Displayables' **properties is quite special since it's only meant for a dict that contains keys from style properties.

Code: Select all

Transform("#f00", xysize=(100, 100), pos=(0.5, 0.5))
# is the same as

Transform("#f00", **{"xysize": (100, 100), "pos": (0.5, 0.5)})
# is the same as

d = {"xysize": (100, 100), "pos": (0.5, 0.5)}
Transform("#f00", **d)
These things are python-related and you can study them in python's official documentation.
The displayable to associate with that image name.

I have no idea what this means "d" is the path to the picture? Why is the name here?
That pertains to the name that you designate when creating an image through the image statement.

Code: Select all

image some name that you can think = Transform("#f00", xysize=(100, 100), pos=0.5, 0.5))
label start:
some name that you can think that is the image name that the parameter d is talking about.
The name of the image to display, a string.
name should be the path to the image.

Basically, renpy.image is the python equivalent of the renpy image statement.
It allows you to define images just like the image statement through python.

Code: Select all

image some name that you can think = "image.png"
# is the same as

init python:
  renpy.image("image.png", "some name that you can think")
Additonally, if you ever see a child parameter in one of the Displayable classes or anything that's asking for a displayable it means it's asking for any valid expression that can evaluate to a Displayable object.
The following are valid.

Code: Select all

child="#f00"                                           # evaluates automatically to a Solid() displayable
child=Null()                                           # evaluates to a Null() displayable
child="image.png"                                      # evaluates to the path of the image
child="some name that you can think"                   # evaluates to the image name that you designated when defining through image statement
It's also documented here, as stated in the first few lines.
It seems that the documentation was created to troll people.
You're probably frustrated, but I don't think you really mean this.
Don't devalue the effort of the contributors, besides Ren'Py is an open source software everything was possible because of volunteerism and stuff.
We're all using it for free and these ppl have no obligation of providing us anything in the first place.

Posts: 102
Joined: Fri Jul 08, 2022 9:29 pm
itch: rpymc

Re: return Transform(self.path, size=(self.sizes)) + pos(self.x, self.y) ?

#3 Post by span4ev » Mon Aug 15, 2022 2:51 pm

enaielei wrote:
Mon Aug 15, 2022 1:44 am
First, I want to thank you for taking the time to explain in detail. Thank you very much!

So "d" is just **kwargs ? Oh my god, this is such a simple explanation, but I would never have figured it out from the documentation.

Now everything immediately became clear after your words.

Code: Select all

d = {
    'size' : (self.sizes),
    'pos'  : (self.x, self.y)

return Transform(self.path, **d)
Now it is clear why this option will not work:

Code: Select all

Transform(self.path, size=(self.sizes)) + pos(self.x, self.y)
Looking at this pattern

Code: Select all

Transform('images/' + name + '.png', size=(width, hight))    pos(pos)
# is the same as:

Transform('img_path', img_size=(couple))      pos(couple)
I didn't look at the Transform() function as a whole with positioning.
Transform() is separately in its own brackets, pos() is also separate. I thought that these are separate functions and they cannot be linked together, and I did not think that I could pass something to Transform () separated by commas, as you showed:

Code: Select all

return Transform(self.path, size=(self.sizes), pos=(self.x, self.y))
All I needed was a comma and "="... Oh my god... When someone explains it becomes so easy.

Thank you very much! Now I will apply this knowledge in solving other problems.

Yes, you are right, I was really very upset. For me, each task is a collision with insurmountable difficulties in solving this task.
Before creating a topic, I can search Google for answers for a couple of days and experiment. I get frustrated every time.
I know Python a little and I love it very much. Python is an amazing language, I love its syntax, concept and flexibility.
And renpai is a fairly simple game engine with a simple syntax.
It seems that the combination of python and Renpy should be very simple, and if you can write a neural network in python, then you can also write a simple output of the image Renpy.image(...)

But very often the solution is not obvious. The solution needs some syntax that is not in the documentation. In my last question, the person told me that there are no examples in the documentation, and many things are simply not described there, so you just need to know them or come to an understanding on your own.

I didn't mean to be rude. Of course, I understand that both Renpy and the documentation are all provided free of charge to people and devs are under no obligation to make the best documentation on the web. But still, sometimes it seems that devs are not so much interested in people understanding their language.

I mentioned this because I have a simple idea - to improve the documentation a bit so that it becomes easier for all other people to understand Renpy. I think everyone will like it if the documentation is more meaningful and informative, and there are real examples in it.
Documentation is just html code. It is not difficult to add a few examples to the html page. I think you will agree with me that this is a fairly simple fix.

But I am nobody. I'm not good with Renpy. I don't even know how to contact the Renpy authors. But I am sure that there are other people who know how to influence the situation. They can ask the right people to expand the documentation. They can prepare the necessary code so that the devs simply update the contents of the documentation pages.
This is not only about me, but also about thousands or tens of thousands of people who will be able to read more meaningful documentation. It's not just about today and tomorrow, but about years and decades, during which all people will be able to read meaningful documentation.
If you do it right now, then everyone will be fine.

I think a lot of the daily questions in this and other forums are related to the fact that the documentation does not have the right example. But to solve this problem and help all people at once - you don't need to add something to the game engine, decompile / compile, or anything so complicated. It's enough just to change the html code with CTRL+C and CTRL+V. Well, update the content of the site.

I saw other documentation and there was a similar situation. Often the documentation is more like a reference book to remind you what the thing does. But the documentation does not decompose the essence of this thing into atoms, so that everyone who reads the documentation understands it so well that he does not have any questions left.
As a result, the bulk of knowledge is in the head of hundreds of people who share it with those who are looking for answers to their questions. But those answers might be in the documentation. I just don't understand why the documentation is the way it is, because it could be done better. This will save a lot of people a lot of time. I'm just wondering why it's like this:

1. devs want simplicity and minimalism? They do not want to load the code with unnecessary information?
2. devs are busy with the engine itself and hundreds of tasks and they have no time to deal with documentation?
3. devs think this information is enough?
4. some other options.

Why do many documentations look like a reference book, but not a textbook?

I just want to make it clear that I'm talking not only about myself and not about my tasks, but about the entire community. And I'm not talking about the here and now, but about decades of using Renpy. The richer the documentation, the more games there will be in the gaming industry that will give us all pleasure. The easier it is to understand Renpy, the more people will be able to master it. Some people drop out of studying because it seems difficult to them, but these people can be very talented writers and artists and they could make masterpieces for the gaming industry.
But perhaps their thinking is arranged differently and it is difficult for them to understand the "dry", official, "serious" language of documentation. There are different types of thinking, different levels of perception of information. There are humanitarian education and technical. It is easier for people with a technical background to read documentation.

Post Reply

Who is online

Users browsing this forum: No registered users