Mathematics, science, and computer programming are all based on logical reasoning. Logic defines a set of rules. It is a way of making sure everyone is on the same page.
Common human language is often left open to interpretation. If you tell your friend "Timmy's house is so big!", you are not telling her the exact size of Timmy's house. What you consider a big house, someone else might consider small. There is no room for this type of interpretation in game development. A computer can not interperate this type of language. Even if it could, its interpretation could lead to unexpected results.
As a programmer, your goal is telling the computer exactly what to do in any possible scenario. You do this by writing logic. Game development logic is based on mathematical logic. Propositional logic is the building block. Conditional statements such as if-statements are directly based on propositional logic.
Note: It is humanly impossible to think of every possible scenario. Why set an impossible goal? If you don't try to think of every possible scenario, you will end up ignoring many probable scenarios. We are all unique individuals with our own thought patterns. If you write your code only based on scenarios that are probable for you, you will ignore the needs and thought patterns of your users.
Propositional logic defines the rules of validity (true or false). At the end of the day, anything can be broken down to "true or false" logic. For example, say you are taking a multiple-choice test with four options: a, b, c, or d. Only one answer is correct. This can be broken down to propositional logic by evaluating each possible answer as
Propositional logic is also known as "statement logic". It is the process of determining if a statement is true or false. We use propositional logic to define conditions. When will what code execute? Since logic is based on rules and definitions, let's define a
We can combine propositions to solve more complicated problems. We do this using variables, comparison operators, and logical operators. You may want to look back at GDScript Operators
In mathematical notation this is read "p and q". Pluging in our values, this would be read "Kobe completed level three and Kobe got a perfect score on level three."
In order for p ⋀ q to evaluate true, both conditions must be satisfied:
extends Node var completed: bool = false var perfect: bool = false func _ready(): if (completed == true) && (perfect == true): print("Kobe completed level three with a perfect score!")
In mathematical notation this is read "p or q". Pluging in our values, this would be read Kobe completed level three or Kobe got a perfect score on level three.
In order for p ⋁ q to evaluate true, only one of the statements must be true. Either Kobe completed level three or he got a perfect score on level three.
extends Node var completed: bool = false var perfect: bool = false func _ready(): if (completed == true) || (perfect == true): print("Level Complete!")
In mathematical notation this is read "p implies q" or "if p than q". This means if
extends Node var completed: bool = false func _ready(): if (completed == true): print("Kobe got a perfect score on level three!")
If you want to learn more about logic, check out Logic for Programmers. The page includes additional videos and a logic quiz game!