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.
I just discovered the blur function for images and want to apply it to all the backgrounds in my scenes once we get into a dialogue scene, but without having to set up code for each and every possible location. I keep all my backgrounds in a folder called 'bgs' in the image folder and they all follow the naming convention of 'bg LOCATIONNAME.jpg'. I thought I'd be clever and set up a variable called 'stloc' that would mirror that one variable aspect of the background naming convention , so it could just be plugged in to a bit of code like this:
And then just have 'storyback' as the image used for the scene. Of course, that doesn't work, returning '"OError: Couldn't find the file 'bgs/bg [stloc].jpg'."
If I do it for a specific image like the 'bedroom' location:
then it works fine, but of course then I'd have to code up a line for every background which seems excessive. So I think it's just how I incorporate that variable into the image file name on the blur, but I'm having trouble on figuring out the how of that. Help?
im.Blur does require a specific path for the image, so using image statement will not work, however if you use the same convention for all of your backgrounds, you could try something like this:
init python:
# A function that receives a string and optional xrad and yrad parameters, and returns a blurred image formatted with those
def bg_blur(img, xr=1.5, yr=None):
return im.Blur("bgs/bg {}.jpg".format(img), xr, yr)
Thanks for your help RicharDann, that works! Certainly more efficient than what I would have otherwise done, so you have my gratitude for that!
Is there any way to incorporate the 'location' variable into the expression you've come up with at all? I thought to use the same sort of code to add a blurred background of the current location when the player activates a cellphone interface, but I haven't succeeded with my 'trial and error' attempts (just runs into the same problem I had in the first place) and can't see anything in the documentation that jumps out as being useful in terms of that.