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 solve the area of a cone with the given variables. Each variable is declared with a specific type and properly positioned for global and local functions.

It uses similar functions based on the previous tutorial plus the latest sqrt() function. I suggest to do the previous tutorial before studying this one.

The answer of this example is printed in the Output console.

The Area of a Cone

Declaring variables with specific types and placing them in their proper scopes can minimize bugs and errors.

As for your practice, solve for the Area of a Sphere.

Related Posts:

  • Tutorial 9: Basic While Loop in GDScript GDScript While Loop The GDScript above shows the basic uses of while loop to increment and decrement values. In this example the decrement operator -= is introduced. You can download the source code here. In this tutoria… Read More
  • Tutorial 11: Series 1 Exercise 1 in GDScriptextends Node2D const CURRENT_PRINCIPAL: float = 5678.9 const INTEREST_RATE: float = 0.03 const COMPOUND_PER_YEAR: int = 1 var years_to_grow: int = 50 var target_amount: int = 7000 func _ready(): plot_years(CURRENT_PRINCIPA… Read More
  • Tutorial 12: Series 1 Excercise 2 - Recursionextends Node2D # Recursive function using factorial as example const NUM: int = 8 func _ready(): print("Using Function 1 - " + str(NUM) + "! Factorial is: " + str(factorial_one(NUM))) print("Using Function 2 - " + st… Read More
  • Series 1 Tutorials - Basic GDScriptThis series covers just the basics of Godot scripting or GDScript. You can download all the source codes here. I recommend not to skip one tutorial if this is your first time to GDScript; each tutorial builds from the concep… Read More
  • Tutorial 10: Diamond Shapes using Loops in GDScriptextends Node2D # Draws a diamond with adjustable size func _ready(): # Try changing 6 with even integers from 4 to 26 diamond_for(6) diamond_while(6) func diamond_for(size: int): tri_for(size) #Upside T… Read More

0 comments:

Post a Comment

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