- May 24, 2018
- 74
- 181
i'm testing some script to make a script to read all images in a folder and put it in a .rpy script and maybe make some mod making more easy
throw this:
File "game/Mod.rpy", line 44: invalid syntax
f.write(f'image {image_name} = ')
Ren'Py Version: Ren'Py 6.99.13.2919
Code:
asset_folder = "Mods"
asset_extensions = (".png", ".jpg") # Add any additional image extensions here.
# Get a list of all image files in the asset folder and its subfolders.
image_paths = []
for root, dirs, files in os.walk(asset_folder):
for file in files:
if file.lower().endswith(asset_extensions):
image_paths.append(os.path.join(root, file))
# Create a dictionary of image names and lists of image paths.
images = {}
for image_path in image_paths:
image_name = os.path.splitext(os.path.basename(image_path))[0]
if image_name in images:
images[image_name].append(image_path)
else:
images[image_name] = [image_path]
# Write the images to a .rpy script.
with open("Mod_images.rpy", "w") as f:
for image_name, image_paths in images.items():
f.write(f'image {image_name} = ')
if len(image_paths) == 1:
f.write(f'"{image_paths[0]}"\n')
else:
f.write("[")
for image_path in image_paths:
f.write(f'"{image_path}", ')
f.write("]\n")
File "game/Mod.rpy", line 44: invalid syntax
f.write(f'image {image_name} = ')
Ren'Py Version: Ren'Py 6.99.13.2919