showing a scene with a variable scene image name

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
Pyro
Newbie
Posts: 22
Joined: Tue Feb 03, 2015 6:56 am
Tumblr: daily-dragon
Contact:

showing a scene with a variable scene image name

#1 Post by Pyro » Tue Feb 10, 2015 10:27 am

Hi guys
I just want to ask about using variables for scene image names.
My project has been getting quite large now so I want to bring things together into classes.

I have a particular environment object declared like this

Code: Select all

$Camp = Environment("Camp", renpy.image("bgCamp", "environments/camp.jpg"), 0, True, False)
I want to be able to do something like this

Code: Select all

scene Camp.background with dissolve
What would be the best way to go about this?

My environment class is defined like this

Code: Select all

class Environment: 
            def __init__(self, name, background, discoveryScore, discovered, visitable):
                self.name = name                        # The name of the environment
                self.background = background            # The background image
                self.discoveryScore = discoveryScore    # The score needed to discover the land
                self.discovered = discovered            # Wether the land has been discovered or not
                self.visitable = visitable              # If the land can be visited or not
                    
            # Discover the environment
            def discover(self):
                self.discovered = True
Thanks a lot!

User avatar
deliciumartis
Regular
Posts: 30
Joined: Mon Feb 09, 2015 11:32 am
Location: shadowland
Contact:

Re: showing a scene with a variable scene image name

#2 Post by deliciumartis » Tue Feb 10, 2015 11:01 am

I'm sure it's hamfisted, as opposed to elegant, but you could try adding:

Code: Select all

$ renpy.transition (dissolve)
$ renpy.pause (1)
before you call your scene in the script. That should force the dissolve transition and the pause should give it enough time to play before the scene loads.
"What bothers me is, nothin' does."
--The dixie flatline

Pyro
Newbie
Posts: 22
Joined: Tue Feb 03, 2015 6:56 am
Tumblr: daily-dragon
Contact:

Re: showing a scene with a variable scene image name

#3 Post by Pyro » Tue Feb 10, 2015 11:26 am

Hey there, thanks for the quick response.

Its not really the effect I was looking for help with, more actually getting the scene to show in the first place. I probably should have not included the effect in my example.

Currently if I use "Camp.background" in place of say "bgCamp" then I get an "end of line expected" error.

Code: Select all

File "game/scripts/chapters/Chapter 1/intro.rpy", line 10: end of line expected.
    scene Camp.background
              ^
I was wondering if there was an elegant way to use variables for the "scene" keyword/function.

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: showing a scene with a variable scene image name

#4 Post by PyTom » Tue Feb 10, 2015 11:33 am

perhaps:

Code: Select all

scene expression Camp.background with dissolve
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Pyro
Newbie
Posts: 22
Joined: Tue Feb 03, 2015 6:56 am
Tumblr: daily-dragon
Contact:

Re: showing a scene with a variable scene image name

#5 Post by Pyro » Tue Feb 10, 2015 11:53 am

Awesome, that sort of works!

If "Camp.background" contains a renpy.image() then I get a "Not a displayable: None" exception.
However. If I point it to something like "Camp.name" and make that the same as the graphic name then it will work.

So I am guessing

Code: Select all

scene XXX
wants XXX to be a string relating to a stored image rather than the image object itself.

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: showing a scene with a variable scene image name

#6 Post by PyTom » Tue Feb 10, 2015 2:19 pm

renpy.image returns None, it just registers the image name. If you make it an Image, that will work. (Using a string is better, since you generally don't want to use direct references to Images in code that will be saved.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: _ticlock_