Page 1 of 1
If X does not equal Y, go back to question.
Posted: Mon Oct 21, 2013 6:40 pm
by Jengo
((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.
Re: If X does not equal Y, go back to question.
Posted: Mon Oct 21, 2013 7:25 pm
by jesusalva
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
There is a simple code.
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...
Re: If X does not equal Y, go back to question.
Posted: Mon Oct 21, 2013 8:53 pm
by Jengo
Thank you kindly, Jesusalva!
Re: If X does not equal Y, go back to question.
Posted: Tue Oct 22, 2013 4:51 am
by Elmiwisa
Uh, I think the OP is asking for
go back to question, not quit the game.
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..."
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.
Re: If X does not equal Y, go back to question.
Posted: Tue Oct 22, 2013 12:15 pm
by jesusalva
Uh, I think the OP is asking for go back to question, not quit the game.
Sorry,
Elmiwisa, but I've included one that don't quit the game. It is the last example.
Yeah, using a while statement is easier than using my example. It take less lines. How could I forgot about while loop?
I'm using so much the “if” statement in my project (because WHILE is not working and FOR is too hard to I use it (In my case, yeah, it is. Maybe because I'm just doing the last thing that you would do with renpy?)) That the first think that come in my mind is the if statement. (and sorry for not putting it into past.)Just some
deadly explanation about why I used if statement instead while.
Re: If X does not equal Y, go back to question.
Posted: Wed Oct 23, 2013 1:45 am
by Elmiwisa
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.
Re: If X does not equal Y, go back to question.
Posted: Tue Oct 29, 2013 2:27 pm
by jesusalva
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 a
improved revision without the 'safe-guards' (I doubt that someone would use that, but...)
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...