-
-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathlesson.tres
299 lines (256 loc) · 11.3 KB
/
lesson.tres
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
[gd_resource type="Resource" load_steps=29 format=2]
[ext_resource path="res://resources/Lesson.gd" type="Script" id=1]
[ext_resource path="res://course/Documentation.tres" type="Resource" id=2]
[ext_resource path="res://resources/Practice.gd" type="Script" id=3]
[ext_resource path="res://resources/QuizChoice.gd" type="Script" id=4]
[ext_resource path="res://resources/ContentBlock.gd" type="Script" id=5]
[sub_resource type="Resource" id=1]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-KUdOCQiG.tres"
title = ""
type = 0
text = "In this lesson, we'll make our code easier to follow and understand at a glance.
Take a look at this example."
visual_element_path = ""
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=2]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-jB7tKRHJ.tres"
title = ""
type = 0
text = ""
visual_element_path = "visuals/ExampleUnclear.tscn"
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=3]
script = ExtResource( 4 )
quiz_id = "res://course/lesson-12-using-variables/quiz-MQ2XNwQM.tres"
question = "In the above example, what does the number 4 mean?"
content_bbcode = ""
hint = ""
explanation_bbcode = "The code above rotates the character [code]4[/code] radians per second."
answer_options = [ "It's how fast the character rotates.", "It's how far the character moves in pixels.", "It's how long the rotation takes." ]
valid_answers = [ "It's how fast the character rotates." ]
is_multiple_choice = false
do_shuffle_answers = true
[sub_resource type="Resource" id=4]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-qAYVjotx.tres"
title = ""
type = 0
text = "We can guess what a number represents by looking at the function names, but it's harder to recall what this number does by quickly looking at the code.
We've seen how different functions have their own names. Using these names communicates to developers what the functions do."
visual_element_path = ""
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=5]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-F5HUxZPx.tres"
title = ""
type = 0
text = ""
visual_element_path = "visuals/ExampleFunctions.tscn"
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=6]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-Y8VUDpPw.tres"
title = ""
type = 0
text = "As we learned in lesson 8, we can also assign labels to numbers to help us remember what they do.
We call these labels [i]variables[/i].
[b]A variable is a label for a value we can save, change, and read later.[/b]
Let's recap how to define a variable."
visual_element_path = ""
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=7]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-QDwfyqdY.tres"
title = ""
type = 0
text = ""
visual_element_path = "visuals/VariableDefinition.tscn"
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=8]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-OexRjTRh.tres"
title = ""
type = 0
text = "We improve the first example to make it clear what the number [code]4[/code] does."
visual_element_path = ""
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=9]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-ZN4rS5AJ.tres"
title = ""
type = 0
text = ""
visual_element_path = "visuals/ExampleUnclearImproved.tscn"
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=10]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-Rw9clsFc.tres"
title = ""
type = 0
text = "Labeling a value makes the code easier for us to read now [i]and[/i] in the future."
visual_element_path = ""
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=11]
script = ExtResource( 4 )
quiz_id = "res://course/lesson-12-using-variables/quiz-n1TxlTtc.tres"
question = "In the above example, which line defines the angular speed variable?"
content_bbcode = ""
hint = ""
explanation_bbcode = "We create the [code]angular_speed[/code] variable, then assign it the value of [code]4[/code]."
answer_options = [ "var angular_speed = 4", "func _process(delta):", "rotate(angular_speed * delta)" ]
valid_answers = [ "var angular_speed = 4" ]
is_multiple_choice = false
do_shuffle_answers = true
[sub_resource type="Resource" id=12]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-yhcIb5Bn.tres"
title = ""
type = 0
text = "If we define variables outside of functions, we can re-use them in different functions.
Because any function can use variables we define outside of them, we call these variables [b]script-wide[/b].
Here we use the [code]angular_speed[/code] script-wide variable in both the [code]_process()[/code] function and the [code]set_angular_speed()[/code] function."
visual_element_path = ""
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=13]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-VHARbBWN.tres"
title = ""
type = 0
text = ""
visual_element_path = "visuals/ExampleScriptWide.tscn"
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=14]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-bDGt6fUq.tres"
title = ""
type = 0
text = "We can also define variables inside of functions.
We align the variable assignment by indenting to make it part of the function body. Make sure to create the variable before using it!
If we define a variable inside of a function, only that function can use it."
visual_element_path = ""
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=15]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-bTxYej47.tres"
title = ""
type = 0
text = ""
visual_element_path = "visuals/ExampleInFunction.tscn"
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=16]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-MqE82V6j.tres"
title = ""
type = 0
text = "The [code]angular_speed[/code] variable only exists inside [code]_process()[/code], because we defined it there. The [code]set_angular_speed()[/code] function can't use it.
Trying to use it there will result in an error.
Here's what this error might look like."
visual_element_path = ""
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=17]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-GvGm22rt.tres"
title = ""
type = 0
text = ""
visual_element_path = "visuals/ErrorAccess.tscn"
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=18]
script = ExtResource( 4 )
quiz_id = "res://course/lesson-12-using-variables/quiz-QEn91c9l.tres"
question = "Where can we define variables?"
content_bbcode = ""
hint = ""
explanation_bbcode = "Functions can use any variables defined outside of functions. These variables are [b]script-wide[/b].
If we define a variable inside of a function, only that function can use it."
answer_options = [ "Outside of functions.", "Inside of functions." ]
valid_answers = [ "Outside of functions.", "Inside of functions." ]
is_multiple_choice = true
do_shuffle_answers = true
[sub_resource type="Resource" id=19]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-SrGQgrVc.tres"
title = ""
type = 0
text = "Variables are also great at grouping values that control how a character behaves.
Grouping them in this way allows us to easily change them."
visual_element_path = ""
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=20]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-s7CAcYuv.tres"
title = ""
type = 0
text = ""
visual_element_path = "visuals/ExampleVariableGrouping.tscn"
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=21]
script = ExtResource( 5 )
content_id = "res://course/lesson-12-using-variables/content-lf8B67UJ.tres"
title = ""
type = 0
text = "In the following practices, we'll define variables and use them with some familiar functions to make our code more readable."
visual_element_path = ""
reverse_blocks = false
has_separator = false
[sub_resource type="Resource" id=22]
script = ExtResource( 3 )
practice_id = "res://course/lesson-12-using-variables/practice-lkGx0c7D.tres"
title = "Clarifying Code Using Variables"
goal = "Let's give the [code]4[/code] here a label so we know what it does.
Create a variable called [code]angular_speed[/code] outside of the [code]_process()[/code] function to make it script-wide. This allows us to use it in other functions too.
Then, replace the [code]4[/code] with [code]angular_speed[/code]."
starting_code = "func _process(delta):
rotate(4 * delta)"
cursor_line = 0
cursor_column = 0
hints = PoolStringArray( "Define the [code]angular_speed[/code] variable at the top of the script to make it script-wide", "Don\'t forget to use it in the [code]rotate()[/code] function", "To define the variable, use [code]var angular_speed = 4[/code]" )
validator_script_path = "clarify/TestClarifyCode.gd"
script_slice_path = "clarify/ClarifyCode.live-editor/slices/ClarifyCode.clarify.slice.tres"
documentation_references = PoolStringArray( "rotate", "_process" )
documentation_resource = ExtResource( 2 )
description = "Using variables to store number values makes code easier to read. Tidy up this function by storing a value in a variable."
[sub_resource type="Resource" id=23]
script = ExtResource( 3 )
practice_id = "res://course/lesson-12-using-variables/practice-KUdOCQiG.tres"
title = "Fixing an Out of Scope Error"
goal = "There's something wrong with the code here. Can you see what it is?
Run the code and read the error.
Correct the code so it works as intended."
starting_code = "func _process(delta):
var angular_speed = 4
rotate(angular_speed * delta)
func set_angular_speed(new_angular_speed):
angular_speed = new_angular_speed"
cursor_line = 0
cursor_column = 0
hints = PoolStringArray( "You need to make [code]angular_speed[/code] script-wide so it\'s available to all functions", "Define [code]angular_speed[/code] at the top of the script instead" )
validator_script_path = "fixing_error/TestFixingError.gd"
script_slice_path = "fixing_error/FixingError.live-editor/slices/FixingError.clarify.slice.tres"
documentation_references = PoolStringArray( "rotate", "_process" )
documentation_resource = ExtResource( 2 )
description = "Uh oh! There's something wrong here. Can you fix it?"
[resource]
script = ExtResource( 1 )
title = "Using Variables to Make Code Easier to Read"
content_blocks = [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 6 ), SubResource( 7 ), SubResource( 8 ), SubResource( 9 ), SubResource( 10 ), SubResource( 11 ), SubResource( 12 ), SubResource( 13 ), SubResource( 14 ), SubResource( 15 ), SubResource( 16 ), SubResource( 17 ), SubResource( 18 ), SubResource( 19 ), SubResource( 20 ), SubResource( 21 ) ]
practices = [ SubResource( 22 ), SubResource( 23 ) ]