From bdee3d0637707ab88bb056a2a71f758f3547d424 Mon Sep 17 00:00:00 2001 From: Nathan Lovato <12694995+NathanLovato@users.noreply.github.com> Date: Sat, 2 Apr 2022 14:57:56 +0200 Subject: [PATCH] content: explain when you want to store return values in lesson 22 --- app-practice-screen.png.import | 35 +++++++++++++++++++ .../lesson.tres | 28 ++++++++++++--- .../visuals/CodeRoundingHealth2.tscn | 24 +++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 app-practice-screen.png.import create mode 100644 course/lesson-22-functions-return-values/visuals/CodeRoundingHealth2.tscn diff --git a/app-practice-screen.png.import b/app-practice-screen.png.import new file mode 100644 index 00000000..17b106f7 --- /dev/null +++ b/app-practice-screen.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/app-practice-screen.png-2803de6b8f7978f679c93f9f4836ed49.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://app-practice-screen.png" +dest_files=[ "res://.import/app-practice-screen.png-2803de6b8f7978f679c93f9f4836ed49.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/course/lesson-22-functions-return-values/lesson.tres b/course/lesson-22-functions-return-values/lesson.tres index b039106f..10c89049 100644 --- a/course/lesson-22-functions-return-values/lesson.tres +++ b/course/lesson-22-functions-return-values/lesson.tres @@ -1,4 +1,4 @@ -[gd_resource type="Resource" load_steps=23 format=2] +[gd_resource type="Resource" load_steps=25 format=2] [ext_resource path="res://course/Documentation.tres" type="Resource" id=1] [ext_resource path="res://resources/Lesson.gd" type="Script" id=2] @@ -68,9 +68,29 @@ script = ExtResource( 4 ) content_id = "res://course/lesson-22-functions-return-values/content-qdYOexRj.tres" title = "" type = 0 -text = "Notice how we assign the result of the function call to a variable. Because the [code]round()[/code] function returns a [i]new[/i] value, we need to store the result. +text = "Notice how we assign the result of the function call to a variable. Because the [code]round()[/code] function returns a [i]new[/i] value, we need to either store the result or use the value immediately. -So we assign the result to a variable." +Above, we assigned it to a variable, but you could also do the following." +visual_element_path = "" +reverse_blocks = false +has_separator = false + +[sub_resource type="Resource" id=20] +script = ExtResource( 4 ) +content_id = "res://course/lesson-22-functions-return-values/content-izKUdOCQ.tres" +title = "" +type = 0 +text = "" +visual_element_path = "visuals/CodeRoundingHealth2.tscn" +reverse_blocks = false +has_separator = false + +[sub_resource type="Resource" id=21] +script = ExtResource( 4 ) +content_id = "res://course/lesson-22-functions-return-values/content-iGjB7tKR.tres" +title = "" +type = 0 +text = "You can assign the return value of a function call if you plan on using it more than once." visual_element_path = "" reverse_blocks = false has_separator = false @@ -226,5 +246,5 @@ description = "We lost the function to convert grid coordinates, but we desperat [resource] script = ExtResource( 2 ) title = "Functions that return a value" -content_blocks = [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 6 ), SubResource( 7 ), SubResource( 19 ), SubResource( 8 ), SubResource( 9 ), SubResource( 10 ), SubResource( 11 ), SubResource( 12 ), SubResource( 13 ), SubResource( 14 ), SubResource( 15 ), SubResource( 16 ) ] +content_blocks = [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 6 ), SubResource( 20 ), SubResource( 21 ), SubResource( 7 ), SubResource( 19 ), SubResource( 8 ), SubResource( 9 ), SubResource( 10 ), SubResource( 11 ), SubResource( 12 ), SubResource( 13 ), SubResource( 14 ), SubResource( 15 ), SubResource( 16 ) ] practices = [ SubResource( 17 ) ] diff --git a/course/lesson-22-functions-return-values/visuals/CodeRoundingHealth2.tscn b/course/lesson-22-functions-return-values/visuals/CodeRoundingHealth2.tscn new file mode 100644 index 00000000..8c7b1873 --- /dev/null +++ b/course/lesson-22-functions-return-values/visuals/CodeRoundingHealth2.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://course/common/GDScriptCodeExample.gd" type="Script" id=1] + +[node name="GDScriptCodeExample" type="TextEdit"] +anchor_right = 1.0 +margin_right = -1620.0 +margin_bottom = 60.0 +rect_min_size = Vector2( 300, 80 ) +size_flags_horizontal = 3 +text = "set_text(round(health))" +readonly = true +syntax_highlighting = true +show_line_numbers = true +draw_tabs = true +draw_spaces = true +context_menu_enabled = false +shortcut_keys_enabled = false +smooth_scrolling = true +wrap_enabled = true +caret_block_mode = true +caret_blink = true +script = ExtResource( 1 ) +min_size = Vector2( 300, 80 )