How do I transfer held image variable into another image variable

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
jac600
Newbie
Posts: 17
Joined: Thu Apr 19, 2018 5:04 pm
Github: Dalton
Soundcloud: White
Contact:

How do I transfer held image variable into another image variable

#1 Post by jac600 »

Howdy! My friend is working on a project that is trying to display images using variables. But in the following code this does not display at all. With the problem displayed very simply.

x = image1
y = x
output y, show image 1

So how does he get the images to properly display?


label start:
# Initial Declaration
image player_initiative_token = "init_head_4.png"

# Transfer From Declaration To Neutral Variable (Does Not Work, Says 'player_initiative_token' Is Undefined.
image initiative_filler = player_initiative_token

# Transfer From Declaration To Neutral Variable Alternative (Does Not Work, Thinks "player_Initiative_token" Is The Image.
image initiative_filler = "player_initiative_token"
return

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: On RPG Style Initiative System

#2 Post by Alex »

What are you trying to achieve?
Some tips:
- image statement is used to declare displayables.
- all the declarations (default/define values for variables, images, screens) are execute befor start of the game no matter where you placed them in script.
So check the tutorial that ships with the engine, some documentation and script samples to fix your code.
https://www.renpy.org/doc/html/index.html
https://www.renpy.org/doc/html/index.ht ... le-scripts

If you need a dynamic image check this
https://www.renpy.org/doc/html/displaying_images.html
https://www.renpy.org/doc/html/displaya ... splayables
https://www.renpy.org/doc/html/changelo ... mic-images
viewtopic.php?f=51&t=19063#p246889

jac600
Newbie
Posts: 17
Joined: Thu Apr 19, 2018 5:04 pm
Github: Dalton
Soundcloud: White
Contact:

Re: How do I transfer held image variable into another image variable

#3 Post by jac600 »

Hi there, thanks for the quick response again Alex, this is a message he wanted me to send you back. Says he's going for a image held in variable he can transfer to other variables

Basically, if I have
image player_initiative_token = "init_head_4.png"
image player_initiative_coin = "init_head_5.png"

image initiative_filler = player_initiative_token
show initiative_filler

Then I want "init_head_4.png" to show up.

image initiative_filler = player_initiative_coin
show initiative_filler

Then I want "init_head_5.png" to show up.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How do I transfer held image variable into another image variable

#4 Post by kivik »

Sounds like he just wants to do dynamic images by using variables to alter the image being shown?

If that's the case, this may be easier:

Code: Select all

image player_head = "init_head_[filler].png"
default filler = "4" #make sure this is string

label start:
    show player_head # shows init_head_4.png
    filler = "5" # immediately changes head to init_head_5.png
I could be mistaken, but the image declaration statement isn't python:

Code: Select all

image player_initiative_token = "init_head_4.png"
Does not equal to:

Code: Select all

$ player_initiative_token = Image("init_head_4.png")
What's actually happening is:

Code: Select all

$ renpy.image("player_initiative_token", "init_head_4.png")
Consider this: You can define images with spaces:

Code: Select all

image eileen = "eileen.png"
image eileen happy = "eileen_happy.png"
There isn't a variable called "eileen happy" with the image stored inside. It's just that there's now a renpy image with the name "eileen happy" with tag "eileen" automatically created.

It can be a bit confusing but anything that's renpy specific language do not behave like python language, and note that any variable declarations within renpy are done with $ (python statement prefix), except for the "default" and "define" statements. So hopefully it'll make sense to your friend soon.

Overall I think what he wants is to look into dynamic images: https://www.renpy.org/doc/html/changelo ... mic-images

jac600
Newbie
Posts: 17
Joined: Thu Apr 19, 2018 5:04 pm
Github: Dalton
Soundcloud: White
Contact:

Re: How do I transfer held image variable into another image variable

#5 Post by jac600 »

Great Kivik! So the issue got fixed but a certain part of the problem wasen't covered with your solution. My friend was able to make a work around with your solution.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: How do I transfer held image variable into another image variable

#6 Post by kivik »

I think it's best for your friend to start at a higher level with his questions - as the questions are very specific and detailed, and there may actually be much simpler solutions to his problems if he lets us know the broader picture of what he's trying to achieve.

Sounds like he's making progress but just tell him to bear that in mind :)

Post Reply

Who is online

Users browsing this forum: Google [Bot]