Tutorial 7: Basic Match Statement in GDScript

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.

Related Posts:

  • Tutorial 4: Basic Functions in GDScript GDScript with Basic Functions Declaring a function in GDScript is not difficult; just like what is shown in the image above. You can declare a function with func someFunctionName(some_variable): , but I prefer declaring i… Read More
  • Tutorial 8: Basic For Loop in GDScript GDScript of Basic For Loop In this example, it shows the basic uses of a for loop statement. One is to increment and the other decrements the value of 'n'. There are other usages but for now let's tackle the common ones. … Read More
  • Tutorial 5: Basic Functions in GDScript Part 2 GDScript for Determining an Even or Odd Number This is the second part of the function tutorial. Please study the previous tutorials before studying this one; it builds from the concepts of the past tutorials 1 to 4. The… Read More
  • Tutorial 7: Basic Match Statement in GDScript 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… Read More
  • Tutorial 6: Basic Conditional Statements in GDScript GDScript of Basic Conditional Statements The basic GDScript conditional statements shown above is pretty much straightforward. It simply uses the if, elif and else statements. You can download the source code here. In th… Read More

0 comments:

Post a Comment

© 2020 by Emman Lijesta, all rights reserved. Powered by Blogger.