Need a second set of eyes on my code. Trying to make buttons that switch screens.
Posted: Thu Mar 10, 2022 1:30 am
For my own education in Ren'Py, I'm coding a prototype that's supposed to advance one at a time through pages of images. (Currently, the images are represented by a placeholder called "squarey.png.") Like a gallery, but all the gallery tutorials I've seen use a list of different pages you can go to, rather than allowing the player to advance a page at a time.
The first screen below, callPageMain, appears as an icon during gameplay. You press the icon and it takes you to the "gallery" itself. This is working as intended.
The "gallery" consists of the screen pageMain for navigation ("Return," "Next" [next page], "Previous" [previous page]) and uses several screens (sheetOne, sheetTwo, sheetThree) in turn to display each page of images. Here's where the code doesn't work. The first page of images displays fine when the screen opens, but the button to advance doesn't work.
Also, mysteriously, the button to advance highlights properly when hovered-- but the button to dismiss the screen ("Return") does not highlight when hovered... though it still functions when pressed.
Code below. (Actual code contains proper indentations, which I don't know how to render on here.) If anyone can help me stop bashing my head against the wall, it'd be much appreciated.
image overlayBeige = Solid("F5F5DC")
screen callPageMain():
zorder 90
imagebutton:
hover "butty_hover.png"
idle "butty_idle.png"
xalign 1.0
yalign 0
action [Show("pageMain", transition=Dissolve(.2)), ToggleVariable("quick_menu", False)]
screen sheetOne():
tag menu
zorder 95
modal False
grid 2 2 at truecenter:
spacing 20
xspacing 100
image "squarey.png"
image "squarey.png"
image "squarey.png"
image "squarey.png"
screen sheetTwo():
tag menu
zorder 95
modal False
grid 2 2 at truecenter:
spacing 20
image "squarey.png"
image "squarey.png"
image "squarey.png"
image "squarey.png"
screen sheetThree():
tag menu
zorder 95
modal False
grid 2 2 at truecenter:
spacing 20
image "squarey.png"
image "squarey.png"
image "squarey.png"
text Null()
screen pageMain(passedPage="pageone"):
modal True
$currentPage = passedPage
zorder 100
add "overlayBeige"
sensitive True
if currentPage=="pageone":
use sheetOne
if currentPage=="pagetwo":
use sheetTwo
if currentPage=="pagethree":
use sheetThree
textbutton "Return":
align (.5,.9)
action [ToggleScreen("pageMain", transition=None), ToggleVariable("quick_menu", True)]
if currentPage=="pageone" or currentPage=="pagetwo":
textbutton "Next":
align (.75, .9)
if currentPage=="pageone":
action SetLocalVariable("currentPage","pagetwo")
if currentPage=="pagetwo":
action SetLocalVariable("currentPage","pagethree")
if currentPage=="pagetwo" or currentPage=="pagethree":
textbutton "Previous":
align (.25,.9)
if currentPage=="pagetwo":
action SetLocalVariable("currentPage","pageone")
if currentPage=="pagethree":
action SetLocalVariable("currentPage","pagetwo")
The first screen below, callPageMain, appears as an icon during gameplay. You press the icon and it takes you to the "gallery" itself. This is working as intended.
The "gallery" consists of the screen pageMain for navigation ("Return," "Next" [next page], "Previous" [previous page]) and uses several screens (sheetOne, sheetTwo, sheetThree) in turn to display each page of images. Here's where the code doesn't work. The first page of images displays fine when the screen opens, but the button to advance doesn't work.
Also, mysteriously, the button to advance highlights properly when hovered-- but the button to dismiss the screen ("Return") does not highlight when hovered... though it still functions when pressed.
Code below. (Actual code contains proper indentations, which I don't know how to render on here.) If anyone can help me stop bashing my head against the wall, it'd be much appreciated.
image overlayBeige = Solid("F5F5DC")
screen callPageMain():
zorder 90
imagebutton:
hover "butty_hover.png"
idle "butty_idle.png"
xalign 1.0
yalign 0
action [Show("pageMain", transition=Dissolve(.2)), ToggleVariable("quick_menu", False)]
screen sheetOne():
tag menu
zorder 95
modal False
grid 2 2 at truecenter:
spacing 20
xspacing 100
image "squarey.png"
image "squarey.png"
image "squarey.png"
image "squarey.png"
screen sheetTwo():
tag menu
zorder 95
modal False
grid 2 2 at truecenter:
spacing 20
image "squarey.png"
image "squarey.png"
image "squarey.png"
image "squarey.png"
screen sheetThree():
tag menu
zorder 95
modal False
grid 2 2 at truecenter:
spacing 20
image "squarey.png"
image "squarey.png"
image "squarey.png"
text Null()
screen pageMain(passedPage="pageone"):
modal True
$currentPage = passedPage
zorder 100
add "overlayBeige"
sensitive True
if currentPage=="pageone":
use sheetOne
if currentPage=="pagetwo":
use sheetTwo
if currentPage=="pagethree":
use sheetThree
textbutton "Return":
align (.5,.9)
action [ToggleScreen("pageMain", transition=None), ToggleVariable("quick_menu", True)]
if currentPage=="pageone" or currentPage=="pagetwo":
textbutton "Next":
align (.75, .9)
if currentPage=="pageone":
action SetLocalVariable("currentPage","pagetwo")
if currentPage=="pagetwo":
action SetLocalVariable("currentPage","pagethree")
if currentPage=="pagetwo" or currentPage=="pagethree":
textbutton "Previous":
align (.25,.9)
if currentPage=="pagetwo":
action SetLocalVariable("currentPage","pageone")
if currentPage=="pagethree":
action SetLocalVariable("currentPage","pagetwo")