![]() |
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 it with specific types in order to reduce bugs and errors, especially when the program gets too large. I declare it this way func someFunctionName(some_variable: TYPE) -> TYPE: and make sure you indent the codes within the function. You can download the source code here.
This tutorial solves for the square of a base. The function is called with an input variable and returns a float type that is assigned to a variable sqr, which is then converted to 2 decimal places and into a string before printing into the Output console.
![]() |
The Square of the Base |
As for your practice, create a function that returns true if the input integer is an even number with the use of a modulus or remainder operator %.
0 comments:
Post a Comment