Help on Very Simple Gallery Code

DoctorPervic

Well-Known Member
Game Developer
Aug 13, 2019
1,082
4,430
Hi, Im a noob developer of a game.
I wanted a very simple gallery code to use for displaying HD renders for anyone who is playing my game and reaches a specific place in my game and unlocks a gallery.

So I am using the code got from here.



It is great and works perfectly. However there are a few things I wanted to change but I do not know how. I have tried to figure it out but cant seem to find a solution, so if there is someone on here who can help, I would be very grateful.

The Gallery code I used is below.
_________________________________________________________________________

#REMINDERS.
#PLACE THIS CODE INTO ANY PART OF YOUR SCRIPT TO UNLOCK A GALLERY IMAGE. REMEMBER TO CHANGE THE NAME FROM end1 to end2 or end3 ect...
#$ persistent.end1 = True



init python:

# Step 1. Create the gallery object.
g = Gallery()


# This button has a condition associated with it, allowing the game
# to choose which images unlock.
g.button("end1")
g.condition("persistent.end1")
g.image("images/gallery/end1.jpg")

g.button("end2")
g.condition("persistent.end2")
g.image("images/gallery/end2.jpg")

g.button("end3")
g.condition("persistent.end3")
g.image("images/gallery/end3.jpg")

g.button("end4")
g.condition("persistent.end4")
g.image("images/gallery/end4.jpg")

g.button("end5")
g.condition("persistent.end5")
g.image("images/gallery/end5.jpg")

g.button("end6")
g.condition("persistent.end6")
g.image("images/gallery/end6.jpg")




# Step 3. The gallery screen we use.
screen gallery:

# Ensure this replaces the main menu.
tag menu

# The background.
add "images/gallery/background.jpg"

# A grid of buttons.
grid 3 3:

xfill True
yfill True

# Call make_button to show a particular button.
add g.make_button("end1", "images/gallery/endsmall1.jpg", locked = "images/gallery/lock.png", xalign=0.5, yalign=0.5)
add g.make_button("end2", "images/gallery/endsmall2.jpg", locked = "images/gallery/lock.png", xalign=0.5, yalign=0.5)
add g.make_button("end3", "images/gallery/endsmall3.jpg", locked = "images/gallery/lock.png", xalign=0.5, yalign=0.5)

add g.make_button("end4", "images/gallery/endsmall4.jpg", locked = "images/gallery/lock.png", xalign=0.5, yalign=0.5)
add g.make_button("end5", "images/gallery/endsmall5.jpg", locked = "images/gallery/lock.png", xalign=0.5, yalign=0.5)
add g.make_button("end6", "images/gallery/endsmall6.jpg", locked = "images/gallery/lock.png", xalign=0.5, yalign=0.5)




# The screen is responsible for returning to the main menu. It could also
# navigate to other gallery screens.

textbutton "Previous" action ShowMenu("gallery") xalign 0.5 yalign 0.5
textbutton "Next" action ShowMenu() xalign 0.5 yalign 0.5
textbutton "Return" action Return() xalign 0.5 yalign 0.5

_______________________________________________________________________________________

So my problem is that in this code, the gallery can only hold 6 images at a time, and I was wondering if I can change that to something else so I can add more. Also, the gallery images are spaced pretty far apart, and was wondering if I can have them closer.

Also when my main image is displayed in the gallery, the user can view it but if he clicks on the image it disappears and goes back to the gallery page, is it possible to give the viewer the option to download or save the image to his computer for displaying as a desktop background, I would like to give the player that option if they want.

Anyways, any help is greatly appreciated in this, and if it cant be done, I would like to know that also.

Thanks so much. :)
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,130
3,194
or this one here as well

 

DoctorPervic

Well-Known Member
Game Developer
Aug 13, 2019
1,082
4,430
You might want to look at the gallery code that I posted here:
https://f95zone.to/threads/code-for-gallery.37121/post-2422874

This combines both code similar to what you've done above, plus also making the gallery code "pageable."
Hi, thanks so much for your help. I am trying out your code sample first.

This is what I have in my gallery.rpy

______________________________________________

init python:
def gallery_thumbnail(thumbnail_name):
return im.FactorScale(thumbnail_name, 0.2)

image_gallery = Gallery()
image_gallery.transition = dissolve
image_gallery.locked_button = "gallery_locked_button"

image_gallery.button("slot01")
image_gallery.condition('renpy.seen_image("ch0d_1")')
image_gallery.unlock_image("ch0d_1")
image_gallery.unlock_image("ch0d_2")

image_gallery.button("slot02")
image_gallery.condition('renpy.seen_image("ch0d_1")')
image_gallery.unlock_image("ch0d_1")
image_gallery.unlock_image("ch0d_2")

image_gallery_buttons_pages = [
[
( "slot01", "Ch 1: Brad and Emily", "images/gallery2/ch0d_1.jpg" ),
( "slot02", "Ch 1: Parker and Becky", "images/gallery2/ch0d_2.jpg" ),
]
]
screen gallery_buttons(data):
for (name, title, thumbnail) in data:
if name:
vbox:
$ the_button = image_gallery.make_button(name, gallery_thumbnail(thumbnail))
add the_button
if image_gallery.buttons[name].check_unlock():
text title
else:
text ""
else:
text ""

screen gallery():
default page = 1
tag menu

use game_menu(_("Gallery"), scroll="viewport"):

style_prefix "gallery"

vbox:
xsize 940
ysize 500
label "Page [page]":
xalign 0.5
bottom_margin 10

grid 3 2:
style_prefix "gallery_slot"

xalign 0.5
yalign 0.5

xspacing 30
yspacing 20

use gallery_buttons(image_gallery_buttons_pages[page-1])

hbox:
style_prefix "page"

anchor (0.5, 0.0)
pos(0.5, 1.0)

spacing gui.page_spacing

if page > 1:
textbutton _("<") action SetScreenVariable("page", page - 1)
else:
textbutton _("<") action NullAction()

for i in range(1, len(image_gallery_buttons_pages) + 1):
textbutton "" action SetScreenVariable("page", i)

if page < len(image_gallery_buttons_pages):
textbutton _(">") action SetScreenVariable("page", page + 1)
else:
textbutton _(">") action NullAction()

style gallery_slot_text:
size 18
xalign 0.5
yalign 0.0

style gallery_button is button:
hover_background "#fff"

style gallery_button_text:
size 24
bold True
color "#fff"
hover_color "#000"
underline True

style gallery_button_current is button
style gallery_button_current_text is gallery_button_text:
underline False
hover_color "#fff"

________________________________________


I am getting an error right now that says.

```
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 316: is not terminated with a newline. (Check strings and parenthesis.)
textbutton _("Gallery") action [ShowMenu("gallery")

Ren'Py Version: Ren'Py 7.3.5.606
Wed Dec 02 09:31:56 2020
```

Can you help me understand what I must do? also if I got everything correct in your code sample.

I only am listing 2 images the same on each page, just as a test. after the gallery is working I will go ahead and att more images and change their names to be more aproperate.

any help is most appreciated.
 

DoctorPervic

Well-Known Member
Game Developer
Aug 13, 2019
1,082
4,430
Well i think I fixed the error. I just copied

textbutton _("Preferences") action ShowMenu("preferences")

To

textbutton _("Gallery") action ShowMenu("gallery")

and it worked, but now I have a new error

```

Exception: Grid not completely full.

My apologies, but I am a real noob at Python, still learning a lot of stuff.
 

DoctorPervic

Well-Known Member
Game Developer
Aug 13, 2019
1,082
4,430
I figured it out. :)
I needed to fill all the slots with none. like this

[
( "slot01", "Ch 1: Brad and Emily", "images/gallery2/ch0d_1.jpg" ),
( "slot02", "Ch 1: Parker and Becky", "images/gallery2/ch0d_2.jpg" ),
( None, None, None),
( None, None, None),
( None, None, None),
( None, None, None),
],
[
( None, None, None),
( None, None, None),
( None, None, None),
( None, None, None),
( None, None, None),
( None, None, None),
],
[
( None, None, None),
( None, None, None),
( None, None, None),
( None, None, None),
( None, None, None),
( None, None, None)
]
]
 

DoctorPervic

Well-Known Member
Game Developer
Aug 13, 2019
1,082
4,430
So what I need help with now, is how to unlock an image.
previously I would place this code in my script whenever I wanted a specific image to be unlocked.

$ persistent.ch0d_1 = True

can I still use it or is there a different code to use. thanks
 

Rich

Old Fart
Modder
Donor
Respected User
Game Developer
Jun 25, 2017
2,566
7,384
Glad you figured it out.

Note - when you post code, put [code] before it and [/code] after it. That way, the forum will format it properly, preserving indentation and the like. (Incorrect indentation is a common source of error in Renpy/Python)
 

Merizmare

Newbie
Game Developer
Nov 24, 2017
34
1,085
This must be a dead thread, but I'll try to ask.
My gallery code is very similar to the author's (we must have been watching the same guide). Can I make it so that the picture in my gallery changes depending on the player's choice?
For example in my VN, the player's choice:
*define one = False*
And depending on what choices the player makes in the game, the picture in the gallery slot changes to either one or the other.
Uh, I hope I explained it clearly. I am a so noob in ren'py, I would be extremely grateful if you would show me how to do it.
 
Last edited:

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,130
3,194
This must be a dead thread, but I'll try to ask.
My gallery code is very similar to the author's (we must have been watching the same guide). Can I make it so that the picture in my gallery changes depending on the player's choice?
For example in my VN, the player's choice:
*define one = False*
And depending on what choices the player makes in the game, the picture in the gallery slot changes to either one or the other.
Uh, I hope I explained it clearly. I am a so noob in ren'py, I would be extremely grateful if you would show me how to do it.
it's best that you created your own thread instead of hijacking someone else thread and that you give more information on what you are trying to do

no it will require you to use python 3 instead of using python 2

python 2 is required that you have more then the code that shown in the example of
like if and elif or else statements and class so it will become complicated to do so not in less you know what you are doing and what you want it to do

with python 3 you will be able to it better but I can't help you with it

it best for you to create you own gallery code that my best option for you, so that you understand it more
 
  • Like
Reactions: Merizmare