Simple password
Code: Select all
init:
$ door_pass = "12345"
label start:
"In order to open the door you need to know the password."
$ user_pass = renpy.input(u"Enter the password (5 characters)", "00000", length = 5)
if user_pass == door_pass:
jump open_door
else:
"Mistake"
jump start
Code: Select all
$ available_passwords = [Oak, Aspen, Poplar, Birch, Spruce, Pine, Cedar, Hornbeam]
Code: Select all
$ available_passwords = [str(renpy.random.randint(1000, 9999)) for i in range(10)]
str (blabla) - a function to convert a number to a string. The fact is that the value of a menu item can only be a string.
The number 1000 is an inappropriate option, but the string "1000" is a suitable
range (10) - a list of numbers from 0 to 9
for i in something is a cycle in which all the values from this “something” are written alternately in variable i. In our case, the numbers 0, 1, 2, ..., 8, 9 will be alternately written into the variable i.
2. Now we randomly select one of our passwords, which will be correct in this game launch.
Code: Select all
$ correct_password = renpy.random.choice(available_passwords)
Code: Select all
label start:
"In the cracked safe there was only a small piece of paper. "
"It was written that the password for today is [correct_password]. "
"Well, that will be very useful for me!"
Code: Select all
$ answer = renpy.display_menu([(x,x) for x in passwords])
Code: Select all
if answer == correct_password:
"The guard smiled and opened the door for me."