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.

  • 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 1 Sep. 11, 2024
  • 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
  • Best practicemajestic-turtleWhen scripting in Godot, is it considered best practice to default to the following: - access nodes as scene unique names by marking them as Scene Unique ? - use the @onready annotation to get references to nodes ? - preload all the resources with the preload() function ? Or are there instances where a beginner like myself should avoid them ? Thank you for your time and dedication. I'm really impressed by the quality of your content :) 2 0 Nov. 10, 2024
  • {} and []silver-foxI have a Quenstion. The list of the Dictionary is in  curly braces. And to access dictionary values we use  curly braces. Shouldn't we use also curly braces for accessing the values? is a little bit confusing 1 0 Oct. 30, 2024
  • Feedback: ["this"] and .thatMrBright01One of my biggest confusion points during the learning process with gdquest is when to use ["name"] and .name when changing a value. I spent a lot of effort trying to memorize when you use which, and it made it sometimes much harder to finish tests because I was trying to figure out what they did differently and which I needed at any given time. ... But they both work? Arrrrglebargle. Just my opinion of course, but I think a small dropdown helper early on that explains that they do the same thing but are used differently for clarity/good style practices would go a long way for someone like me in really understanding how they both work. Not sure how common that is, might not be worth it, but was worth commenting. That said, your explanation of arrays and dictionaries was wonderful and helped me a great deal, as that was something I had a lot of difficulty with the same subject in the "learn to code from zero in godot" free course. Like the other suggestion, might just be me, and might not be worth pursuit (probably take a lot of work because of the structure differences), but wanted to comment on that as well. This has been a great course, and I am glad I picked it up. It was during the practice on the previous chapter when it all clicked and I started to be able to predict solutions and write them ahead of time, even if they were generally less elegant than the solutions taught by the end. So the objective of teaching enough to be able to go past copying was a complete success in my case. And now, with arrays and dictionaries so wonderfully explained, it feels like I am reaching a point where I could actually go try to make something entirely on my own with nothing but my notes and the documentation. Very well done. Thank you. 1 0 Oct. 28, 2024
  • Small inconsistency - changing_expressions.gd & expressions.gdCasimirMorelThe script file for expressions is referred by expressions.gd in the body of the lesson and by changing_expressions.gd at the end of the lesson (and also at the end of lesson 9) BTW thank you for the puns in the lessons, those are important ("because it's full of bugs", "42", etc.) 1 0 Oct. 24, 2024
  • Text to fix (and thanks)LaevusTwo small text mistakes to fix in the next update: When explaining lambda's, between the two code examples of the formatting, there's "lamdas". In the optional drop down box "How can I save preferences?" there's the text "you'll learn this in a next module", where "a next" should be either "the next" or "a later", depending on which is correct. But just so it's not all corrections, thanks for the pace change. It's helping me to start engaging my brain more and pay closer attention. 1 0 Oct. 17, 2024
  • Slight refactoringfabulous-giraffeNot a question, more of a note While I see the value in lambdas, I think adding a "change_expression" and "change_body" function called via those lambdas could be helpful, something like : (to avoid typos / simplify refactoring down the line if the dicts names changes for example) ```gdscript func _ready() -> void: body.texture = bodies["pink"] expression.texture = expressions["happy"] button_sophia.pressed.connect(func() -> void: _change_body("sophia")) button_pink.pressed.connect(func() -> void: _change_body("pink")) button_happy.pressed.connect(func() -> void: _change_expression("happy")) button_regular.pressed.connect(func() -> void: _change_expression("regular")) button_sad.pressed.connect(func() -> void: _change_expression("sad")) func _change_expression(exp: String) -> void: expression.texture = expressions[exp] func _change_body(b: String) -> void: body.texture = bodies[b] ``` 1 0 Oct. 02, 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?