Page 1 of 1
About ImageReference()
Posted: Sat Nov 01, 2008 10:28 pm
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.
Re: About ImageReference()
Posted: Sat Nov 01, 2008 10:31 pm
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)
Re: About ImageReference()
Posted: Sat Nov 01, 2008 10:33 pm
by deltazechs
Ah, I understand now. Thanks for clearing that up.
Re: About ImageReference()
Posted: Mon Nov 03, 2008 9:14 am
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 ^^.
Re: About ImageReference()
Posted: Mon Nov 03, 2008 9:53 am
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
Re: About ImageReference()
Posted: Mon Nov 03, 2008 2:37 pm
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:
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.
Re: About ImageReference()
Posted: Mon Nov 03, 2008 2:44 pm
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.
Re: About ImageReference()
Posted: Tue Nov 04, 2008 7:45 pm
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.
Re: About ImageReference()
Posted: Tue Nov 04, 2008 9:28 pm
by deltazechs
Ah, nevermind, it looks like this problem can be solved with dynamic displayable and ConditionSwitch
Re: About ImageReference()
Posted: Tue Nov 04, 2008 9:54 pm
by PyTom
You could also use [func]renpy.image[/url], which is the programmatic version of an image statement.