If X does not equal Y, go back to question.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
If X does not equal Y, go back to question.
((That's the best way I could describe it in a title.))
I'm trying to figure out how to write a code that will only progress the story if you type in the right answer (for example, the combination for a safe to open it).
I figure this is going to end up being really simple.
I'm trying to figure out how to write a code that will only progress the story if you type in the right answer (for example, the combination for a safe to open it).
I figure this is going to end up being really simple.
- jesusalva
- Regular
- Posts: 88
- Joined: Mon Jul 22, 2013 5:05 pm
- Organization: Software in Public Interest, Inc.
- IRC Nick: jesusalva
- Github: pazkero
- itch: tmw2
- Location: Brazil
- Discord: Jesusalva#4449
- Contact:
Re: If X does not equal Y, go back to question.
Code: Select all
$ yourcode = "Null" #Start the name variable.
e "Fast, put the password! otherwise, us are doomed!"
$ yourcode = renpy.input("But... what is the password?") or "Null" # Call renpy.input to ask you.
if yourcode != "0xc4efe35": # Here, 0xc4efe35 is the password.
e "Wrong!" # If you failed.
show nuke
"Game Over."
return
else: # if the code is right
e "Right! us are safe!"
show joy
"Good ending."
return
return
the "!=" means different, while "==" means equal, in the "if" statement.
In your case, us should place in a label:
Code: Select all
$ yourcode = "Null" #Start the name variable.
e "Fast, put the password! otherwise, us are doomed!"
label password_hour:
$ yourcode = renpy.input("But... what is the password?") or "Null" # Call renpy.input to ask you.
if yourcode != "0xc4efe35": # Here, 0xc4efe35 is the password.
e "Wrong!" # If you failed.
e "Try again!"
jump password_hour # jump back.
return # just if it fail.
else: # if the code is right
e "Right! us are safe!"
pass # as it says... continue the label. In this case, it jump to "continuation" label, because it is under the code.
label continuation:
# History continues...
Jesusaves/Jesusalva
Re: If X does not equal Y, go back to question.
Thank you kindly, Jesusalva!
Re: If X does not equal Y, go back to question.
Uh, I think the OP is asking for go back to question, not quit the game.
Just use while statement.
For example:
That say, it's more polite to the player if you let them a way out rather than force a perpetual loop on those who didn't remember the password.
Just use while statement.
For example:
Code: Select all
$safe_password="password"
while safe_password!=renpy.input("Looks like it needs a password...",default=""):
"Nope, that one doesn't do it..."
- jesusalva
- Regular
- Posts: 88
- Joined: Mon Jul 22, 2013 5:05 pm
- Organization: Software in Public Interest, Inc.
- IRC Nick: jesusalva
- Github: pazkero
- itch: tmw2
- Location: Brazil
- Discord: Jesusalva#4449
- Contact:
Re: If X does not equal Y, go back to question.
Sorry, Elmiwisa, but I've included one that don't quit the game. It is the last example.Uh, I think the OP is asking for go back to question, not quit the game.
Yeah, using a while statement is easier than using my example. It take less lines. How could I forgot about while loop?
Jesusaves/Jesusalva
Re: If X does not equal Y, go back to question.
Oh right I am sorry, I did not read it carefully. But then, why would you put return in there if it will always jump before it get to that point? Also, why do you have to set yourcode to "Null"? I guess it's harmless, but it doesn't do anything either.
- jesusalva
- Regular
- Posts: 88
- Joined: Mon Jul 22, 2013 5:05 pm
- Organization: Software in Public Interest, Inc.
- IRC Nick: jesusalva
- Github: pazkero
- itch: tmw2
- Location: Brazil
- Discord: Jesusalva#4449
- Contact:
Re: If X does not equal Y, go back to question.
Sorry for not replying earlier, but, as you've said, them aren't nedeed.
I've put the 'return' command just-in-the-case that something goes wrong.
And, yes, setting 'yourcode' to 'Null' is not needed either. I've just placed it just-in-case that ren'py raise an error. I don't trust too much in ren'py, so, I always put 'safe-guards' in my script, to ensure that no error can happen while running the script code.
This is aimproved revision without the 'safe-guards' (I doubt that someone would use that, but...)
I've put the 'return' command just-in-the-case that something goes wrong.
And, yes, setting 'yourcode' to 'Null' is not needed either. I've just placed it just-in-case that ren'py raise an error. I don't trust too much in ren'py, so, I always put 'safe-guards' in my script, to ensure that no error can happen while running the script code.
This is a
Code: Select all
e "Fast, put the password! otherwise, us are doomed!"
label password_hour:
$ yourcode = renpy.input("But... what is the password?") or "Null"
if yourcode != "0xc4efe35":
e "Wrong!"
e "Try again!"
jump password_hour
else:
e "Right! us are safe!"
pass
label continuation:
# History continues...
Jesusaves/Jesusalva
Who is online
Users browsing this forum: Google [Bot], _ticlock_