Hey! I'm finally getting back into working on my game, and I figured that it might be an interesting idea to make it so the background image in my main menu cycles through different backgrounds in the game. I'm struggling a bit with accessing the folder and putting the list in my game. Here's a couple of methods that I tried:
Code: Select all
init python:
import os
path = 'images/bgs'
mmBackground = os.listdir(path)
imageIndex = random.randint(0,len(mmBackground)-1)
gui.main_menu_background = mmBackground[imageIndex]
screen main_menu():
The error here is:
Code: Select all
WindowsError: [Error 3] The system cannot find the path specified: u'images/bgs\\*.*'
So I figured that I just should've used a back slash instead of a forwards slash, but the new error only left me more confused.
Code: Select all
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: u'images\x08gs\\*.*'
...So, I tried something else.
Code: Select all
define mmBackgrounds = renpy.list_files('images/bgs')
define imageIndex = renpy.random.randint(0,len(mmBackgrounds)-1)
define gui.main_menu_background = mmBackgrounds[imageIndex]
screen main_menu():
Which was a little bit closer, I did
actually get to the main menu this time instead of the code aborting right away. However, it seems like it's just listing all the files in the game and not specifically the ones in that directory as I will occasionally get the error:
Code: Select all
Exception: Could not load image u'00compat.rpy': error ('Unsupported image format',)
Not always that specific file, but I am trying to get files
only in 'images/bgs'. This game is going to be released in multiple chapters that have to be installed, and I want to make sure new backgrounds still have the potential to load so I'd rather not manually input the whole list of images if I can avoid it.
Any help with whichever method would be appreciated, thank you!