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.

0 comments:

Post a Comment

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