How to declare an extension as an image?

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
M0d1997
Newbie
Posts: 5
Joined: Tue Aug 24, 2021 4:34 am
Contact:

How to declare an extension as an image?

#1 Post by M0d1997 » Sat Aug 28, 2021 1:20 am

(This symbol (%) indicates an indentation)
Hey everyone! I'm creating a project, and what I'm trying to do is NOT have to write:

image charselect = Movie(size=(1920,1080), channel ="movie", play="movies/charselect.webm", loop=True)

over and over again.

The code I am using to accoplish this, is:

$ from os import listdir

$ for file in listdir("movies")
$ name = file.split(".")[0]
$ renpy.image(name, "movies"+file)

$ for file in listdir("movies")
$ name = file.split(".")[0]
$ renpy.image(name, "movies/fechap1"+file)

It was originally written to me like this:

$ from os import listdir:

(%) for file in listdir("movies")
(%) name = file.split(".")[0]
(%) renpy.image(name, "movies"+file)

(%) for file in listdir("movies")
(%) name = file.split(".")[0]
(%) renpy.image(name, "movies/fechap1"+file)

I can't, for the life of me, figure out where I'm going wrong. I keep getting the error "Invalid syntax:
for file in listdir("movies")

and I have no clue why! Anyone have any ideas?

P.S. This is my first post, apologies if I messed anything up!

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: How to declare an extension as an image?

#2 Post by hell_oh_world » Sat Aug 28, 2021 1:56 am

Use renpy.list_files.
Observe that renpy.image can only be called inside an init block and that the next parameter can be a displayable itself. In short, you can just do...

Code: Select all

init python:
  ...
  renpy.image("name", Movie(..., play="path.webm"))

M0d1997
Newbie
Posts: 5
Joined: Tue Aug 24, 2021 4:34 am
Contact:

Re: How to declare an extension as an image?

#3 Post by M0d1997 » Sat Aug 28, 2021 4:23 pm

I'm not fully understanding the code there, or in the renpy documentation to be honest.
According to the documentation, I could use


Code: Select all

renpy.list_files ("game/movies", common=True)
to list all the files in the directory "movies" correct? If thats the case, I think what you're saying is I can then use

Code: Select all

Init python:
	renpy.image ("movies", Movie("insertfilename", play="movies/charselect.webm", loop=True)
Right? If so, how does it define all of the files in "Movies" as images?

I guess, I'm saying I don't understand how this code block works, or how it would help define all of the webm files in a folder as images, so I can call them with the
scene command.

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: How to declare an extension as an image?

#4 Post by hell_oh_world » Sat Aug 28, 2021 7:13 pm

Returns a list of files, with / as the directory separator.

Code: Select all

init python hide:
  for f in renpy.list_files():
    parts = f.split("/")
    fparts = parts[-1].split(".")
    name, ext = " ".join(fparts[:-1]), fparts[-1]
    if ext.lower() == "webm": renpy.image(name, Movie(play=f)) # if your filename is like `name1.name2.name3.webm`, it should be declared as `image name1 name2 name3 = Movie(...)`
This example code should auto-declare all of your webm files as a Movie, using the name of the file.

M0d1997
Newbie
Posts: 5
Joined: Tue Aug 24, 2021 4:34 am
Contact:

Re: How to declare an extension as an image?

#5 Post by M0d1997 » Sat Aug 28, 2021 8:32 pm

That worked beautifully! I ran the code and commented out the code I was using before, and had no issues! One day I hope to get that good at coding. Later on, I'm probably going to pick it apart and see if I can understand it fully. If you need anything feel free to let me know, however unlikely it is I can help I'm willing to try!

Once more- THANK YOU SO MUCH!

Post Reply

Who is online

Users browsing this forum: Bing [Bot]