[Question] Show image depend on variables

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
norrissang
Newbie
Posts: 4
Joined: Tue Jul 03, 2018 9:17 am
Contact:

[Question] Show image depend on variables

#1 Post by norrissang » Tue Oct 06, 2020 9:16 am

I just want to show image and number of it depend of variable like this

Code: Select all

image miko1 = "miko1.png"
image miko2 = "miko2.png"
image miko3 = "miko3.png"

default point = 0

menu:
	"This is good":
		point += 1    #at this time, point = 1
		show miko1
		# if point = 2, show miko2, if 3 show miko3		
the number at the last name of image equal number of variable to show
How to do that. thank you

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: [Question] Show image depend on variables

#2 Post by hell_oh_world » Tue Oct 06, 2020 9:43 am

Code: Select all

label start:
  show expression "miko{}".format(point)
or...

Code: Select all

label start:
  show expression "miko[point]"
i think both would work.
You might also want to make the image dynamic instead of going through all of that process.

Code: Select all

default point = 0
image miko = "miko[point].png"

label start:
  show miko
  $ point += 1
  show miko

User avatar
Oazu
Newbie
Posts: 11
Joined: Tue Aug 25, 2020 1:47 pm
itch: oazu
Location: USA
Contact:

Re: [Question] Show image depend on variables

#3 Post by Oazu » Tue Oct 06, 2020 10:10 am

Hopefully I'm understanding this correctly. It sounds to me like you want to make hotspots or image buttons. Something like this?
Image
If this is the idea then here is what I would do.
I would have two script files. (It probably can be done with 1 but I'm not sure...)

In the first where you start your game (script.rpy) you're going to want to call a screen to select Miko's image.

Code: Select all

label start:
    call screen miko_choice
In another script file, we'll call it miko.rpy, you'll define the miko image.

Code: Select all

init:
##I'm not sure if variable can be 0. On my dress up game I made 1 be the default and it has nothing shown for the image.
    default point = 0
    
image miko = Composite(
    (0, 0),
    (0, 0), "images/miko[point].png"
)

screen miko_choice():
##I'm not sure what modal does but it makes things work for me
    modal True
    
    imagemap:
        ground "images/mikochoices.png"

##You can get the hotspots by being in game and pressing Shift+D to bring up the Developer Menu. From there pick Image Location Picker and then your image that has all 3 miko's next to each other. Click and drag to make a box around each image. The hotspot will be automatically copied.
        hotspot(0, 0, 0) action SetVariable("point", 1), Jump("YourNextScene")
        hotspot(0, 0, 0) action SetVariable("point", 2), Jump("YourNextScene")
        hotspot(0, 0, 0) action SetVariable("point", 3), Jump("YourNextScene")
In theory the second action should work in that code? I'm not sure though... But hopefully you understand what I'm getting at.

Then we go back to script.rpy and put in our next label:

Code: Select all

label YourNextScene
    show miko:
        pos(0, 0)
    "This is good.")
Your image of Miko choices should have all buttons on one image like in the picture I posted at the beginning of the post. What we are doing is defining the area that we want to be a button with hotspot. The coordinates are the button area. And we tell it that we want to change the variable when we click on the image and then Jump to the next screen. The composite image makes it easy to make a sprite. I suppose you could also make composite images for Miko's expressions as well and just layer them on top of her base image.

Hopefully all of this helped? Let me know if I need to explain my idea more. I'm new to making ren'py games...

Post Reply

Who is online

Users browsing this forum: No registered users