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.

  • *Spoiler* Here is the solution to the practice with my reasoning (#).Conrad```gdscript func spawn_candy() -> void: # You have to loop 3 times over the next lines of code! # Note: Practise is asking for always 3 not random compared to the lesson's code. for current_index in range(3): #The radius is the distance from the circle centre #and consequelntly is equivelent to random_distance variable from the lesson #Note: practise is asking for it to be between 0 and 100 so need the randf_range var radius := randf_range(0.0, 100.0) # angle is equivlent random_angle from the lesson (still needs to be random) var angle := randf_range(0.0, 2.0 * PI) #random direction uses the same reasoning as the lesson but instead of random_angle, #its just normal angle (still needs to be random) var random_direction := Vector2(1.0, 0.0).rotated(angle) #refer to my last note regarding the candy.posistion var random_position := random_direction * radius # Instantiate and add the candy as a child of the piñata. const CANDY_PACKED_SCENE := preload("candy/candy.tscn") #this bit was confusing as required memory on the syntax from previous lessons var candy: Node2D = CANDY_PACKED_SCENE.instantiate() add_child(candy) #instead of doing the posistion calculation here we use the "random_posistion" variable, #to store the calculation first candy.position = random_position ``` Feedback for GDquest: - A hint should probably include the syntax for the "var candy: Node2D = CANDY_PACKED_SCENE.instantiate() as this was from previous lessons and was not autofilled and hard to remember (personal take) - Part of the confusion for this practice I believe centers around a lack of explaining the math and how distance from the center circle is equivalent to the radius plus it is probably worth mentioning in the lesson a bit more about radians incase people miss the hyperlink to the dedicated explanation page (https://school.gdquest.com/glossary/angle_radians) Definitely the hardest practice so far! 9 8 Jun. 13, 2024
  • Some encouragement for anyone struggling with this practice.sharethepuddingI had a really hard time with this one and, in the end, had to look at the solutions. I think that's okay, and if you also had to do the same, don't feel bad. I only ever took introductory geometry in all four years of high school because I kept failing the class. (I barely graduated.) But whenever I've been struggling with a concept, I read over all the questions and answers in this Q&A section, look up videos on it, and generally try to digest the information. It might not be as fast as I want to progress or understand, but I do know a lot more about radians now, last lesson I looked up "what is a sine wave" and yeah that was overwhelming. But I only stuck with the basic videos. Basically, I'm doing my best to enjoy the ride and expand my knowledge. It turns out math is pretty interesting when applied to games. I always try to open up a project in Godot and recreate the practices from memory, and if I can't, I look over the lesson again, look up more videos, etc. It's time-consuming, but I know 1000% more about this stuff than I did a month ago. I hope you stick with it 1 6 Jul. 24, 2024
  • This is too much math.ChunkyBitesThe practices are either way too easy (just add queue_free to the code), or impossible. I have no idea how to solve the Pinata practice "legit", without just copy-pasting the code we were provided for the circle spawn. Frankly, i found this entire lesson was WAY too hard on the math. For someone like me who understands precisely nothing about Vector math, much less what a Radian even is, this is just too much information to take in. I like a lot of what i've gotten out of this course, anything about how Godot works is great, but my god, have mercy on us mathematically handicapped people. 11 6 Apr. 06, 2024
  • Idea to help the students struggling with algebraAdrHi, I have read several comments asking for more details about the algebraic elements used in the code examples. Once upon a time, I was confronted with the problem of having to explain these concepts. I hope it's not rude to share, but here's a procedure that in my experience can work. The trick I rely upon was positional state representation and transformation (which we are implicitly doing here) in the context of mobile robots, because that allows for a very gradual increase in the complexity of the exercise. And people tend to like robots :). Please picture a scene with a visual representation of a cartesian coordinate frame and a little rectangle shape representing a little robot with googly eyes, so that there's an idea of direction. First stage: explain the how the position of the robot is encoded relative to the coordinate frame. Show that by changing x or y, the robot is displaced relative to the coordinate frame. Explain the vector being a essentially a more compact way to represent x and y together. Second stage: explain the concept of vector and scalar multiplication. Assign a non zero vector position and show how by scaling the factor, the position is affected. A slider really helps hammer the concept home. Third stage: the yaw. Explain that the 2D coordinate frame is a projection from 3D and that we have an imaginary rotation axis. Graphically represent two stages of the same object with only a yaw difference. I found that it helps to make the reference frame local to the object to simplify the drawing and the trigonometry. Visually showcasing the right triangles and where the cos is, the sin is, with some reminder of their definition tends to help people having previous bad experience with trigonometry. Fourth stage: moving the center of rotation and introducing polar coordinates to explain the contribution of the rotation to the objects position state. And to highlight that all of what we are doing is impose arbitrary conventions to model reality and that switching convention is like changing the perspective you have on a puzzle. Fifth stage: Introduce the matrix representation of the rotation and how vector position times rotation matrix is really just another way to write what we had just in the previous stage. This is probably the toughest stage in my experience. It tends to help to insist that once again, this is just a way to represent information in a yet different way. Sixth stage: Introduce translation plus rotation combinations and the couple rules that are to be followed, with visual representation of the consequences of "messing up" the order. Seventh stage: Present the way the framework under use simplifies most of the notations by providing convenience helpers (like rotated in Godot). Eighth stage: Provide something that brings the pieces together and gives a feeling of mastery. For instance, a small toy controllable by the arrow keys demonstrating the Kinematic bicycle model or a tank-like one. Thank you for reading so far. I hope that this suggestion does not come across as rude or arrogant as that is not my intent. Having faced people struggling with these concepts in the past (and remembering struggling myself when I first learned them), a part of me couldn't help but share what I had on the subject. I wish you a pleasant day. :) 3 3 May. 29, 2024
  • How to change array drop % for items.fledgerIf we wanted to make the key item spawn 10% of the time and say the apple 60%. How should one go about this? I figured this type of drop chance will matter a lot in various game types! 4 3 May. 26, 2024
  • L6.P1: Cannot pass random position checknear-octopusHi, with L6.P1, I'm unsure what is causing my code to fail? I can pass "When clicked, the balloon spawns 3 candies", but I can't pass "The candles are spawned at random positions around the balloon, within a 100 pixels radius." I can't see what is wrong with the logic I have written though. My full code for `balloon_piñata.gd` is below: ```gdscript extends Area2D func _ready() -> void: randomize() func _input_event(viewport: Node, event: InputEvent, shape_index: int): var event_is_mouse_click: bool = ( event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed() ) if event_is_mouse_click: spawn_candy() input_pickable = false queue_free() func spawn_candy() -> void: # You have to loop 3 times over the next lines of code! for current_index in range(3): # Complete the variables to calculate a random position in a circle using polar coordinates. var radius := 100.0 var angle := randf_range(0.0, 2.0 * PI) var random_direction: Vector2 = Vector2(1.0, 0.0).rotated(angle) var random_distance: float = randf_range(0.0, radius) var random_position: Vector2 = random_direction * random_distance # Instantiate and add the candy as a child of the piñata. const CANDY_PACKED_SCENE := preload("candy/candy.tscn") var candy: Node2D = CANDY_PACKED_SCENE.instantiate() candy.position = random_position self.add_child(candy) ``` 16 3 Mar. 24, 2024
  • Function names not starting with underscoreFasionMagazineI'm wondering why some functions don't start with an underscore. If a leading underscore indicates the function is meant to be used only in the script it was written, won't the vast majority of functions have a leading underscore? Or are functions used outside of the script they're written in semi often? Why wouldn't the open() function and set_outline_thickness() have a leading underscore if they seem specific to the chest? 3 2 Apr. 20, 2024
  • add_child adds the items to the chests scene hierarchy instead of the miniDungeon scene MarcJI noticed that add_child is called from the chest scenes and so adds the items spawned under the chests scene hierarchy (I confirmed this using the remote tree). In this case it's not really an issue but I would think that in most situations you would want the items spawned under the parent scene for a number reasons. For example if the chest was released with queue_free. Does that make sense? To do that what would be a good approach? send a signal to the parent so it would handle spawning the items? Have a reference to the parent scene in the chest and call add_child on that? 6 2 Mar. 25, 2024
  • Bug in Practice L6.P1 (v4.0.9.0 on Linux)stark-echidnaI've noticed a bug in the practice session L6.P1 (using the files with the version 4.0.9.0 on Linux). This code will result in an error, claiming the 2nd point is not met (random position in a 100 pixel radius): ```gdscript func spawn_candy() -> void: # Instantiate and add a random candy as a child of the piñata. # Use the possible_candies.pick_random() function to pick a random candy. var candy: Node2D = possible_candies.pick_random().instantiate() # Complete the variables to calculate a random position in a circle using polar coordinates. var random_angle := randf_range(0.0, 2 * PI) var random_direction := Vector2(1.0, 0.0).rotated(random_angle) # The random distance should be a random value between 0 and 100. var random_distance := randf_range(0.0, 100.0) # Finally, position the candy at the calculated random position. add_child(candy) candy.position = random_direction * random_distance ``` However, this code will run without issues: ```gdscript func spawn_candy() -> void: # Instantiate and add a random candy as a child of the piñata. # Use the possible_candies.pick_random() function to pick a random candy. var candy: Node2D = possible_candies.pick_random().instantiate() add_child(candy) # Complete the variables to calculate a random position in a circle using polar coordinates. var random_angle := randf_range(0.0, 2 * PI) var random_direction := Vector2(1.0, 0.0).rotated(random_angle) # The random distance should be a random value between 0 and 100. var random_distance := randf_range(0.0, 100.0) # Finally, position the candy at the calculated random position. candy.position = random_direction * random_distance ``` The only difference between the 2 codes is the line add_child(candy). It seems that not placing the line directly after filling the variable will mess with how the code is checked. 1 1 Oct. 03, 2024
  • Hint error(?)KupoHello im not sure if i did the excercise wrong in the end or if the hint is not up to date, i like to review the hints after i finish the task since that can bring to light some things i missed, anyways i saw that the first one mentions a  `possible_candies.pick_random()` function that does not exist on the exercise i got, i also do not see an array of candies for that matter, i was able to complete the task with just the instantiated candy by using CANDY_PACKED_SCENE, id like to know if there is an array for this and i just missed it 1 1 Sep. 24, 2024
  • "The Pinata" practice bug in 0.8.0alarming-baboonThe Sprite2D in candy_red.tscn has no Texture assigned. When running the practice scene, although it marks the 3 candies spawn objective as passed, having only 2 visibles candies feels weird. (Assigning candy_red.png to the Sprite2D fixes the problem in the practice result, however not in the Reference scene) 3 1 Sep. 22, 2024
  • Four questionsNikita Myshkin1. What we use the `in` operator for. I have not found information on the Internet about such operators as`in`, `is`, `and`. Even in the Godot documentation. Do you know any websites with information about these operators? 2. Do I understand the `loop`working principle correctly? The `randi_range()` function takes information from the `_spawn_random_item()` function selects an object/scene and returns it to `range()`. Is everything right? 3. Do I understand correctly that an Argument is something that fills itself in when something is returned. Is the parameter what I fill in? 4. `var random_angle := randf_range(0.0, 2.0 * PI)` I don't understand a bit why the first parameter is 0.0. The value 0.0 is the x coordinate and 2.0 is the y coordinate. Then why are we multiplying only y by PI? I understand why we multiply. In order to get 360 degrees. PI is 180 degrees. I was only discouraged by the practical work, in which I got lost, like in a maze. It is very different from what was in the lesson. It's just that this lesson is already quite difficult to understand. Before that, the lessons were simpler and the practical work was appropriate. And if you ask me, what exactly discouraged me. I won't be able to answer clearly, because almost everything. For example, why are the names of variables without random? At first I thought it was a hint that they shouldn't be random. Although the assignment says that they should be random. Or why is this line with the scene located at the bottom of the const `CANDY_PACKED_SCENE := preload("candy/candy.tscn")` function? Although you said they should be at the top. Nevertheless, I am still satisfied. Thanks! 2 1 Jun. 26, 2024
  • L6.P1 is needlessly confusinghefty-pigI found the starter code to be pretty confusing to work through. The question itself is fine and I certainly don't mind having to take a moment to parse the code but in changing the variable names from the text to the starter it could probably be better stated what you want the student to do with it. I think that might be a source of some of the frustration that seems to be directed at this lesson. I did solve the question, but I wound up just ignoring the ponderous 'radius' and 'angle' variables and don't have too many qualms about deriving the correct solution but the friction left me feeling 'unsatisfied' with the solution. Otherwise keep up the good work, the course is one of the best I've seen for programming classes! 4 1 Jun. 21, 2024
  • Small details in practice.AphexIt's probably a nitpick but it would help me a lot if the practice scripts kept the same variables as the script we worked on for our projects. Something as simple as the angle variable in the practice, to me should be random_angle like we've done in the project. It throws me off guard also to see radius as a variable when we never used it in the project (Even if it means the same thing as the variable in our project script). Idk maybe it's just me. 4 1 Jun. 03, 2024
  • Question on unchaining functionsHermundureI tried to "unchain" the random item spawn function to see if I grasped the mechanics. Below is the original code, my approach without looking anything up and the working solution after looking at M5. Why did my approach throw an error, which problem did I ignore? ```gdscript #This is the course code: func _spawn_random_item() -> void: var loot_item: Area2D = possible_items.pick_random().instantiate() add_child(loot_item) #This is what I tried but it has thrown an error: func _spawn_random_item() -> void: var loot_item = possible_items.pick_random() loot_item.instantiate() add_child(loot_item) #This is my working "unchain" solution after checking M5 again: func _spawn_random_item() -> void: var loot_item = possible_items.pick_random() var loot_scene = loot_item.instantiate() add_child(loot_scene) ``` 2 1 Apr. 12, 2024
  • Having a problem with the practicehappygavgavI am trying to spawn the candies and I am getting the error telling me I am not spawning the candies in random positions. Could you help show me what I am doing wrong here? func spawn_candy() -> void: # You have to loop 3 times over the next lines of code! for current_index in range(3): # Complete the variables to calculate a random position in a circle using polar coordinates. var radius := 100.0 var angle := randf_range(0.0, PI * 2) var random_direction := Vector2(1.0, 0.0).rotated(angle) var random_position := random_direction * radius # Instantiate and add the candy as a child of the piñata. const CANDY_PACKED_SCENE := preload("candy/candy.tscn") var candy: Node2D = CANDY_PACKED_SCENE.instantiate() add_child(candy) candy.position = random_position 2 1 Apr. 06, 2024
  • @export usagebumpy-kookaburaWhy is the @export encouraged. I can´t properly understand the difference or the advantage of using export rather than defining and @onready list of preloads. 1 0 Dec. 03, 2024
  • Items going into wallsscary-mallardHi, when a chest is close to a wall, there's a chance that an item will spawn in the wall. How to avoid that? Raycasting to detect walls and adjust angle and distance? Something like a vector that will go 360 from chest's center and "draw" an area where the item can be spawned. What is the best (easiest and efficient) way to do this? 1 0 Nov. 24, 2024
  • Array mentionned in the practice description nowhere to be foundCptnNuggetsHello there, I just had a massive brainfuck trying to choose the spawned candy among an array "possible_candies" mentioned in the practice description... that, as far as I can tell, doesn't exist (at the very least, I didnt find it and it wasnt required to complete the practice). Something to look into. Anyway, thanks for the great work, this course is a gold mine :) 3 0 Nov. 23, 2024
  • Alternate ordering and way of using loopJohnyWuijtsNLWhen I tried to add the random spawning myself before doing the lesson, I used the range function like this: `for i in randi_range(1, 4):` And when I did the lesson, I noticed I did it "wrong" however it still worked, it spawned between 1 and 4 items just as expected. Is this bad practice? It didn't work when I was doing the "pinata" practice lesson. I also changed the ordering of the instantiation, first I instantiate, then I set a location, and THEN I added the object as a child. That worked just fine for the project, but again in the pinata practice, it kept saying I didn't do it properly until I set the location after adding the candy as a child. Is it bad practice to change the location or other properties before adding an object as a child? 3 0 Nov. 02, 2024
  • Loot explosionElfaronCarnotI use create_timer() and add a little tween to create mini loot explosion effect. I think it looks pretty cute. So, I thought I'd share. Reviews and ideas for improvement would be much appreciated :) ```gdscript func open() -> void: animation_player.play("open") input_pickable = false if possible_items.is_empty(): return for current_index in range(randi_range(2, 5)): _spawn_random_items() await get_tree().create_timer(0.1).timeout func _spawn_random_items() -> void: var loot_item: Area2D = possible_items.pick_random().instantiate() add_child(loot_item) var random_angle := randf_range(0.0, 2.0 * PI) var random_direction := Vector2.RIGHT.rotated(random_angle) var random_distance := randf_range(60.0, 80.0) var final_position = random_direction * random_distance var tween := create_tween() var duration := randf_range(0.4, 0.8) tween.set_ease(Tween.EASE_OUT) tween.set_trans(Tween.TRANS_EXPO) tween.tween_property(loot_item, "position", final_position, duration) ``` Edit: I've just realised that animating the items would be covered in the next lesson 🤣 1 0 Oct. 30, 2024
  • Is this a bug or is it me? scientific-tarsierI initially wrote my spawn_candy() function with the following code: var candy etc. var random_angle etc. var random_direction etc. var random_distance etc. add_child(candy) candy.position etc. For some reason when I did it like this it was saying I'd failed the second part of the practice. (And it didn't have the pngs of the balloon linked to the sprite2Ds, but I don't think that made a difference.) It was only when I moved the add_child(candy) function to after the var candy that it worked. I'm not sure if this is because I was doing this in the wrong order or if it's because of an interaction with the plugin? 1 0 Oct. 21, 2024
  • Balloon textures are missing in L6.P1milkyfoxIt looks like textures for the Sprite2D nodes (*Bottom* and *Top*) are not set correctly in `balloon_pinata.tscn`. When I ran the practice, I don't see the balloon displayed, it only spawns candies. I checked the texture property in *Bottom* and *Top* nodes, and empty CompressedTexture2D are set for both of them. I could fix this by dragging png files from FileSystem dock to Texture property in Inspector. The project files were `l2dfz-0.9.0-win.zip`. I downloaded it on October 15th. 1 0 Oct. 21, 2024
  • the_pinata is bugged, solution code drops 2 candiesearly-turtleHi! This one really stumped me, especially because I was in an older version. Updated to 0.9 version and checked out the solution project and used the code for the workbook. The workbook plug in gave a "correct answer" but the code (from the Solution project) only spawned 2 candies and the balloon pops by itself. I took a screenshot but I can't upload it here, but this is the code copied over from the Solution project that makes it so only 2 candies spawn but its still taken as correct by the plug in. ```gdscript func _ready() -> void: randomize() func _input_event(viewport: Viewport, event: InputEvent, shape_index: int): var event_is_mouse_click: bool = ( event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed() ) if event_is_mouse_click: input_pickable = false for current_index in range(3): spawn_candy() func spawn_candy() -> void: var candy: Node2D = possible_candies.pick_random().instantiate() add_child(candy) var random_angle := randf_range(0.0, 2.0 * PI) var random_direction := Vector2(1.0, 0.0).rotated(random_angle) var random_distance := randf_range(0.0, 100.0) candy.position = random_direction * random_distance ``` 3 0 Oct. 18, 2024
  • The items that spawn are below the lid of my chestsubstantial-tarsierNot sure why but I can't seem to figure out how to change this. I asssume it has to do with the order that Godot is rendering the nodes. But the items are above the bottom and below the lid. Only really noticeable when the random position my item lands on happens to also be where the lid landed in my tween animation. 1 0 Sep. 28, 2024
  • BalloonPinata exercise: What did I do wrong?datiswousSo I've the following code for the spawn_candy() function in the BalloonPinata exercise: ```gdscript func spawn_candy() -> void: # Complete the variables to calculate a random position in a circle using polar coordinates. var random_angle := randf_range(0.0, 2.0 * PI) var random_direction := Vector2(1.0, 0.0).rotated(random_angle) # The random distance should be a random value between 0 and 100. var random_distance := randf_range(0.0, 100.0) # Instantiate and add the candy as a child of the piñata. # Then, position the candy at the calculated random position. const CANDY_PACKED_SCENE := preload("candy/candy.tscn") var candy: Node2D = possible_candies.pick_random().instantiate() add_child(candy) candy.position = random_direction * random_distance ``` This doesn't pass me the test. It says I forgot to randomize the position of the candy, but that is what I did I think. 4 0 Sep. 27, 2024
  • PlaceholderdatiswousI did not understand what this text means: > Functions that return a value can be used as a placeholder for the value they will return. So, you can chain or nest function calls when they're compatible. 2 0 Sep. 26, 2024
  • Don't understand radiansdatiswousSo here is some text: > We start by defining a random angle. Remember that we are working with [radians](https://school.gdquest.com/glossary/angle_radians) by default as the angle unit in game engines. Two times *PI* radians correspond to `360` degrees, a full turn. So, we need to generate a value between zero and `2 * PI` to generate points within a full circle. Add this code to the `_spawn_random_item()` function: I don't understand the Radians explenation. It's simply too complicated. > Because the perimeter of a circle is 2π multiplied by the circle radius, and one radian corresponds to an arc as long as the radius of the circle, there are 2π radians in a circle. This is jibberish. If I don't know any of these numbers, how can I picture how this works? > Two times *PI* radians correspond to `360` degrees, a full turn. How? 2 0 Sep. 26, 2024
  • Spawning Specific Items as wellYourFriendJoeyComing back to this lesson after having finished later modules, I wanted to try adding a feature of having the chest guarantee specific items spawn, as well as spawning random ones. Can you tell me if this approach seems sensible? Or perhaps other ways you might approach it? Thanks again; all your hard work is truly phenomenal. First, I added a similar exported array called "specific items" `@export var specific_items: Array[PackedScene] = []` Then, in `open_chest()`, I added another for loop that iterates through the items on `specific_items` list, and pass them as an argument to a function called `spawn_specific_item()` in order to instantiate them. I did this because I couldn't think of a way to do it just within the function itself (like how `possible_items.pick_random().instantiate()` works in `_spawn_random_item()`) And then everything else in *_*spawn_specific_item works similarly to `_spawn_random_item()` Let me know what you think, thanks! ```gdscript extends Area2D @export var possible_items: Array[PackedScene] = [] @export var specific_items: Array[PackedScene] = [] #... func open_chest() -> void: input_pickable = false chest_anim_player.play("open") if possible_items.is_empty(): return for current_index in range(randi_range(1, 3)): _spawn_random_item() if specific_items.is_empty(): return for item_scene in specific_items: _spawn_specific_item(item_scene) func _spawn_specific_item(item_scene:PackedScene) -> void: var loot_item:Area2D = item_scene.instantiate() add_child(loot_item) var random_angle := randf_range(0.0, 2.0 * PI) var random_direction := Vector2.RIGHT.rotated(random_angle) var random_distance := randf_range(60.0, 120.0) loot_item.position = random_direction * random_distance func _spawn_random_item() -> void: var loot_item:Area2D = possible_items.pick_random().instantiate() add_child(loot_item) var random_angle := randf_range(0.0, 2.0 * PI) var random_direction := Vector2.RIGHT.rotated(random_angle) var random_distance := randf_range(60.0, 120.0) loot_item.position = random_direction * random_distance ``` 2 0 Sep. 23, 2024
  • Is the proper solution for the Practice supposed to be a square?elastic-kingfisherHello, In the Practice for this Lesson, the variables are given to us in a specific way for checking, but wouldn't a Vector2 for the *random_position* Variable create a square with the possibility of a Vector greater than 100 pixels, which deviates from the instructions? Please advise :) 1 0 Sep. 12, 2024
  • "_" vs !"_" in front of functions?graceful-clamCan I get another example on this so that I can better understand it conceptually. For instance, in our script, "open" seems like it would be a chest only function, so wouldn't it be "_open"? Same with set_outline_thickness. Whereas, _on_mouse_entered seems like it could be called in any script? It seems like something that may be subjective to the coder to decide, but it seems so foundational for me to at least get a better grasp so I can make calls like this in my own code. 1 0 Sep. 01, 2024
  • How to make the chest spawns chest indefinitely ?FlyeramI just tried to add the chest scene "chest.tscn" to the possible_items array in the inspector. Then, I've encountered to cases : First, I add the chest in the *possible_item* array of an instance of the chest from the inspector, available on the mini_dungeon scene tree and this work well. Second, I want to add the chest in the Chest scene *possible_item* array in the inspector (So that chest can be spawn of spawned chest), I get this error : ```gdscript scene/resources/resource_format_text.cpp:1870 - Circular reference to resource being saved found: 'res://lessons/chest.tscn' will be null next time it's loaded. ``` Thanks for the help to let me understand how things are handled differently ! 3 0 Aug. 29, 2024
  • M6L6: Why does items only spawn on the right side of the chest?DefumakI followed all the lesson and I can run it without errors, but I'm curious why does the items are only spawned on the right side of the chest? ```gdscript var loot_item : Area2D = self.possible_items.pick_random().instantiate() var random_angle := randf_range(0.0, 2.0 * PI) var random_direction := Vector2(1.0, 0.0).rotated(random_angle) var random_distance := randf_range(60.0, 120.0) loot_item.position = random_direction * random_distance ``` If I understand correctly, the random angle should point to any place in a full circle, which means, any place around the chest. Is there something missing when converting the angle to the direction? Also, is there any difference in case I use: ```gdscript var random_direction := Vector2.from_angle(random_angle) ``` 3 0 Aug. 27, 2024
  • Question about constantlordcyber12I finished my practice lesson , but I don't understand the reason to have the constant CANDY_PACKED_SCENE inside of a function that will be called 3 times. Can you explain the reason of a constant there ? 1 0 Aug. 26, 2024
  • Math questionMLI think I understand the random_angle and the random_distance, but I struggle understanding the direction part. Could we start with any unit vector? Would Vector2(0.0, 1.0) also work? Why or why not? When we then call .rotated(random_angle), I understand this as pointing the vector to the direction we received from randf_range(0.0, 2.0 * PI). What does it mean to be a point of reference for angles? 1 0 Aug. 25, 2024
  • can someone point what these 2 lines of code represents in radians? betoharres ```gdscript var random_angle := randf_range(0.0, 2.0 * PI) var random_direction := Vector2(1.0, 0.0).rotated(random_angle) var random_distance := randf_range(60.0, 90.0) ``` 1 0 Aug. 16, 2024
  • spawn-items-in-a-random-circle-around-the-chest lacks visual explanationbetoharresreading the explanation of polar coordinates makes me try to visualize more than actually understanding the section. It's clear that this section begs for images 1 0 Aug. 15, 2024
  • solution to empty chest betoharresthe lesson doesn't mention it(which should), but you have to fill **EACH** chest with the possible items scenes, or you can go to the chest scene and fill it there by default 1 0 Aug. 15, 2024
  • Failing second check in The pinataopulent-crocodileHi, first wanted to say how brilliant these courses are so far, but this has proved to be a particularly tricky one for sure! I also am a little light on maths, so with all the folks here who have commented on the ramp up in difficulty. I'm falling at the second hurdle in the pinata exercise and getting a red fail on the candies spawning in random positions, but strangely it seems to work visually and look identical on the two views, so not sure what is wrong? (I just looked at it again and switched out 6.283 for 2.0*PI and it goes through fine so it seems that was making it think the candies werent getting ditributed correctly, but I'm posting this anyway in case that is something that shouldn't cause it to fail?) Here's my code > ```gdscript func spawn_candy() -> void: # You have to loop 3 times over the next lines of code! for current_index in range(3): # Complete the variables to calculate a random position in a circle using polar coordinates. var radius := randf_range(0.0,100.0) var angle := randf_range(0.0, 6.283) var random_direction := Vector2(1.0,0.0).rotated(angle) var random_position := Vector2(random_direction * radius) # Instantiate and add the candy as a child of the piñata. const CANDY_PACKED_SCENE := preload("candy/candy.tscn") var candy: Node2D = CANDY_PACKED_SCENE.instantiate() add_child(candy) candy.position = random_position ``` 1 0 Aug. 09, 2024
  • L6.P1 - Auto mouse clicking for meIronEvaWhen clicking 'RUN' on the L6.P1 GDQuest panel, the test automatically clicks the balloon for me and I was wondering if this is the intended behaviour? I'm asking because when I clicked Run, I would see the balloon and then click on it with **my mouse button** which would spawn 3 balloons but then the game would automatically click it and then spawn another 3 balloons which would then fail. I was so confused by this as sometimes it passed and sometimes it failed. Turns out I was the problem. Here is a gif of it happening. [https://jmp.sh/s/4gEoP04fyVKKqP8825Jv](https://jmp.sh/s/4gEoP04fyVKKqP8825Jv) Placing this here just in case I did something silly in the code. ```gdscript func spawn_candy() -> void: # You have to loop 3 times over the next lines of code! for current_index in range(3): # Complete the variables to calculate a random position in a circle using polar coordinates. var radius := randf_range(0.0, 100.0) # this just means, how far away are you from the origin var angle := randf_range(0.0, 2.0) * PI # how far round are you var random_direction := Vector2(1.0, 0).rotated(angle) # I understand but the maths slaps me var random_position := radius * random_direction # Instantiate and add the candy as a child of the piñata. const CANDY_PACKED_SCENE := preload("candy/candy.tscn") var candy: Node2D = CANDY_PACKED_SCENE.instantiate() add_child(candy) candy.position = random_position ``` 2 0 Jul. 28, 2024
  • .rotated() confusionIronEvaSo I understand as I am very confused by this, does the .rotated() method convert a radian value into a vector? What is the .rotated() doing in the background when it is run? 1 0 Jul. 25, 2024
  • Maths IronEvaHey GDQuest, Math isn't exactly my best friend, which can be frustrating. Every time a new concept pops up, I feel like I fall down this endless knowledge rabbit hole that pulls me away from the GDQuest course. Sometimes I come back even more confused than before, and then the negative thoughts play through my head: "You're terrible at math... You're just not good at it... Maybe you should give up." (But nope! Not gonna listen to that!) I'm learning so much new stuff with this course every day, and I don't want to let those voices win. :) I was wondering if you could point to math resources at the start of the lessons. I've seen some incredibly helpful comments from other GDQuest students mentioning Khan Academy [https://www.khanacademy.org/](https://www.khanacademy.org/) or [https://nrich.maths.org/](https://nrich.maths.org/) but I am unsure where to even begin in these places. 3 0 Jul. 20, 2024
  • Question about rotated(angle)HazlarHello, I don't quite understand how `var random_direction := Vector2(1.0, 0.0).rotated(random_angle)` works, I understand that indicating the position "right on .x" as the starting point of the angle but by having modified the argument by `var random_direction := Vector2(1.0, 0.0).rotated(deg_to_rad(270))` the loot appears at 12 o'clock but it should rather appear at 6 o'clock right? is this due to the inversion on the .y axis between negative and positive phase? because by convention in math (according to the courses I am following) if we start on the right as a reference point we circulate in the counter-clockwise direction it seems to me for positive angles. Thanks 1 0 Jul. 15, 2024
  • Question about the random positionagrateFor the purposes of the item spawning would these two statements be the same, since the position of the loot item when it is added as a child to the scene (I assume) starts at 0, 0?: `loot_item.position = random_direction * random_distance` `loot_item.position += (random_direction * random_distance)` 1 0 Jul. 10, 2024
  • Current_Indexsnowm8nI've been trying to understand the concept of **current_index** in this lesson. It wasn't clear what it does or how to use it. I looked in the 2D course, the Godot documentation, and online, but nothing really stood out. Can you explain what **current_index** does and when to use it? Or was this an arbitrary name, like a variable? Strange Feature Request: I tried to search **current_index** with CMD F, but the Q&A won't play nice (default, it is hidden with an accordion). It would be super cool to be able to search Q&A using CMD F 💪 4 0 Jun. 30, 2024
  • Error Invalid callLestat LeyvaNot sure what I did wrong. I got a error message: Invalid call. Nonexistent function 'instantiate' in base 'Nil'. When I run the chest portion by itself it works fine. The issue seems to be when I run it in the Mini dungeon (Main). 10 0 Jun. 09, 2024
  • Spawned items receiving generic names in Remote viewA_Room_With_A_MooseIs there any way to change the node names of the duplicate items that spawn from each chest as opposed to leaving them with the generic name that Gadot applies to them? For example, currently if a chest spawns one Apple and two Keys, they could show in the Remote viewer as Chest > Apple, Chest > Key, Chest > @Area2D@3 (<- what the heck is that?). If a chest spawn three of the same item, say a Potion, it could show as Chest > Potion, Chest > @Area2D@3, Chest > @Area2D@4. This sequence continues if there are more duplicate items in subsequent chests. This makes identifying a spawned item by its name very difficult if there are a lot of them in the scene. Hypothetically speaking, if we needed to reference all nodes of a given type of loot quickly by name (e.g. Apple1, Apple2, Apple3, etc., which are all "Apple"), it wouldn't be possible using a generic name like "@Area2D@3". What would be the best way of handling this in code? Thank you, I'm looking forward to moving on to your 3D course next! 1 0 May. 27, 2024
  • Adding Scenes to Array Errorhaunting-camelI'm not sure if I've missed something obvious, but I'm not able to add scenes to the "Possible Items" array as described. The 0 <empty> does not light up like in your screenshot (https://puu.sh/K7KyJ/3892d81663.png), though I am still able to add by dragging onto the Array[PackedScene] . I presume that M6L5 & L6 onwards will be a point I have to revisit a number of times to wrap my head around the code (though maybe I need to stop copying the reference code at the end of a lesson and keep my heavily commented version), but if I can 'fix' UI stuff easily then that's at least some progress! 3 0 May. 27, 2024
  • A little flavor suggestionDifio```gdscript extends Area2D func _ready() -> void: randomize() func _input_event(viewport: Node, event: InputEvent, shape_index: int): var event_is_mouse_click: bool = ( event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed() ) if event_is_mouse_click: spawn_candy() input_pickable = falsefunc spawn_candy() -> void: # You have to loop 3 times over the next lines of code! for current_index in range(3): # Complete the variables to calculate a random position in a circle using polar coordinates. # Instantiate and add the candy as a child of the piñata. const CANDY_PACKED_SCENE := preload("candy/candy.tscn") var candy: Node2D = CANDY_PACKED_SCENE.instantiate() add_child(candy) var random_angle := randf_range(0.0, 2.0 * PI) var random_direction := Vector2(1.0, 0.0).rotated(random_angle) var random_distance := 100.0 candy.position = random_direction * random_distance ``` 1 0 May. 21, 2024
  • Error: L6.P1 Pinata practise test.gd scriptei8htbitI enter the following solution in the balloon_pinata.gd script that appears to work when running the scene separately, however when I run through the practice test plugin to assert/validate I get a Stack Trace Error (see below) ***balloon_pinata.gd entry*** ```gdscript # ... func spawn_candy() -> void: for current_index in range(3): var radius := randf_range(0.0, 100.0) var angle := randf_range(0.0, 2.0 * PI) var random_direction := Vector2(1.0, 0.0).rotated(angle) var random_position := (radius * random_direction) const CANDY_PACKED_SCENE := preload("candy/candy.tscn") var candy: Node2D = CANDY_PACKED_SCENE.instantiate() add_child(candy) candy.position = random_position ``` ***Stack Trace Error (line 70 test.gd):*** `Out of bounds get index '0'(on base: 'Array[Node]')` ***Stack Frame:*** `0 - res://addons/gdpractice/practice_solutions/L6.P1.the_pinata/test.gd:70 - at function: <anonymous lambda>` ***Line 69/70 of test.gd for quick ref:*** ```gdscript for idx in range(practice_candies.size()): is_position_same_a.push_back(practice_candies[idx].position.is_equal_approx(solution_candies[idx].position)) ``` I'm not sure what elements may have thrown this out of whack but just in case it helps prevent future bugs for others figured I'd raise it here. 1 0 May. 20, 2024
  • M6.L6: A thoughtjonathajI have been enjoying these lessons so far and have learned allot. I currently just finished M6.L6 and, looking through some of the other comments here, i also struggled a bit here. Specifically, the "spawn items in a random circle around the chest" section. I don't know if its my lack of knowledge dealing with vector math, but this section took me several read throughs to understand what was being said. I think the difficulty started for me with this sentence: "We can convert the angle to a direction vector and multiply the direction vector by the distance to get a random point within a circle." That's allot to take in and threw my brain through a loop. Maybe that sentence could be broken down into simpler concepts? Another thing that confused me was after we did the calculation for the random_angle, you said: "We can then convert this angle to a direction". Why do we need to convert this to a direction? Maybe have an explanation why we need to do this. Also when talking about the rotated() function it is said: "The function returns a rotated copy of the vector based on the angle we pass as an argument." For me that's hard to understand without a visualization, maybe a image of a circle with how the vector changes could help? This section seemed to go pretty fast over this concept compared to the other sections i have done. For example in M4.L5, i thought you guys did a fantastic job explaining the concepts behind the steering vectors and visualizing that for us. Maybe something like that for this section could help make it more understandable? Other than that i think the course has been great so far and i look forward to the future lessons. Keep up the great work! 1 0 May. 20, 2024
  • Difficulty jump was too vast with this lesson, feeling lost and confused!leafI'm at a complete loss at what to do coming to L6 - the complexity seems to have sky rocketed, and what I have learned from previous lessons aren't setting a foundation to even know where to begin with the practice lesson. It also doesn't help that the scripts used for the practice lesson seem slightly different from what we have been working with in the lesson. Typically I would have mountains of questions about the actual content and learning material when I would become lost or confused, but at the moment my only questions are - How can I proceed? Do I need to start over, again? Which lessons am I needing to redo, what concepts am I not grasping or understanding? What even are the questions that I need to ask in order to understand what I need to understand to move forward? What did I do wrong in my studies and practices to miss the vital information needed to secure a foundation to use these methods and techniques to succeed in this lesson? Why is this the lesson I feel like I have learned nothing, and success is yet again impossible to achieve? 14 0 May. 11, 2024
  • Listening to signals from packed scenesHermundureAs we learned so far, we need to @onready var apple: Area2D = $Apple to preload a node and afterwards connect it in the _ready() function with a function of our liking, for example: apple.picked_up.connect(_on_picking_apple_up) (This is no built-in-signal by Godot, its just an example signal that the apple emits at some point.) Now, if the apple node is part of my scene tree I can follow the procedure above and can work with the signal. But what if, like in this exercise, the apple is NOT part of the scene tree but instead is part of a @export var possible_items: Array[PackedScene] = [] How is it possible to listen to the apples signal in this case? 4 0 May. 08, 2024
  • Item scenes are causing a crashfine-cattleEven with the exact code copied and pasted from this lesson, I'm crashing every time I run the game. I believe the issue is with the item scenes that I added to the array because I cannot open any of them. Each time I try to open the apple scene or either of the other two just as a scene to take a look at their code, Godot crashes. Could this be a file organization issue? I'm on Mac, using the proper version of Godot. Everything worked fine until the item array steps and adding the items. 12 0 May. 02, 2024
  • What if I want each chest to only give one type of loot?tesfalconHow do I isolate each chest instance so that each chest gives x loot and only x loot? In your final example, the chests randomly chose whether to give apples, keys, or potions. What if I want that left chest to ALWAYS give apples, the center chest to ALWAYS give keys, and the right chest to ALWAYS give potions? 3 0 Apr. 28, 2024
  • Suggestions: Visual for Polor coordinates explanationill-fated-heronHello, The title already explained pretty much but I think it would be a nice addition to illustrate the algo used to coordinate the point in circle. I know you did something similar in a previous session explaining vector in general and it was really helpful. 2 0 Apr. 26, 2024
  • Error in lesson descriptionAlainThis sentence: `In the previous module, **we learned how to spawn items and place them randomly.** This time, we will build upon that and make the system more flexible using exported variables.` But no, in the previous lesson we opened the chest when clicking. I guess you refactored the lessons and merged spawning the items + variable export and forgot to change the text. 2 0 Apr. 17, 2024
  • Preload vs. Packed ScenesHermundureIs it advised to work with one way over the other? Right now, I feel like creating an array of preloaded items through code is more easy to read and understand afterwards, as everything happens in one place and is not "outsourced" to a different place. Does this impression change over time, are there drawbacks on using one way over the other or is it ok to stay with the preload-way of filling the arrays? 3 0 Apr. 13, 2024
  • Difficult lessonicy-codWhy are input events so complicated? Why would you want to use this? Difficult lesson in general. 1 0 Apr. 07, 2024
  • Resolution in Practices is weirdgbrownFor M5, the practices looked crisp and clear. Since M6, when I run any practice, it looks very pixelated. Especially the writing on the left side shows the effect and is hard to read. Any idea, what this might be? 2 0 Apr. 05, 2024
  • Another small error in the lesson textCerealHello in this lesson it says "In *M5. Looting*, we generated coordinates inside a rectangle representing our game window." I believe it should be "In *M5. Loot it all*, we generated coordinates inside a rectangle representing our game window." Thanks for all the cool course material! 1 0 Apr. 03, 2024
  • How to instantiate just once an element from an array?EddyHi, I try to reuse what I've learnt in this course in a little project: a card game (Patience). What I want is to have each element of the Array just once. But when I create my variable to instantiate the Array, I have an error "Cannot find property "instantiate" in base "Array[PackedScene]. Here's my code for now with the error: **extends Node2D** **@export** var set_cards : Array[PackedScene] = [] **func _ready()**: _set_game() **func _set_game()**: for *x* in range(8): for *y* in range(4): var cards_start = set_cards.instantiate() set_cards.shuffle() add_child(cards_start) var pos = Vector2(x * 200 + 140, y * 220 + 150) cards_start.position = pos I search in the code reference but did not find any methods that could help me. How can I can instantiate my cards only once? To be clear, for the cards I use the pattern than the chest in the course. Thanks. Hoping that I am clear. 4 0 Apr. 01, 2024
  • L6.P1 question about parentingTJI have a question about where to parent the candies! One of the requirements in this practice is: `When clicked, the balloon is freed.` But in hint 3 it says: `Add the candies as children of the balloon node to make them visible in the scene.` Adding the candies as children to a freed node probably wouldn't make much sense, so I was a bit confused about the best approach? What I did was the following, and it passed the test: - Don't free the balloon at all (so not calling `queue_free()`) - Parent the candies as children under the still available balloon, in the same way as explained for the Chest in the course. 1 0 Mar. 29, 2024
  • Instantiating as a Node2DhellobombisthekittyWhen we pick a random item, and instantiate it, we use the type hint of Node2D: `var loot_item: Node2D = possible_items.pick_random().instantiate()` .. but the root node of the items (apple, key, potion) are all Area2D nodes. I recognize that Area2D is a child of the Node2D class (and thus why it likely works) — but is there best-practices with this? Would it be more correct to type-hint with Area2D? 2 0 Mar. 27, 2024
  • Updating instanced variables after adding as a childgsomin function func _spawn_random_item() we called add_child(loot_item) before changing position of instance of loot_item. But that it works can cause a bug (because loot_item is still locates to added child and they are same) and loot_item real value is unpredicted or can be null. It is possible better to call add_child(loot_item) at the end of a function. 1 0 Mar. 25, 2024
  • An experiment of mine failed and I can't figure out whyFeeyraI was trying to make it so my chest could spawn a replica chest that can also spawn it's own items. However, upon doing this I get a returned error about my `possible_item` array: > Invalid call. Nonexistent function 'instantiate' in base 'Nil'. I double checked this by using `print(possible_items)` in my `open()` functions and it returned null for my 4th value. I don't understand why though. We used the Key.tscn, Apple.tscn, and Potion.tscn and they work, so I figured I would be able to use the chest.tscn for a fourth, but I get that error every time it tries it spawn. I attempted to duplicate it, moving the duplicate to the same folder and setting that as the .tscn used (named chest2 for simplicity), however, I run across the same issue. How can I resolve this to make a chest spawn a fully functioning duplicate of itself? 6 0 Mar. 25, 2024
  • Is PackedScene a Node2DGilbertTheGreatIn the @export array we specify that the array should contain PackedScene objects, which represent a .tscn. When we actually instantiate a random scene from the array, it's type hint is Node2D. Could we replace the PackedScene with Node2D when defining the array? Looking at the docs of PackedScene, it doesn't seem to inherit from Node2D. 4 0 Mar. 24, 2024
  • About for loopsBartek PatoletaI remember that in Learn GdScript form zero I've always preferred to use "for n in numbers" instead of "for n in range(numbers)" as godot automatically knows that I want to check a particular array. Is there any difference in using a "range(array)" compared to using array alone? Thank you for another amazing module, Nathan. The slow scaling in learning new things is just perfect. Hope you are managing stress with workload and not overworking yourself. 1 0 Mar. 24, 2024
  • Bug in the Balloon Pinata practice test.gd scriptJanne```gdscript var candy_scene_practice: Node = _load("candy.tscn", true).instantiate().scene_file_path ``` When attempting to run the test using the given practice solutions I encounter an error: "Trying to assign value of type "String" to a variable of type "Node". Godot then directs me to the test.gd script, specifically to line 3 as shown above. 4 0 Mar. 23, 2024
Site is in BETA!found a bug?