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 example shown in the image above introduces new operators, the remainder or modulus % and boolean operator ! (NOT), and the basic declaration of boolean variable type. You can download the source code here.

In the code, it asks for an integer and the function determines if it's an even number. If it's even, then it returns true, otherwise, false if it's an odd number. The code returns true because the given integer for analysis is 2. Try changing it to any odd number and it will return false.

The Function Returns True

As for your practice, create a similar program that takes in any integer and returns true if it's an odd number.

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 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 3: Basic Operators in GDScript GDScript Basic Operators In this tutorial, you'll learn how to use the basic operators like addition, subtraction, multiplication and division used in the compound interest formula, as shown above. You can download the so… 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
  • Tutorial 2: Basic Variables in GDScript GDScript with Specific Variable Types and Scoping The image above shows a GDScript with basic variables declared with specific types, and with proper scoping. You can download the source code here. In this example, we so… Read More

0 comments:

Post a Comment

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