learning gdscript (part 1)
Nov. 16th, 2022 02:53 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
trying to use my blog more but my mind is usually ??? ^_^'' anyways after some time of being burnt out and not working on my game i think i wanna take it slow this time and finally learn my coding fundamentals.. in the past ive just learned game programming by looking up how to do x or y, but especially since moving to godot i find myself very lost :')
yesterday i started watching this video by gdquest and while i won't go over everything in detail, here's just some notes so i can remind myself of them:
syntax
gdscript is a dynamic language (whatever that means) so unlike c#, variables can be declared a few ways and godot will usually know what i'm talking about. ex:
var health = 100 # health is an integer, but can also be a float, string, or bool
var health : int = 100 # health can ONLY be an integer
var health : = 100 # health can still only be an integer, but we're using a shorthand and godot figures out the type for us
so basically these are the same:
var variable_name : type = value
var variable_name : = value
variables
there are a few variable types, which are..
int whole numbers (0,1,2)
float numbers with decimals (0.0, 0.1, 0.2, 0.3)
string words ("Hello!")
bool true or false
constants
constants are like variables, but their values are only declared once and do not change. they're written with this convention:
const VARIABLES_ARE_UPPERCASE_LIKE_THIS = 100
operators
these are ways to compare two values, and there's a hierarchy in which the calculations take place (like PEMDAS). they are:
also in this category are boolean operators, used in if statements. they are:
ex:
health > 2 # if health is more than 2
health < 2 # if health is less than 2
health >= 2 # if health is more or equal to 2
health <= 2 # if health is less or equal to 2
health == 2 # if health is equal to 2
health != 2 # if health is NOT equal to 2
health = 2 # health equals 2 (this assigns a value instead of comparing it)
health == 2 && speed > 0 # if health is equal to 2 and speed is more than 0
health < 0 | | speed > 0 # if health is less than 0 OR speed is more than 0
conditions
conditions are things like if, elif, and else statements that are used in a function and tell the engine "if a condition is met, do this, otherwise, do this"
if health > 0
print ("you are alive")
else
print ("you are dead")
next section is a WIP!!
arrays
loops
objects
classes
yesterday i started watching this video by gdquest and while i won't go over everything in detail, here's just some notes so i can remind myself of them:
syntax
gdscript is a dynamic language (whatever that means) so unlike c#, variables can be declared a few ways and godot will usually know what i'm talking about. ex:
var health = 100 # health is an integer, but can also be a float, string, or bool
var health : int = 100 # health can ONLY be an integer
var health : = 100 # health can still only be an integer, but we're using a shorthand and godot figures out the type for us
so basically these are the same:
var variable_name : type = value
var variable_name : = value
variables
there are a few variable types, which are..
int whole numbers (0,1,2)
float numbers with decimals (0.0, 0.1, 0.2, 0.3)
string words ("Hello!")
bool true or false
constants
constants are like variables, but their values are only declared once and do not change. they're written with this convention:
const VARIABLES_ARE_UPPERCASE_LIKE_THIS = 100
operators
these are ways to compare two values, and there's a hierarchy in which the calculations take place (like PEMDAS). they are:
Operator | Description |
---|---|
-x | Negation |
* / % | Times / Divide / Remainder |
+ | Add |
- | Subtract |
also in this category are boolean operators, used in if statements. they are:
Operators | Description |
---|---|
< == > != >= <= | Comparison operators |
! not | NOT |
&& and | AND |
|| or | OR |
ex:
health > 2 # if health is more than 2
health < 2 # if health is less than 2
health >= 2 # if health is more or equal to 2
health <= 2 # if health is less or equal to 2
health == 2 # if health is equal to 2
health != 2 # if health is NOT equal to 2
health = 2 # health equals 2 (this assigns a value instead of comparing it)
health == 2 && speed > 0 # if health is equal to 2 and speed is more than 0
health < 0 | | speed > 0 # if health is less than 0 OR speed is more than 0
conditions
conditions are things like if, elif, and else statements that are used in a function and tell the engine "if a condition is met, do this, otherwise, do this"
if health > 0
print ("you are alive")
else
print ("you are dead")
next section is a WIP!!
arrays
loops
objects
classes