- Sep 29, 2020
- 2
- 6
default persistent.gallery_elements = []
What bipedal posted also tracks with some important caveats:Python variables that are not changed before the game begins will not be saved.
Good work on that gallery implementation though.All data reachable through fields on persistent is saved when Ren'Py terminates, or when renpy.save_persistent() is called. Persistent data is loaded when Ren'Py starts, and when Ren'Py detects that the persistent data has been updated on disk.
As persistent data is loaded before init python blocks are run, persistent data should only contain types that are native to Python or Ren'Py. Alternatively, classes that are defined in python early blocks can be used, provided those classes can be pickled and implement equality.
That is expected, the gallery_elements member exists only within the persistent object, so that's only how it can be accessed.I could only access the gallery_elements list if I referred to it as persistent.gallery_elements.
label start:
$ persistent.gallery_elements.append(blah blah)
You don't need that.After that, we have a few utility methods for resizing the images (so that there is no need for separate image sizes for thumbnails and the high res image).
Frame
automatically resize the image for you.Also, Ren'py automatically create an image object with the name of all the images in "game/images" and its sub-directories ; unless the name is duplicated, then only the first one will be created. Therefore, you just need that :Code:image gallery_img_1 = max_scale("gallery/gallery_img_1.jpg") [...] image gallery_thumbnail_1 = min_scale("gallery/gallery_img_1.jpg", GALLERY_ELEMENT_WIDTH, GALLERY_ELEMENT_HEIGHT)
gallery_elements.append(GalleryElement(GALLERY_ITEM_NAME_1,["gallery_img_1", "gallery_img_1b"]))
Frame( gallery_elements[i].image_list[0], size=( GALLERY_ELEMENT_WIDTH, GALLERY_ELEMENT_HEIGHT) )
or directly gallery_elements[i].image_list[0]
.The objects are created at init time, therefore they'll not be saved.Python:# This block is responsible for declaring the elements which should be available in the gallery init python: gallery_elements = [] gallery_elements.append(GalleryElement(GALLERY_ITEM_NAME_1,["gallery_img_1", "gallery_img_1b"],"gallery_thumbnail_1")) gallery_elements.append(GalleryElement(GALLERY_ITEM_NAME_2,["gallery_img_2"],"gallery_thumbnail_2")) gallery_elements.append(GalleryElement(GALLERY_ITEM_NAME_3,["gallery_img_3"],"gallery_thumbnail_3"))
label start:
call initGallery
[...]
label initGallery:
python:
gallery_elements = []
gallery_elements.append(GalleryElement(GALLERY_ITEM_NAME_1,["gallery_img_1", "gallery_img_1b"],"gallery_thumbnail_1"))
gallery_elements.append(GalleryElement(GALLERY_ITEM_NAME_2,["gallery_img_2"],"gallery_thumbnail_2"))
gallery_elements.append(GalleryElement(GALLERY_ITEM_NAME_3,["gallery_img_3"],"gallery_thumbnail_3"))
return
Hmm.- I've tried putting the list into a "default" declaration as follows:
[...]
Shouldn't this produce the same result? I had zero success with this approach.
init
block.persistent
prefix, come from the fact that you don't verify it the list exist before creating it. Therefore, every time Ren'py is launched, it reset the said list ; things are persistent, as long as you don't write over them.init python:
if persistent.gallery_elements is None:
persistent.gallery_elements = []
persistent.gallery_elements.append(GalleryElement(GALLERY_ITEM_NAME_1,[...] )
[...]
This don't works with persistent values. Due to its destination, the object handling them is designed to never throw an1) Before actually initialiazing the list in a label, check if it already exists or not (hasattr()). You might be overwriting it without knowing it.
AttributeError
exception, therefore hasattr()
will always return True
.None
or not.Not sure if you've changed it, but the defaultIf anybody got any ideas for improvement and how to fix the spacing issues, please share so I can update the code.
Frame
style has a 6px padding (defined as Border in gui.rpy
if I recall correctly) that can mess it up if you're trying pixel-perfect UI. You're mixing two different things here. There'sNot sure if you've changed it, but the defaultFrame
style has a 6px padding (defined as Border ingui.rpy
Ah, right. That will teach me trying to read code snippets semi-awake.You're mixing two different things here. There'sYou must be registered to see the links, that was my advice, which is a displayable, and there'sYou must be registered to see the linkswhich is a screen statement and the one that have the padding.