Logical Operators Part 2
Part of the Fundamentals section of Coddy's GDScript journey. Lesson 22 of 92.
A truth table lists the result of a logical operator for every combination of values.
and is true only when both values are true:
false and falseisfalsefalse and trueisfalsetrue and falseisfalsetrue and trueistrue
or is true when at least one value is true:
false or falseisfalsefalse or trueistruetrue or falseistruetrue or trueistrue
not takes one value and reverses it:
not trueisfalsenot falseistrue
For example, a player who carries a bow but no sword:
var has_sword := false
var has_bow := true
print(has_sword or has_bow) # true
print(has_sword and has_bow) # false
print(not has_sword) # trueChallenge
EasyChange the values of b1 and b2 to whole numbers so that b3 is true.
b3 is true when the product of b1 and b2 is greater than their sum and the two numbers are not equal.
Do not change the line of b3 or the print() line. The output must be:
b3 = trueTry it yourself
extends Node
func _ready():
# Change the values of b1 and b2
var b1: int = 0
var b2: int = 0
# Don't change the lines below
var b3: bool = (b1 * b2 > b1 + b2) and not (b1 == b2)
print("b3 = ", b3)
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsInteger DivisionModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators10Functions
Declare a FunctionArgumentsReturnReturn TypesRecap - Sigma FunctionRecap - Validation FunctionDefault Values5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary OperatorPractice on your own: Online GDScript compiler