[Solved] Input menu, go to a new result?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
Post Reply
Message
Author
Rekoija
Newbie
Posts: 15
Joined: Wed Nov 20, 2019 3:19 pm
Contact:

[Solved] Input menu, go to a new result?

#1 Post by Rekoija » Sun May 24, 2020 7:22 am

Sorry for the vague title, not sure how to phrase it.
I already know which part breaks the code, but I don't know how to fix it... So lemme just show you and explain it.

label user123:

$ user1_input = renpy.input(prompt = "Input code. To leave, enter '0'", allow="1234567890")
$ user1_input = user1_input.lower().strip()
if user1_input == "": #This will happen if there's no input.
system "You need to actually write something..."
jump user123
if user1_input in ('0'):
jump user1

if user1_input == ('123') and x == False:
system "stuff is said"
$ x = True

elif user1_input == ('432'):
system "blergh"

elif user1_input == ('123','432'): # if you remove the '432' the code will work.
$ xyz = renpy.random.randint(1,3)
if xyz == 1:
system "more stuff is said"
if xyz == 2:
system "more stuff more stuff"
if xyz == 3:
system "this is more stuff being said"

jump user123



any help will be appreciated!
Last edited by Rekoija on Sun May 24, 2020 3:30 pm, edited 1 time in total.

User avatar
hell_oh_world
Veteran
Posts: 464
Joined: Fri Jul 12, 2019 5:21 am
Projects: The Button Man
Organization: NILA
Github: hell-oh-world
Location: Philippines
Contact:

Re: Input menu, go to a new result?

#2 Post by hell_oh_world » Sun May 24, 2020 7:42 am

are you trying to phrase in the elif something like this? `elif user1_input is equal to 123 or user1_input is equal to 432`? if that's the case you should use `or` to separate multiple conditions like that or create a tuple / list of choices and use `in` operator.

Code: Select all

default user1_input = "" # always default variables that you plan to change in different parts of your code. Nonetheless, always default your variables to be sure...
default x = False
default xyz = 0

label user123:

	$ user1_input = renpy.input(prompt = "Input code. To leave, enter '0'", allow="1234567890")
	$ user1_input = user1_input.lower().strip()

	if not user1_input: # the previous one is valid, but this one is much better to test if a string is empty.
		system "You need to actually write something..."
		jump user123

	if user1_input == '0': # changed from user1_input in ('0')
		jump user1

	if user1_input == '123' and not x: # not x is equivalent to x == False
		system "stuff is said"
		$ x = True

	elif user1_input == '432':
		system "blergh"

	elif user1_input in ('123','432'): # checks whether the input is within the tuples of codes 123 and 432, if true execute below
		$ xyz = renpy.random.randint(1,3)

	if xyz == 1:
		system "more stuff is said"
	elif xyz == 2:
		system "more stuff more stuff"
	elif xyz == 3:
		system "this is more stuff being said"

		jump user123

User avatar
gas
Miko-Class Veteran
Posts: 718
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Input menu, go to a new result?

#3 Post by gas » Sun May 24, 2020 11:44 am

The above code from hell_oh_world is correct, the expalantion is:

Code: Select all

elif user1_input == ('123','432'): # if you remove the '432' the code will work.
What you are asking this way if the input is TOTALLY EQUAL a tuple so made: ('123',432')
And it throw an error as your user_input1 is a single string, something like '123' or '571'.
To check if a string is legit on a numer of possible strings, you must check if that string is in the tuple.

This one, for example, check if the string is present in a list of 3 possible combinations.

Code: Select all

elif user1_input in ('123','432', 571'):
==============================
Conditionals Explained
(Small extra tutorial!)
The truth check ('if... something') work mostly this way.

IF {whatever follow} RETURN TRUE:

so you can check things based if they return true or false.

Code: Select all

default name = "Greg"
if name == "Gas":
The conditional return False, as 'name' is not equal 'Gas'. so the following block is not executed.

If 4/2 == 3: # is true that 4 divided by 2 is equal 3?
this will never pass the check, as the reply is False.

For booleans, a value that is False return false and a value that is True return true.

Code: Select all

$ default check = True
if check:
You don't need to check if a boolean is 'True' or 'False', python use the boolean flag to determine it.

if not check:
this one for example verifiy if the variable 'check' is not True, so if it's False

You can also quote functions directly and check if they return True.
if my_function(value =100):
In that case the condition is met if the function, after computing, return True.

And that's all about conditionals.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll be not notified about.

10 ? "RENPY"
20 GOTO 10

RUN

Rekoija
Newbie
Posts: 15
Joined: Wed Nov 20, 2019 3:19 pm
Contact:

Re: Input menu, go to a new result?

#4 Post by Rekoija » Sun May 24, 2020 2:44 pm

hell, you're a life saver for reals, thank you so much, I would've never figured this out on my own. MVP!
i really appreciate the help!

it took me a bit to understand, and i had to line it up next to my own code and try to figure out what you'd changed, but when i finally realized, wow. thank you thank you thank you xD

Post Reply

Who is online

Users browsing this forum: No registered users