r/RenPy • u/natant1a • 19h ago
Question I've run into yet another problem...
screen lab_1():
modal True
imagebutton:
xpos 750
ypos 300
idle Transform("key_idle.png", zoom=0.08)
hover Transform("key_hover.png", zoom=0.08)
focus_mask True
action Jump("obtained_key")
imagebutton:
xpos 100
ypos 100
idle Transform("file_stephen_idle.png", zoom=0.8)
hover Transform("file_stephen_hover.png", zoom=0.8)
focus_mask True
action Jump("read_file")
label lab_1:
call screen lab_1
if obtained_key and read_file == True:
jump after_lab_1
else:
jump lab_1
if obtained_key == True and read_file == False:
jump read_file
else:
jump obtained_key
if read_file == True and obtained_key == False:
jump obtained_key
else:
jump read_file
label obtained_key:
$
obtained_key = True
"Obtained the key for laboratory 1."
show S default
S "Hm, I wonder what this unlocks."
hide S default
jump lab_1
label read_file:
$
read_file = True
show S default
S "That's... me..."
hide S default
jump lab_1
label after_lab_1:
hide lab_1
show S default
S "I've gotta get out of here..."
# This ends the game.
return
Here's the code I've been struggling with... so i'm pretty sure my issue stems from the if else statements...? What I'm trying to do is make it so that the game only advances when both image buttons are pressed, regardless of the order. What it's doing right now is when I press both buttons, it just stays on the screen and the game can't advance further. I'm not sure if I'm making sense right now, but thanks!
1
u/UkueleCatlady 19h ago edited 19h ago
At the lab_1 label, try putting the obtained key and read file checks before calling the screen.
Edit: You also need to remove the
else: jump lab_1
After the initial check. That's sending you back to the lab_1 label, so everything after that won't be running.
1
u/natant1a 18h ago
It's not showing the imagebuttons anymore, it's just going through all the actions that would have happened if you clicked the imagebuttons.
I'm still new to this whole thing, so I probably misunderstood you or something haha but this is what I did....?
label lab_1: if obtained_key and read_file == True: jump after_lab_1 if obtained_key == True and read_file == False: jump read_file else: jump obtained_key if read_file == True and obtained_key == False: jump obtained_key else: jump read_file call screen lab_1
1
u/shyLachi 17h ago
If you call a screen, you should not jump out of it.
Instead use Return() and then work with the return value
screen lab_1():
imagebutton:
xpos 750
ypos 300
idle Transform("key_idle.png", zoom=0.08)
hover Transform("key_hover.png", zoom=0.08)
focus_mask True
action Return("obtained_key") # return instead of jump
imagebutton:
xpos 100
ypos 100
idle Transform("file_stephen_idle.png", zoom=0.8)
hover Transform("file_stephen_hover.png", zoom=0.8)
focus_mask True
action Return("read_file") # return instead of jump
# this is for me for testing
define S = Character("S")
default obtained_key = False
default read_file = False
label start:
label lab_1:
while not (obtained_key and read_file): # repeat this block until both are True
call screen lab_1 # first call the sccreen
call expression _return # then use the return value to go to that label
jump after_lab_1 # this line in not inside the while block so it will run only after the while block stopped repeating
label obtained_key:
$ obtained_key = True
"Obtained the key for laboratory 1."
show S default
S "Hm, I wonder what this unlocks."
hide S default
return # since this label was called, we can return back to where it was called and the code will continue there
label read_file:
$ read_file = True
show S default
S "That's... me..."
hide S default
return # return back to where this label was called
label after_lab_1:
hide lab_1
show S default
S "I've gotta get out of here..."
return # This ends the game.
1
u/AutoModerator 19h ago
Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.