Looks like you're not logged in

Login or Register to continue

Lesson Q&A

Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.

  • A question about L8.P1EddyI did the exercice and completed the tasks. But I have a question about the result. Before completing it, if I ran the scene the first displayed character is Dani. Why, after completing the exercice, do I have Nova displayed first instead of Dani? Is there a part of the code where she is selected first or is it something else? 8 1 May. 22, 2024
  • Multiple cursors...AJ StudiosI imagine that this technique is very useful when dealing with large dictionaries and or arrays but I'm struggling a bit when it comes to multiple cursors. I'm using a Macbook Pro and a separate bluetooth keyboard. There is no end key or home key on the laptop or the keyboard I'm using. So when is time to let's say insert parenthesis it will insert "()" in the beginning of all the lines, not the lines within parenthesis. I will continue doing research on this topic and report back if I find a solution for Mac users like myself. 8 1 May. 21, 2024
  • Typo in practice codenear-octopusIn `L8.P1.pick_your_character/pick_your_character.gd` there is a small typo in the code comment: ```gdscript # make the gobot and sophia buttons work below ``` But the characters for the exercise are Dani, Gobot, and Nova. 1 1 May. 20, 2024
  • We will not use Expressions scene anymoreMarcJJust FYI, at the end of this lesson there's a line that says > We will not use the scene expressions.tscn in this module anymore But it's used in the next lesson and repeats the line at the end 1 1 May. 13, 2024
  • Update on typed Dictionaries. / using enumsEasySpeedsTyped Dictionaries are coming in Godot 4.4! ```gdscript var dict : Dictionary[int, CompressedTexture2D] ``` [https://godotengine.org/article/dev-snapshot-godot-4-4-dev-2/](https://godotengine.org/article/dev-snapshot-godot-4-4-dev-2/) I'd like to be cautious about using strings as keys in a dictionary as it seems too error prone. So instead of using strings or variables like (var sophia = "sophia"), I opted to use an enum. As a bonus, the key index can also be auto-completed to some degree. Please forgive the variable names being almost identical. ```gdscript extends Control @onready var sophia_button: Button = %SophiaButton @onready var pink_button: Button = %PinkButton @onready var normal_button: Button = %NormalButton @onready var sad_button: Button = %SadButton @onready var happy_button: Button = %HappyButton @onready var body: TextureRect = %Body @onready var expression: TextureRect = %Expression enum Bodies {SOPHIA, PINK} enum Expressions {NORMAL, SAD, HAPPY} var body_textures = { Bodies.SOPHIA : preload("res://assets/sophia.png"), Bodies.PINK : preload("res://assets/pink.png"), } var expression_textures = { Expressions.NORMAL : preload("res://assets/emotion_regular.png"), Expressions.SAD : preload("res://assets/emotion_sad.png"), Expressions.HAPPY : preload("res://assets/emotion_happy.png"), } func _ready() -> void: sophia_button.pressed.connect(func() -> void : body.texture = body_textures[Bodies.SOPHIA] ) pink_button.pressed.connect(func() -> void : body.texture = body_textures[Bodies.PINK] ) normal_button.pressed.connect(func() -> void : expression.texture = expression_textures[Expressions.NORMAL] ) sad_button.pressed.connect(func() -> void : expression.texture = expression_textures[Expressions.SAD] ) happy_button.pressed.connect(func() -> void : expression.texture = expression_textures[Expressions.HAPPY] ) ``` 1 0 Sep. 11, 2024
  • Alternate way to change the textures (not a question)Abdul Hannan Ahmed```gdscript extends Control const BODY_TEXTURES := { "pink": preload("res://assets/pink.png"), "sophia": preload("res://assets/sophia.png") } const EXPRESSION_TEXTURES := { "regular": preload("res://assets/emotion_regular.png"), "sad": preload("res://assets/emotion_sad.png"), "happy": preload("res://assets/emotion_happy.png") } @onready var body: TextureRect = %Body @onready var expression: TextureRect = %Expression @onready var button_sophia: Button = %ButtonSophia @onready var button_pink: Button = %ButtonPink @onready var button_sad: Button = %ButtonSad @onready var button_regular: Button = %ButtonRegular @onready var button_happy: Button = %ButtonHappy func _ready() -> void: button_sophia.pressed.connect(change_texture.bind(body, BODY_TEXTURES["sophia"])) button_pink.pressed.connect(change_texture.bind(body, BODY_TEXTURES["pink"])) button_sad.pressed.connect(change_texture.bind(expression, EXPRESSION_TEXTURES["sad"])) button_regular.pressed.connect(change_texture.bind(expression, EXPRESSION_TEXTURES["regular"])) button_happy.pressed.connect(change_texture.bind(expression, EXPRESSION_TEXTURES["happy"])) func change_texture(texture_rect: TextureRect, new_texture: Texture2D) -> void: texture_rect.texture = new_texture ``` Hi! I just found an alternate way to change the textures. I just wanted to ask, is this way considered a good practice too? Thanks in advance, Regards, Abdul Hannan Ahmed 3 0 Sep. 09, 2024
  • Lambdas inside LambdaspicrocAs a JS developer, I use Lambdas a lot, and was really glad to find out they are in GDScript. However, it's still not as good because - Indents instead of braces make it hard to read - If assigned to a variable, you can't call them as regular functions (only by using `.call`) Here's my take on the connections code: ```gdscript var set_body := func(body_name: String) -> Callable: return func() -> void: body.texture = bodies[body_name] var set_expression := func(expression_name: String) -> Callable: return func() -> void: expression.texture = expressions[expression_name] button_sophia.pressed.connect(set_body.call("sophia")) button_pink.pressed.connect(set_body.call("pink")) button_regular.pressed.connect(set_expression.call("regular")) button_sad.pressed.connect(set_expression.call("sad")) button_happy.pressed.connect(set_expression.call("happy")) ``` 1 0 Sep. 02, 2024
  • Workaround for autocompleting keys in dictionary lookupsprofuse-otterI don't really like using strings for lookups since you don't get autocomplete or error-checking so I tried a solution using enums for keys. I was wondering if there are any drawbacks to this. It did somewhat limit my ability to do multiline text editing ```gdscript enum BODIES {SOPHIA, PINK} var bodies := { BODIES.SOPHIA: preload("res://assets/sophia.png"), BODIES.PINK: preload("res://assets/pink.png") } enum EXPRESSIONS {HAPPY, REGULAR, SAD} var expressions := { EXPRESSIONS.HAPPY: preload("res://assets/emotion_happy.png"), EXPRESSIONS.REGULAR: preload("res://assets/emotion_regular.png"), EXPRESSIONS.SAD: preload("res://assets/emotion_sad.png"), } # Called when the node enters the scene tree for the first time. func _ready() -> void: body.texture = bodies[BODIES.PINK] expression.texture = expressions[EXPRESSIONS.HAPPY] ``` 1 0 Aug. 27, 2024
  • Tiny typo in Lambda functions glossaryMatejUnder [Case 4](https://school.gdquest.com/courses/learn_2d_gamedev_godot_4/telling_a_story/code_changing_expressions#case-4-immediately-invoked-function-expressions): immediately invoked function expressions, second code example, Node2D is typed as Nod2D ```gdscript @onready var largest_target := (func() -> Nod2D: # We nodding in 2D ``` 1 0 Aug. 21, 2024
  • Object Notation Owl Knight1. It's more explicit. When you write `bodies["sophia"]`, you are reminded that you are not sure the key exists. If you write `bodies.sophi` (the "a" is missing here), Godot will not tell you if there is an error. At least at the stage this is stated, I do not find this to be true. I see no squigglies or console message warning me about either method when purposefully using a typo. Perhaps I am missing something? ```gdscript var bodies: Dictionary = { "sophia": preload("res://assets/sophia.png"), "pink": preload("res://assets/pink.png"), } var expressions: Dictionary = { "regular": preload("res://assets/emotion_regular.png"), "sad": preload("res://assets/emotion_sad.png"), "happy": preload("res://assets/emotion_happy.png"), } func _ready() -> void: body.texture = bodies["pin"] # TYPO HERE expression.texture = expressions.sa # TYPO HERE ``` 4 0 Aug. 14, 2024
  • Expected end of file.KaiI had a weird error show up: Error at (41, 1): Expected end of file. Line 41: Expected end of file. I was so confused at first until I hit "ctrl s" to save my work. Suddenly, it automatically created a line 41 and the error went away. I removed line 41 to see if it would come back and it did. Do you know the precise reason this error occurs or is it intended? I suppose it wasn't able to tell I was finished with the ready function without that additional line after the final bracket? This is the code with the error: ```gdscript func _ready() -> void: body.texture = bodies["pink"] expression.texture = expressions["happy"] button_sophia.pressed.connect(func() -> void: body.texture = bodies["sophia"] ) button_pink.pressed.connect(func() -> void: body.texture = bodies["pink"] ) button_regular.pressed.connect(func() -> void: expression.texture = expressions["regular"] ) button_sad.pressed.connect(func() -> void: expression.texture = expressions["sad"] ) button_happy.pressed.connect(func() -> void: expression.texture = expressions["happy"] ) ``` And here's the code without the error: ```gdscript func _ready() -> void: body.texture = bodies["pink"] expression.texture = expressions["happy"] button_sophia.pressed.connect(func() -> void: body.texture = bodies["sophia"] ) button_pink.pressed.connect(func() -> void: body.texture = bodies["pink"] ) button_regular.pressed.connect(func() -> void: expression.texture = expressions["regular"] ) button_sad.pressed.connect(func() -> void: expression.texture = expressions["sad"] ) button_happy.pressed.connect(func() -> void: expression.texture = expressions["happy"] ) ``` You can see the only difference is the new line created after line 19. 2 0 Aug. 12, 2024
  • Solution without LambdasDustin```gdscript extends Control @onready var button_sophia: Button = %ButtonSophia @onready var button_pink: Button = %ButtonPink @onready var button_regular: Button = %ButtonRegular @onready var button_sad: Button = %ButtonSad @onready var button_happy: Button = %ButtonHappy @onready var expression: TextureRect = %Expression @onready var body: TextureRect = $Body const HAPPY := 0 const REGULAR := 1 const SAD := 2 const PINK := 0 const SOPHIA := 1 var available_bodies: Array[CompressedTexture2D] = [ preload("res://assets/pink.png"), preload("res://assets/sophia.png") ] var available_expressions: Array[CompressedTexture2D] = [ preload("res://assets/emotion_happy.png"), preload("res://assets/emotion_regular.png"), preload("res://assets/emotion_sad.png") ] func _ready() -> void: var sad_expression: Callable = switch_expression.bind(SAD) var happy_expression: Callable = switch_expression.bind(HAPPY) var regular_expression: Callable = switch_expression.bind(REGULAR) var sophia_body: Callable = switch_bodies.bind(SOPHIA) var pink_body: Callable = switch_bodies.bind(PINK) button_sad.pressed.connect(sad_expression) button_happy.pressed.connect(happy_expression) button_regular.pressed.connect(regular_expression) button_sophia.pressed.connect(sophia_body) button_pink.pressed.connect(pink_body) func switch_bodies(index) -> void: body.texture = available_bodies[index] func switch_expression(index) -> void: expression.texture = available_expressions[index] ``` 2 0 Aug. 03, 2024
  • Anyone else having issues with the multiple cursors?PurrNuggetI'm on windows with a standard keyboard. I checked the editor setting shortcuts and it does show the ui_text_caret_add_below/above to be Ctrl+Shift+Down/Up but nothing happens when I click them. I tried both ctrl+shifts. Only way I can create multiple is using ctrl+d to grab similar words and then move out of the selection to keep multiple cursors. Using ctrl+up/down doesn't do anything either but shift+up/down does work. Very strange. 3 0 Jun. 22, 2024
  • Typopuzzled-magpie> It's a function we use it to load resources 2 0 Jun. 20, 2024
  • Lambda FunctionstesfalconI saw lambda functions referenced in the GDScript reference book, but I didn't understand what they were or how to use them. This was very clarifying. Now, I just don't understand why they're called lambdas. 4 0 Jun. 15, 2024
  • Lambda Glossary entry questionStonemonkeyHow would you pass an argument to the lambda in the following code. I can't figure out how to use `num` ```gdscript func _ready() -> void: var multiply_by_ten := func (num: int) -> int: return num * 10 ``` Also in the example: ```gdscript func characters := [ {name = "Gimly", age = 139 }, {name = "Frodo Baggins", age = 50 }, {name = "Gandalf", age = 2000 }, {name = "Samwise Gamgee", age = 33 }, ] ``` I know it's an array that contains dictionaries as values, but the syntax of the dictionary values doesn't make sense to me. Are `name` and `age`supposed to be the keys? If so why aren't they using colons? 2 0 Jun. 03, 2024
  • what does using ":" in a dictionary declaration do?nedif it can't deduce the type of objects in a dictionary, what does it do? 1 0 May. 31, 2024
Site is in BETA!found a bug?