About ImageReference()

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
deltazechs
Newbie
Posts: 16
Joined: Thu Nov 16, 2006 2:10 pm
Contact:

About ImageReference()

#1 Post by deltazechs »

Can someone explain the function, ImageReference() to me? I read up on it in the reference section, but still couldn't really comprehend its function

Does this mean that I can initiate a variable called placeholder and use it to "represent" any images that I declared earlier in the init block?

$ placeholder = ImageReference("name of file")

If that is the case, would performing a move operation on placeholder actually move the image I want on the screen? Thanks for answering my question.
"Darker than a moonless night, hotter and more bitter than hell itself. That is coffee." --- Godot, Phoenix Wright Ace Attorney: Trials and Tribulations

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: About ImageReference()

#2 Post by PyTom »

It would normally be used the other way. For example, say you declared an image elsewhere in the file. You could then use the image in a python expression using ImageReference. Example:

Code: Select all

image eileen happy = "eileen_happy.png"
image eileen vhappy = "eileen_vhappy.png"

image eileen animation = Animation(ImageReference("eileen happy"), 1, ImageReference("eileen vhappy", 1)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

deltazechs
Newbie
Posts: 16
Joined: Thu Nov 16, 2006 2:10 pm
Contact:

Re: About ImageReference()

#3 Post by deltazechs »

Ah, I understand now. Thanks for clearing that up.
"Darker than a moonless night, hotter and more bitter than hell itself. That is coffee." --- Godot, Phoenix Wright Ace Attorney: Trials and Tribulations

herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

Re: About ImageReference()

#4 Post by herenvardo »

I want to mention two separate things:
1st, and most relevant, I have added that example to the wiki page at http://www.renpy.org/wiki/renpy/doc/ref ... eReference.
BTW, I just noticed a minor glitch in the code: there are three "("s but only two ")"s. You know, that's the kind of thing that happens when you write code on the fly; and tends to crash a parser crying about some parsing or syntax error. I guess the correct code would be:

Code: Select all

image eileen animation = Animation(ImageReference("eileen happy"), 1, ImageReference("eileen vhappy"), 1)
2nd, quite pulling this thread to a reverse: is there any way to achieve the opposite? I'd like to be able to make arbitrary displayables (often attributes or properties of a custom class's instance) available to scene and show statements.
For example, having something like that:

Code: Select all

# somewhere in an init python block:
    class Dungeon:
        # lots of irrrelevant stuff here
        def __init__(self, lots_of_arguments_here):
            # more irrelevant stuff here
            self.sprites = whatever # a dictionary or similar thing, including at least a "entrance" key.
# later on, still on some init python block:
    myDungeon = Dungeon(lots_of_stuff_here)
# finally, somewhere in the game script:
    scene myDungeon entrance
Of course, I know I'd have to tweak the Dungeon class; but before I start messing up with that, It'd be good to know if there is at least any hope in what I'm trying; and also to get some idea of what should I do on the code to actually achieve it (for example, should I emulate dictionary behavior on the Dungeon class?). Any hint on this would be appreciated ^^.
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: About ImageReference()

#5 Post by PyTom »

You can use an arbitrary displayable in a scene or show statement using "show expression".

Code: Select all

scene
show expression myDungeon.entrance
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

Re: About ImageReference()

#6 Post by herenvardo »

As usual, things are far simpler than what I could expect ^^;

However, I have some concerns about image tags once I start trying to use this with my Creature objects (the Dungeon was the simplest of my use cases, after all). I have already checked the docs and fount about the "as" clause, but I'm wondering:
1: what should be given as an image tag? A string? any object? an instance of some obscure type normally handled by the image statement? something else?
In other words, would something like this work (assume the obvious meanings for the attributes):

Code: Select all

show expression myCreature.sprites["happy"] as myCreature.name
?
If it works, do I really need to use the creature's name as the tag, or can the Creature object itself be used?

2: Assumming the above (or something similar enough) works, I was hoping to be able to make something like this work:

Code: Select all

show myCreature happy
The idea would be that, simetrically to how I made my Creature objects to pass as Characters, to make them also pass as image declarations. I'm not sure if this is doable at all; and I can live without it (after all, it's just syntax sugar); but I'd like to "centralize" the mess ups I'm doing in my code in a single place (in this case that would be the class definition), where I can document it with some comments, than having weird-looking statements throughout the entire script.
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: About ImageReference()

#7 Post by PyTom »

The as clause takes a name, which is a literal identifier token. If you want to use a computed name, you can use the renpy.show function.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

deltazechs
Newbie
Posts: 16
Joined: Thu Nov 16, 2006 2:10 pm
Contact:

Re: About ImageReference()

#8 Post by deltazechs »

Ok, I think I ran into this problem:

Can you actually declare an 'image' statement inside a python? I think it threw me errors if I write something like:

Code: Select all

python:
              image placeholder = ImageReference(icon)
I placed this code at some later point in the middle of my script. I am certain that I had already declared icon as an image inside my init block. Does this mean that python cannot accept image declarations inside itself?

I am doing this because placeholder is an image that's going to switch back and forth between a lot of different icon images.
"Darker than a moonless night, hotter and more bitter than hell itself. That is coffee." --- Godot, Phoenix Wright Ace Attorney: Trials and Tribulations

deltazechs
Newbie
Posts: 16
Joined: Thu Nov 16, 2006 2:10 pm
Contact:

Re: About ImageReference()

#9 Post by deltazechs »

Ah, nevermind, it looks like this problem can be solved with dynamic displayable and ConditionSwitch
"Darker than a moonless night, hotter and more bitter than hell itself. That is coffee." --- Godot, Phoenix Wright Ace Attorney: Trials and Tribulations

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: About ImageReference()

#10 Post by PyTom »

You could also use [func]renpy.image[/url], which is the programmatic version of an image statement.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: henne