Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:00,030 --> 00:00:03,060
Welcome to the quick introduction to programming.
1
2
00:00:03,270 --> 00:00:10,050
If you're a beginner, then definitely don't skip this. Since we will be using code to implement various
2
3
00:00:10,050 --> 00:00:10,680
systems,
3
4
00:00:10,920 --> 00:00:13,860
it's always a good idea to get up to speed.
4
5
00:00:14,310 --> 00:00:16,820
All of the code will be in GDScript,
5
6
00:00:16,830 --> 00:00:18,990
Godot's native scripting language.
6
7
00:00:18,990 --> 00:00:24,600
Let's look at the core building blocks and how to use them to create more complex functionality.
7
8
00:00:24,610 --> 00:00:30,480
First, I want to mention that all of these examples are available in the downloadable project in the
8
9
00:00:30,480 --> 00:00:33,420
course. If we look at the variables scene:
9
10
00:00:34,550 --> 00:00:36,240
We have the script, by the way.
10
11
00:00:36,260 --> 00:00:38,600
We will discuss first about variables.
11
12
00:00:38,630 --> 00:00:41,630
Variables are used as data containers.
12
13
00:00:41,780 --> 00:00:49,070
They can store numbers, strings and even more complex things as objects, materials and whatever
13
14
00:00:49,070 --> 00:00:50,210
the developer needs.
14
15
00:00:50,390 --> 00:00:53,090
They do come in more shapes and sizes.
15
16
00:00:53,360 --> 00:00:58,130
Usually when creating a new variable, it can store only one thing at a time.
16
17
00:00:58,490 --> 00:01:03,020
This is good for values like hit points, damage, speed, etc..
17
18
00:01:03,200 --> 00:01:09,580
When we are discussing about variables, a core concept is called a "variable declaration" and that one
18
19
00:01:09,590 --> 00:01:13,970
means to let the engine know that we are creating a new variable.
19
20
00:01:14,000 --> 00:01:15,690
The declaration goes like this.
20
21
00:01:15,800 --> 00:01:22,070
Var which is an operator and then the name of the variable that can be whatever you like.
21
22
00:01:22,070 --> 00:01:23,020
I'll just keep it: "a"
22
23
00:01:23,030 --> 00:01:25,010
So by doing this
23
24
00:01:25,100 --> 00:01:33,380
"var a" I'm actually specifying that hey, I want a variable called a from now on so I cannot use it
24
25
00:01:33,620 --> 00:01:41,660
before this. We can also initialize the variable when we declare it by putting an equal and then putting
25
26
00:01:41,840 --> 00:01:46,580
a number, a string or an object. To display the variable in the console
26
27
00:01:46,670 --> 00:01:53,000
we can use a handy function called print() and then in its parenthesis as a parameter we can specify
27
28
00:01:53,030 --> 00:01:53,450
a
28
29
00:01:53,600 --> 00:02:00,470
in this case. We can try it by pressing f6 and of course we will get five because that's the value contained
29
30
00:02:00,470 --> 00:02:01,640
in the variable E.
30
31
00:02:01,730 --> 00:02:05,300
Now let's look at the string and the string is very similar.
31
32
00:02:05,450 --> 00:02:09,840
You can see we can just call it string.
32
33
00:02:09,860 --> 00:02:15,710
By the way, we can specify the type of a variable by adding colons to it.
33
34
00:02:16,130 --> 00:02:18,020
So if I say: string.
34
35
00:02:19,190 --> 00:02:21,410
Then this variable will be a string.
35
36
00:02:21,920 --> 00:02:23,100
Why is this important?
36
37
00:02:23,120 --> 00:02:33,020
Because if we want to assign later another type, then we will get an error because only string is available
37
38
00:02:33,260 --> 00:02:33,980
for this one.
38
39
00:02:34,820 --> 00:02:39,050
Keep in mind that if we don't put this, then we can assign whatever we want.
39
40
00:02:39,380 --> 00:02:41,540
But this will create confusion
40
41
00:02:41,630 --> 00:02:46,910
later in the code. A float variable means a number that has decimal points.
41
42
00:02:46,920 --> 00:02:51,690
For example, PI, which is 3.1415 and so on and so forth.
42
43
00:02:51,710 --> 00:02:57,140
When we need a list of elements, let's say a list of words we can use lists.
43
44
00:02:57,400 --> 00:03:00,590
Lists or arrays are also variables.
44
45
00:03:00,950 --> 00:03:07,910
The main difference between them is the fact that they can store multiple values chained one after another.
45
46
00:03:08,300 --> 00:03:15,620
They are good to store groups of items like inventories, enemies, projectiles. To create an array
46
47
00:03:15,650 --> 00:03:21,230
we can declare it as a regular variable and then just use these brackets.
47
48
00:03:23,730 --> 00:03:25,140
And we have an array.
48
49
00:03:25,260 --> 00:03:32,040
We can also initialize the array as it's here with different values separated through commas.
49
50
00:03:32,130 --> 00:03:39,660
Keep in mind that to reference a particular value in this way we can just say array and then in the
50
51
00:03:39,660 --> 00:03:46,590
same brackets we can just specify the index starting from zero, which would be one in this case, one
51
52
00:03:46,890 --> 00:03:49,110
and two, which would be three.
52
53
00:03:49,740 --> 00:03:51,930
So this is 0, 1, 2.
53
54
00:03:53,170 --> 00:04:01,030
We can also get the size of an array by calling array dot size and this will return three.
54
55
00:04:01,960 --> 00:04:05,080
The array also can be passed, but that is for later on.
55
56
00:04:05,110 --> 00:04:12,940
Another type is also vector2, which is a Godot type and vector2 stores, a pair of values x
56
57
00:04:12,940 --> 00:04:13,480
and y.
57
58
00:04:13,570 --> 00:04:19,630
We can define it like this. And to call it we just say "vec" because that is the name of the variable.
58
59
00:04:19,630 --> 00:04:23,890
And vec.x or vec.y
59
60
00:04:24,250 --> 00:04:27,220
Of course there is vector3 and more.
60
61
00:04:27,670 --> 00:04:32,260
You can find all of the types supported by the GDScript in the link down below.
6169
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.