How to make 2 copies of a gallery
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.
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.
-
staffofmagic
- Newbie
- Posts: 11
- Joined: Fri Sep 20, 2019 3:07 pm
- Contact:
How to make 2 copies of a gallery
Hello. I have a great gallery working on my game I am creating. However, I would like to create another gallery for a different purpose.
I would like to use the same gallery code I have for the use of displaying another type of gallery but I have a problem, every time I change the gallery code to fit the new gallery I get an error saying that it is not defined.
Here is my original gallery code.
###############GALLERY##################
init python:
# Step 1. Create the gallery object.
g = Gallery()
g.locked_button = "gallery/locked.png"
# Step 2. Add buttons and images to the gallery.
# A button that contains an image that automatically unlocks.
g.button("set1")
g.condition("persistent.unlock_1")
g.image("image1")
g.button("set2")
g.condition("persistent.unlock_2")
g.image("image1")
g.button("set3")
g.condition("persistent.unlock_3")
g.image("image1")
g.button("set4")
g.condition("persistent.unlock_4")
g.image("image1")
screen gallery:
# Ensure this replaces the main menu.
tag menu
# The background.
add "backgroundscifi"
# A grid of buttons.
grid 4 3:
xfill True
yfill True
# Call make_button to show a particular button.
add g.make_button("set1", "gallery/unlock1.png", xalign=0.5, yalign=0.5)
add g.make_button("set2", "gallery/unlock2.png", xalign=0.5, yalign=0.5)
add g.make_button("set3", "gallery/unlock3.png", xalign=0.5, yalign=0.5)
add g.make_button("set4", "gallery/unlock4.png", xalign=0.5, yalign=0.5)
add g.make_button("set5", "gallery/unlock5.png", xalign=0.5, yalign=0.5)
add g.make_button("set6", "gallery/unlock6.png", xalign=0.5, yalign=0.5)
add g.make_button("set7", "gallery/unlock7.png", xalign=0.5, yalign=0.5)
add g.make_button("set8", "gallery/unlock8.png", xalign=0.5, yalign=0.5)
add g.make_button("set9", "gallery/unlock9.png", xalign=0.5, yalign=0.5)
add g.make_button("set10", "gallery/unlock10.png", xalign=0.5, yalign=0.5)
imagebutton:
idle "gallery/page2.png"
action ShowMenu("gallery2")
xalign 0.5
yalign 0.5
imagebutton:
idle "gallery/main menu.png"
action Return()
xalign 0.5
yalign 0.5
screen gallery2:
# Ensure this replaces the main menu.
tag menu
# The background.
add "backgroundscifi"
# A grid of buttons.
grid 4 3:
xfill True
yfill True
# Call make_button to show a particular button.
add g.make_button("set11", "gallery/unlock11.png", xalign=0.5, yalign=0.5)
add g.make_button("set12", "gallery/unlock12.png", xalign=0.5, yalign=0.5)
add g.make_button("set13", "gallery/unlock13.png", xalign=0.5, yalign=0.5)
add g.make_button("set14", "gallery/unlock14.png", xalign=0.5, yalign=0.5)
add g.make_button("set15", "gallery/unlock15.png", xalign=0.5, yalign=0.5)
add g.make_button("set16", "gallery/unlock16.png", xalign=0.5, yalign=0.5)
add g.make_button("set17", "gallery/unlock17.png", xalign=0.5, yalign=0.5)
add g.make_button("set18", "gallery/unlock18.png", xalign=0.5, yalign=0.5)
add g.make_button("set19", "gallery/unlock19.png", xalign=0.5, yalign=0.5)
add g.make_button("set20", "gallery/unlock20.png", xalign=0.5, yalign=0.5)
imagebutton:
idle "gallery/page1.png"
action ShowMenu("gallery")
xalign 0.5
yalign 0.5
imagebutton:
idle "gallery/main menu.png"
action Return()
xalign 0.5
yalign 0.5
############################################################## END
I need help in understanding how to use this as a gallery for my main game alongside the current gallery that is there.
in my main menu I have this gallery accessed by
textbutton _("History") action ShowMenu("history")
textbutton _("Save") action ShowMenu("save")
textbutton _("Load") action ShowMenu("load")
textbutton _("Preferences") action ShowMenu("preferences")
textbutton _("Gallery") action ShowMenu("gallery")
Please correct me if I am wrong. but I was under the impression I need to make a copy of this current gallery and change it to something else like Race.rpy
then change the
# Step 1. Create the gallery object.
g = Gallery()
to
# Step 1. Create the gallery object.
r = Race()
and then create a new menu action in the screens list like this
textbutton _("Race") action ShowMenu("race")
and I did that but I get an error that says race is undefined.
Anyways any help is greatly apriciated. I know almost nothing about coding so I am pretty green in this.
thank you very much
I would like to use the same gallery code I have for the use of displaying another type of gallery but I have a problem, every time I change the gallery code to fit the new gallery I get an error saying that it is not defined.
Here is my original gallery code.
###############GALLERY##################
init python:
# Step 1. Create the gallery object.
g = Gallery()
g.locked_button = "gallery/locked.png"
# Step 2. Add buttons and images to the gallery.
# A button that contains an image that automatically unlocks.
g.button("set1")
g.condition("persistent.unlock_1")
g.image("image1")
g.button("set2")
g.condition("persistent.unlock_2")
g.image("image1")
g.button("set3")
g.condition("persistent.unlock_3")
g.image("image1")
g.button("set4")
g.condition("persistent.unlock_4")
g.image("image1")
screen gallery:
# Ensure this replaces the main menu.
tag menu
# The background.
add "backgroundscifi"
# A grid of buttons.
grid 4 3:
xfill True
yfill True
# Call make_button to show a particular button.
add g.make_button("set1", "gallery/unlock1.png", xalign=0.5, yalign=0.5)
add g.make_button("set2", "gallery/unlock2.png", xalign=0.5, yalign=0.5)
add g.make_button("set3", "gallery/unlock3.png", xalign=0.5, yalign=0.5)
add g.make_button("set4", "gallery/unlock4.png", xalign=0.5, yalign=0.5)
add g.make_button("set5", "gallery/unlock5.png", xalign=0.5, yalign=0.5)
add g.make_button("set6", "gallery/unlock6.png", xalign=0.5, yalign=0.5)
add g.make_button("set7", "gallery/unlock7.png", xalign=0.5, yalign=0.5)
add g.make_button("set8", "gallery/unlock8.png", xalign=0.5, yalign=0.5)
add g.make_button("set9", "gallery/unlock9.png", xalign=0.5, yalign=0.5)
add g.make_button("set10", "gallery/unlock10.png", xalign=0.5, yalign=0.5)
imagebutton:
idle "gallery/page2.png"
action ShowMenu("gallery2")
xalign 0.5
yalign 0.5
imagebutton:
idle "gallery/main menu.png"
action Return()
xalign 0.5
yalign 0.5
screen gallery2:
# Ensure this replaces the main menu.
tag menu
# The background.
add "backgroundscifi"
# A grid of buttons.
grid 4 3:
xfill True
yfill True
# Call make_button to show a particular button.
add g.make_button("set11", "gallery/unlock11.png", xalign=0.5, yalign=0.5)
add g.make_button("set12", "gallery/unlock12.png", xalign=0.5, yalign=0.5)
add g.make_button("set13", "gallery/unlock13.png", xalign=0.5, yalign=0.5)
add g.make_button("set14", "gallery/unlock14.png", xalign=0.5, yalign=0.5)
add g.make_button("set15", "gallery/unlock15.png", xalign=0.5, yalign=0.5)
add g.make_button("set16", "gallery/unlock16.png", xalign=0.5, yalign=0.5)
add g.make_button("set17", "gallery/unlock17.png", xalign=0.5, yalign=0.5)
add g.make_button("set18", "gallery/unlock18.png", xalign=0.5, yalign=0.5)
add g.make_button("set19", "gallery/unlock19.png", xalign=0.5, yalign=0.5)
add g.make_button("set20", "gallery/unlock20.png", xalign=0.5, yalign=0.5)
imagebutton:
idle "gallery/page1.png"
action ShowMenu("gallery")
xalign 0.5
yalign 0.5
imagebutton:
idle "gallery/main menu.png"
action Return()
xalign 0.5
yalign 0.5
############################################################## END
I need help in understanding how to use this as a gallery for my main game alongside the current gallery that is there.
in my main menu I have this gallery accessed by
textbutton _("History") action ShowMenu("history")
textbutton _("Save") action ShowMenu("save")
textbutton _("Load") action ShowMenu("load")
textbutton _("Preferences") action ShowMenu("preferences")
textbutton _("Gallery") action ShowMenu("gallery")
Please correct me if I am wrong. but I was under the impression I need to make a copy of this current gallery and change it to something else like Race.rpy
then change the
# Step 1. Create the gallery object.
g = Gallery()
to
# Step 1. Create the gallery object.
r = Race()
and then create a new menu action in the screens list like this
textbutton _("Race") action ShowMenu("race")
and I did that but I get an error that says race is undefined.
Anyways any help is greatly apriciated. I know almost nothing about coding so I am pretty green in this.
thank you very much
Last edited by staffofmagic on Tue Feb 16, 2021 3:32 pm, edited 1 time in total.
-
staffofmagic
- Newbie
- Posts: 11
- Joined: Fri Sep 20, 2019 3:07 pm
- Contact:
Re: How to make 2 copies of a gallery
Just another note to make myself more clear.
I want to have 2 galleries that work. One that is my main gallery and another one that will be used to display info about alien races in my game. I am creating a scifi game and want to have the user be able to access race info about many different races in the game, but I want it so I can only allow the user to unlock specific races if they meet them. I found out that I can do that very easily in a gallery, by using the $ persistent.unlock_1 = True
and that is why I want to create another gallery so I can do that with my alien races. I hope you can understand what I am trying to achieve. If not let me know and I will try to explain better. thank you
I want to have 2 galleries that work. One that is my main gallery and another one that will be used to display info about alien races in my game. I am creating a scifi game and want to have the user be able to access race info about many different races in the game, but I want it so I can only allow the user to unlock specific races if they meet them. I found out that I can do that very easily in a gallery, by using the $ persistent.unlock_1 = True
and that is why I want to create another gallery so I can do that with my alien races. I hope you can understand what I am trying to achieve. If not let me know and I will try to explain better. thank you
-
cheonbyeol
- Regular
- Posts: 37
- Joined: Thu Feb 04, 2021 9:04 am
- Contact:
Re: How to make 2 copies of a gallery
I think, you don't have the screen "race" defined. You could likely copy and modify the code for screen gallery.
To make a gallery for races, you can just do r = Gallery(), this will create a new object of class Gallery. Your original gallery g will stay intact, r will be like a clean slate independent copy, that you can fill up with different images.
Alternatively, you might be interested in this cookbook thread about creating an Encyclopedia. That may be better suited for the races if the info includes text rather than images!
Or you can do a more direct solution, create a simple screen and a few True/False persistent variables that control what text is shown there and what is not. (Let me know if you need help with that!)
Side note: you copied in a lot of code, which made the post look scary long, but most of the code, like defining each image of the gallery, we don't need to see to be able to help. Also, the forum editor allows you to format code, that also helps us with reading!
To make a gallery for races, you can just do r = Gallery(), this will create a new object of class Gallery. Your original gallery g will stay intact, r will be like a clean slate independent copy, that you can fill up with different images.
Alternatively, you might be interested in this cookbook thread about creating an Encyclopedia. That may be better suited for the races if the info includes text rather than images!
Or you can do a more direct solution, create a simple screen and a few True/False persistent variables that control what text is shown there and what is not. (Let me know if you need help with that!)
Side note: you copied in a lot of code, which made the post look scary long, but most of the code, like defining each image of the gallery, we don't need to see to be able to help. Also, the forum editor allows you to format code, that also helps us with reading!
Programmer @ Celestea Productions

NaNo demo out!
My code:
GalleryPlus - extending gallery functionality

NaNo demo out!
My code:
GalleryPlus - extending gallery functionality
-
staffofmagic
- Newbie
- Posts: 11
- Joined: Fri Sep 20, 2019 3:07 pm
- Contact:
Re: How to make 2 copies of a gallery
Hi, thank you so very much for your help.
I would like to try creating another gallery as you suggested first. So what I will do is make a copy of the current gallery but replace all the g. with r. and keep it as
r = Gallery(),
One thing though is how do I link to it via the main menu.
textbutton _("Gallery") action ShowMenu("gallery")
that is the code I use for accessing my main gallery.
If I do this
textbutton _("Alien Race") action ShowMenu("gallery")
It will just overight or cause problums to the main gallery? How do I create a main menu for accessing the new gallery without interfering with my current one.
I would like to try creating another gallery as you suggested first. So what I will do is make a copy of the current gallery but replace all the g. with r. and keep it as
r = Gallery(),
One thing though is how do I link to it via the main menu.
textbutton _("Gallery") action ShowMenu("gallery")
that is the code I use for accessing my main gallery.
If I do this
textbutton _("Alien Race") action ShowMenu("gallery")
It will just overight or cause problums to the main gallery? How do I create a main menu for accessing the new gallery without interfering with my current one.
-
cheonbyeol
- Regular
- Posts: 37
- Joined: Thu Feb 04, 2021 9:04 am
- Contact:
Re: How to make 2 copies of a gallery
So, uh. You sound quite confused, so let me try to explain how these things work. Will try to put it as simply as I can.
There are actually several things/several "layers" of code that make up the gallery.
For your first gallery, you already have:
There's g = Gallery(), a gallery object (a Python thing), that handles things "behind the scenes", so to speak.
Then you have screen gallery() (and also gallery2()), which is the screen that reads the contents from the gallery object g and displays them.
Then you have the button in the main menu: textbutton "Gallery" action ShowMenu("gallery"), that shows the gallery screen.
So, for the second gallery with the races, we kinda repeat the process, with new variables and screens, so we copy and do the same, but don't overwrite the original gallery.
We create another gallery object r = Gallery(). It's empty when you create it, so you have to fill this too, in the fashion
And then you have to create the screen to display this one, something like
Then in the menu you can add
and when you click it, it will show the screen races we created.
What you asked,
it wouldn't overwrite the original gallery. It would just make a button that reads "Alien race", but actually shows the original gallery.
There are actually several things/several "layers" of code that make up the gallery.
For your first gallery, you already have:
There's g = Gallery(), a gallery object (a Python thing), that handles things "behind the scenes", so to speak.
Then you have screen gallery() (and also gallery2()), which is the screen that reads the contents from the gallery object g and displays them.
Then you have the button in the main menu: textbutton "Gallery" action ShowMenu("gallery"), that shows the gallery screen.
So, for the second gallery with the races, we kinda repeat the process, with new variables and screens, so we copy and do the same, but don't overwrite the original gallery.
We create another gallery object r = Gallery(). It's empty when you create it, so you have to fill this too, in the fashion
Code: Select all
r.button("race1")
r.condition("persistent.unlock_race_1")
r.image("image_race_1")
# .... repeat as needed! Code: Select all
screen races():
tag menu
add "backgroundscifi"
grid 4 3:
xfill True
yfill True
add r.make_button("race1", "race1_thumbnail.png", xalign=0.5, yalign=0.5)
#this is where we are calling on the contents of r !
#the first string there is the button name, that's gotta be an existing one, look to the code box above!
#the second one is just the thumbnail to show when the image has been unlocked
#when you click the button, the game should display "image_race_1" that was previously assigned to the "race1" button! that's what r does.
# .... add more of those buttons as needed!
null #this can fill empty slots in the grid, because Ren'Py doesn't like unfilled grids.
#for example if you have a 4*3 grid, that's 12 slots, so if you have 7 races, you'll need 5 nulls.
#but you can also change the grid 4*2 or 3*3 to have less empty slots!
imagebutton:
idle "gallery/main menu.png"
action Return()
xalign 0.5
yalign 0.5
# this is the button to exit the screenCode: Select all
textbutton _("Alien Race") action ShowMenu("races")What you asked,
Code: Select all
textbutton _("Alien race") action ShowMenu("gallery")Programmer @ Celestea Productions

NaNo demo out!
My code:
GalleryPlus - extending gallery functionality

NaNo demo out!
My code:
GalleryPlus - extending gallery functionality
-
staffofmagic
- Newbie
- Posts: 11
- Joined: Fri Sep 20, 2019 3:07 pm
- Contact:
Re: How to make 2 copies of a gallery
Thank you so very much for helping me and explaining to me what is needed to do this. The gallery is working now alongside my original one.
thank you so very much for all your help.
I have learned a lot here and it will help me out greatly in the future. Thanks again
Acharya
thank you so very much for all your help.
I have learned a lot here and it will help me out greatly in the future. Thanks again
Acharya
-
cheonbyeol
- Regular
- Posts: 37
- Joined: Thu Feb 04, 2021 9:04 am
- Contact:
Re: How to make 2 copies of a gallery
Great to hear it's working, and you're welcome! 
Programmer @ Celestea Productions

NaNo demo out!
My code:
GalleryPlus - extending gallery functionality

NaNo demo out!
My code:
GalleryPlus - extending gallery functionality
Who is online
Users browsing this forum: No registered users