GDScript Match Statement |
The Godot match statement is the equivalent of switch statement in other programming languages. It's a cleaner way of handling conditional statements. If a match statement can handle my conditions in the program, then I prefer to use this than the if/eleif/else statements. You can download the source code here.
In the program, it tests the 'a' variable if it matches and integer value of 2. If it's 2, then it satisfies the 2nd match condition.If it's 1, then it will trigger the 1st condition. Other values will trigger the default condition represented by an underscore.
Afterwards, another match statement checks for the TYPE of variable, checking if it's a common or advanced type. So, these are the basic ways of using the match statement. There are other ways but we'll deal with it later in future tutorials.
Output Console with Results |
As for your practice, try changing the values of 'a' and see what happens.
0 comments:
Post a Comment