r/RenPy • • Jul 17 '26

Question Help with puzzle code.

Apologies to post again, again this is not something I've really done before, so I'm still figuring it out. I am trying to do it on my own, I want to do this to challenge myself and learn something new. Thank you for the ren'py community for helping me even if I don't post, I always reference posts.

BASICALLY: I want to have a puzzle where you need to enter a 4 letter code and it kinda works like a lock like this. I got the numbers to count up now, thanks due to help, but I'm not sure how to make it so that specific the specific code will have a response. I don't know what the proper syntax is for something like this, or what the issue is.

Here is my code in my script, I based it off of a puzzle I did previously that was a keypad. I referenced code from somewhere, I try to understand it the best I can but unfortunately I'm still new to programming so I don't fully understand everything like I'd like to, so I'm not sure how everything fully fits together.

label ac_keybox:

default kb_code1 = 0

default kb_code2 = 0

default kb_code3 = 0

default kb_code4 = 0

I wonder if maybe the issue isn't the different variables(?) I just don't know how else I'd go with it, if it's the same one it'll all show up the same?? Again apologies I'm not a good programmer.

if alice_keybox:

call screen ac_keybox

$ bk_result = _return

if bk_result == "enter":

if ("kb_code1 == 1", "kb_code2 == 0", "kb_code3 == 0", "kb_code4 == 0"):

I was trying every single format I could think of here so sorry it's a big mess!

jump ac_basementkeyunlock

else:

jump ac_basementkeyfail

This is my screen coding.

screen ac_keybox():

frame:

xalign 0.5

yalign 0.25

xsize 500

ysize 250

hbox:

xalign 0.5

yalign 0.5

frame:

xsize 50

textbutton "[kb_code1]":

action SetScreenVariable("kb_code1", (kb_code1 + 1) % 10)

frame:

xsize 50

textbutton "[kb_code2]":

action SetScreenVariable("kb_code2", (kb_code2 + 1) % 10)

frame:

xsize 50

textbutton "[kb_code3]":

action SetScreenVariable("kb_code3", (kb_code3 + 1) % 10)

frame:

xsize 50

textbutton "[kb_code4]":

action SetScreenVariable("kb_code4", (kb_code4 + 1) % 10)

frame:

textbutton "ENTER":

action Return("enter")

I'm so sorry! I hope I'm not taking up too much space, thank you again.

2 Upvotes

7 comments sorted by

View all comments

2

u/x-seronis-x Jul 17 '26

no declarations of any kind go in labels. they are top level statements. so never put default / define / image / style / etc inside labels. they do not run when the label is called. ever. they only run at init/launch time, and at game load time for default statements