Hey, welcome to the forum!
First of all, it's really important that you differentiate these two operations:
Code: Select all
question1 = True
question1 == True
The first one with a single = sign assigns whatever's on the right to whatever's on the left of the operator.
The second one with two = signs is a comparison, it returns True or False depending on whether the statement evaluates to True. So your line:
Code: Select all
"Decision" if question1 = True and question2 = True and question3 = True:
needs to be
Code: Select all
"Decision" if question1 == True and question2 == True and question3 == True:
With that out of the way we can do the more advanced stuff!
Another cool feature of comparison operators, is that they do this:
Code: Select all
$ a = False
$ b = True
if a:
"a evaluated to True"
if b:
"b evaluated to True"
Output would be "b evaluated to True"
if variable_name is a shorthand for evaluating variables, it's the same as if variable_name == True - if the variable_name is a boolean value (True or False).
But what if it's not a boolean?
Code: Select all
python:
a = 0
b = 1
c = 2
d = ""
e = "Hello world!"
if a:
"a evaluated to True"
if b:
"b evaluated to True"
if c:
"c evaluated to True"
if d:
"d evaluated to True"
if e:
"e evaluated to True"
This will output b, c and e evaluated to True.
Now I've never asked what's really happening but I know it's what happens, so my way of understanding it is: if you put a variable on its own in an if statement, depending on the type of variable it is, it'll do different evaluations. So the above would be equivalent to:
Code: Select all
if a != 0:
"a evaluated to True"
if b != 0:
"b evaluated to True"
if c != 0:
"c evaluated to True"
if d != "":
"d evaluated to True"
if e != "":
"e evaluated to True"
For numbers, 0 returns False, everything else returns True (including negatives); strings, "" returns False, everything else returns True.
Why did I teach you this? Because we can use it to simplify your code. We'll now set the variables to 1:
Code: Select all
menu ask_witnesses:
"Question1":
$ question1 = 1
jump question1
"Question2":
$ question2 = 1
jump question2
"Question3"
$ question3 = 1
jump question2
Then we can do this:
Code: Select all
if question1 and not (question2 + question3):
detective "Hmm... suspicious"
if question1 and (question2 + question3) == 1:
detective "Hmm... really suspicious"
if question1 + question2 + question3 == 3:
detective "he's the culprit!"
You can work out the variations and the corresponding maths by adding your digits together. But also you can do something like this:
Code: Select all
# if question1 is True and any one or more of the other questions is True:
if question1 and question2+question3+question4:
Hope that's informative and will be helpful in the future!