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.

  • Confused about the argument for the _on_area_entered functionSingleMom420I'm not able to wrap my head around something fundamental with the way signals pass arguments. In our Ship script, we're first connecting the signal in our ready function, right? The signal is area_entered, which I believe is a predefined signal for all Area2Ds, and then in parentheses we have the function name; AFAIK, the function name is essential because that's what the signal actually *does* when it's triggered (in this case, when a body entered the collision shape). Please correct any of that if I'm wrong. Moving on, what really confuses me is the argument part of the function, which for us is "area_that_entered" and is defined as another Area2D. What I don't understand is how this argument (or is it a "parameter"? I'm terrible with terminology) is understood by Godot as being able to fulfill the role it does. Is it that the "area_entered" signal is already set up in advance to only take Area2Ds as the elements it can interact with, and so as long as we pass any Area2D through the function, Godot will understand that we're saying this is the other body that the Area2D this script is attached to is going to interact with (in our case, that means it's going to check if the Area2D is in either of the defined groups and then call the appropriate function)? I'm also somewhat confused about the name of the argument established in the "on_area_entered" function. Could we call it anything? Could we add multiple parameters/arguments? If so, that would make me even more confused regarding how the engine "knows" what to do with each parameter (like, how does it know the correct way to interpret each argument?). 10 5 Feb. 22, 2024
  • if vs. elifmachinemanWould there be any reason to specifically use elif instead of just another if? When detecting what group the item the ship collided with is in. Is it functionally the same? Is this way more performant for some reason? Just curious! 1 3 May. 05, 2024
  • The question about variablesNikita MyshkinA great lesson! In general, everything is clear, but I am tormented by one question. ```gdscript func set_coins(new_coins: int) -> void: coins = new_coins get_node("UI/CoinsCount").text = "x" + str(coins) func set_energy(new_energy: int) -> void: energy = new_energy get_node("UI/EnergyBar").value = energy ``` Why are we adding `new_coins` or `new_energy` when we don't actually use them. And why do we add them to the parameter and then set a new value below. 2 2 Jun. 23, 2024
  • Node Groups -> via code?Hilton184In a previous lesson, you detailed how setting up signals via code is probably a little more robust for a larger project, since then all your signals will be defined in code and can be searched for more easily, and it will be consistent in how you set up signals. Is setting up groups via code something that can or should be done in an analogous way, rather than setting up groups via the UI? 3 2 Feb. 20, 2024
  • Does string interpolation for Label exist ?Ver2terIs there any way to use string interpolation in Label ? It would be great if we could do something similar to this: In the Label inspector we define this : `"Player has {$nbPotion} potions"` and in the script we could do this `get_node("myLabel").text.nbPotion = 12` 2 1 Nov. 24, 2024
  • Adding the coin script breaks the end resultMarkStruikfirst step: add the sprite, works second step: add the collision shape, works all parts of the verification are now green except the the code attaching third step: attaching the existing script, works except now all verification steps are red. it no longer 'sees' the coin? now i do see the coin being removed/queue_free from the screen so i think the end result is working, but it is not marked as completed. Is there an alternative way of adding the exisiting script without it breaking the verifications? 11 1 Feb. 19, 2024
  • Invalid Access or Property Errorformal-nightingaleI followed the steps outlined and tried running the practice. When the game launches, I see the ship go through all of the coins and energies, and arrive at the end of the loop. The game crashes, however, and I get a message in the Stack Trace that says, "Invalid access to property or key 'coin_count' on a base object of type 'Area2D (ship_coins_and_energy_packs.gd)'. I tried to solve this by naming the coin group coins instead, and while that prevents a crash, the practice lesson won't give me credit because I didn't name the group coin. I assume I've made an error somewhere, but I'm unable to figure out where. 0 0 Dec. 21, 2024
  • function set_rifqilubis ```gdscript func set_gemcount(_new_gemcount: int) -> void: gem_count += _new_gemcount func _on_area_entered(area_that_entered: Area2D) -> void: if area_that_entered.is_in_group("gem"): set_gemcount(1) elif area_that_entered.is_in_group("healing_item"): set_health(health + 20) ``` about set_health(health + 20) i don't understand how set_gemcount(gem_count + 1) and set_health(health + 20) works i know they add exaclty the number say. But why not just set_gemcount(1) like i did? the set_health() function kinda confusing. Why need to type health + 20. i thought the set_health(health + 20) function will pass the argument to original function ```gdscript func set_health(_new_health: int) -> void: health = _new_health elif area_that_entered.is_in_group("healing_item"): set_health(health + 20) ``` **Why you need to type health, when the function itself will pass it to original function.** the bold sentence is my question. it need more explaination, why and how health + 20 works. Thanks. 1 0 Dec. 10, 2024
  • Groups Dock not listing the scene/global groupseager-hyenaHello! Title just about says it all. The dock was more or less empty, without the "+" icon for adding groups. I managed alright by typing the group name in the bar at the top though, so it wasn't any problem. Just curious, is this because of the version I'm using (4.2.2), or am I missing something else? 2 0 Nov. 11, 2024
  • Why not "coins += 1"? Also, multiple "coin types"StorytellerI tried the practice before reading the lesson thoroughly and managed to get it functioning with: --- func _on_area_entered(area_that_entered: Area2D) -> void: if area_that_entered.is_in_group("energy"): energy += 20.0 get_node("UI/EnergyBar").value = energy elif area_that_entered.is_in_group("coin"): coins += 1 get_node("UI/CoinsCount").text = "x" + str(coins) What is the functional difference between my code and the lesson code? --- I have another question. Suppose I want to have multiple types of coins or health pickups, like a special coin that's worth 10 coins. I know I could add an entirely different group, EG: elif area_that_entered.is_in_group("big_coin"): coins + = 10 get_mode("UI/CoinsCount").text = "x" + str(coins) But this would be cumbersome in games with dozens of coin types, or translating this code to things that cause damage. Is there a generic function that references the item touched, so, effectively: elif area_that_entered.is_in_group("variablecoin"): coins += coinvalue (defined on the *COIN*) get_mode("UI/CoinsCoint").text = "x" + str(coins) 1 0 Nov. 07, 2024
  • Using TextureRect instead of Sprite2DJohnyWuijtsNLWhen I tried doing it myself before following the lesson, I used a TextureRect instead of a Sprite2D node for the gem sprite next to the gem counter. I figured that would be the best option since it's a UI node. Does it matter which one I use? 1 0 Oct. 16, 2024
  • Why not use different events instead of different groups?acclaimed-guanacoWouldn't it be more elegant to use different (custom) events for gems and healing items? It seems to me that this would be far easier to manage, especially if the number of items gets high (avoiding a long if...elif chain is always a good idea in my experience) or the items become more complex. For example, if we add a composite item like a healing gem, we wouldn't have to worry about adjusting the if..elif chain and could just emit both events instead. 3 0 Oct. 15, 2024
  • maybe a typo in L6.P2 (in v0.8.1)CasimirMorelenergy is set up with `var_energy := 20`, which should infer an `int` if I understand correctly the `_on_area_entered` function seems to use a `float` to increase the value with `energy += 20.0` if left like this, the exercise pass with odd results: the energy increase then seems to get reinitialized 1 0 Oct. 03, 2024
  • Groups management has changed with Godot 4.3Seppo007Hi there, It seems that Godot 4.3 introduced the behaviour to differentiate between scene- and global-wide group definitions. The tutorial has to be adjusted in that way. [https://godotengine.github.io/godot-interactive-changelog/#4.3](https://godotengine.github.io/godot-interactive-changelog/#4.3) [https://github.com/godotengine/godot/pull/60965](https://github.com/godotengine/godot/pull/60965) I think for now it is safe to just use the scene-wide groups which should reflect the behaviour before Godot 4.3 1 0 Sep. 29, 2024
  • Collectibles touchingSpongebossI need a bit of an explanation on why something does what it does with collectibles. When i added the Gems to the project, i immediately thought "What if i place a Gem and a Helthpack adjacent?", because (at least for now) we never check if the Ship touched them or something else touched them. Before doing it, i expected to immediately bump up Ship's Health and GemCount by 1 stage when i press F6 to start the game. Instead, what happened, is partial of what i thought because yes the Gem and HealthPack disappeared immediately but the Ship's Health and GemCount still were at 0 (or basis). I imagine this is because the Gem and Healthpack somehow do not access the Ship's property, but i do not really get why... 3 0 Aug. 29, 2024
  • L6.P2 groups were already assigned?jumpy-goatOne of the objectives of this practice is to add the "coin" group and "energy" group to the Coin scene root and EnergyPack scene root, respectively. However, when I first opened the practice, the instances of those scenes under CoinsAndEnergyPacks already had groups added to them. I saw that if I skipped changing the root scenes I would still fail the practice and be forced to go in and make the change, but I'm curious if that's a limitation of how the practice objects need to be set up? Or is that an oversight? 1 0 Aug. 25, 2024
  • L6.GroupsBrain Siege GameworksI've tried to implement the conditions for checking the group the Area2Ds have however the conditions do not evaluate to true in spite of the group names being exactly the same as in the is_in_group() call. I've tried to print get_groups(and they seem to have the right group?) 3 0 Aug. 21, 2024
  • Is the func set_health and set_gem_count necessary ?CyberHi when I did the L6.P2 I noticed that we can directly adjust the value and text of coins and health in _on_area_entered function. Everything working just fine without the func set_health and set_gem_count. So is it necessary to write func set_health and set_gem_count ? 1 0 Aug. 18, 2024
  • About group Hazlarhello, I come back to the course about groups and I was wondering if instead of the ship identifying an object by its name in the group tab we could directly retrieve the Area2D character string renamed to gem or healpack? Finally the use of groups could be useful if for example we set up a batch of weapons (sprite2d) that we qualify in the group as "weapon" with a particularity common to all these weapons, like a wear time (x ammunition fired) and for the healing objects a random amount of healing depending on the size of the pack, in this sense we could name all the healing packs in the group as "heal" and add another group name behind indicating the size of the pack and use if .is_in_group("heal") and is.in_group("2") and multiply by 2 the healing value? Thanks 1 0 Jul. 12, 2024
  • L6.P2chunchunmaruSame problem as LP6.L1, even tho the code works correctly, the test fails saying that the groups are missing 1 0 May. 27, 2024
  • L6.P1chunchunmaruEverything works, I've even tried to cheat by using the already existing coin.tscn but the test doesn't see them in any way. Is that a problem if skip the test? 1 0 May. 27, 2024
  • Suggestion: Add warning for possible Addon breaksvilithosSeems I did everything right, but the GDQuest addon has some problems detecting if I am doing it right or wrong. My suggestion is to add a little disclaimer in the text that tells you something like: *"Hey, we got reports of the Addon malfunctioning here and there, please consider using the list in the tasks to check if you did it correctly. We're on it!"* This could in my opinion significantly increase the chance somebody isn't too discouraged to continue engaging in the course. 1 0 May. 26, 2024
  • I don't see my mistake BibizeI got this error "Invalid set index 'txt' (on base:'label') with value of type 'string'" ```gdscript func _on_area_entered(area_that_entered: Area2D) -> void: if area_that_entered.is_in_group("coin"): set_coins_group(coins + 1) elif area_that_entered.is_in_group("energy"): energy += 20.0 get_node("UI/EnergyBar").value = energy func set_coins_group(new_coins_count: int) -> void: coins = new_coins_count get_node("UI/CoinsCount").txt = "x" + str(coins) ``` i guess it's a typo or something, but I don't see it. 3 0 Apr. 30, 2024
  • L6.P2 UI doesn't update properly, but pass all testsbluepillThis is an odd one. I'm on MacOS 14.4.1 and Godot 4.2.2 stable. All the practices have worked fine so far. L6.P2 runs and gives me all the green tick marks but the UI doesn't update properly. I think it may be a Godot bug because the CoinsCount text looks like it is overwriting itself rather than replacing the text, so it's garbled. Also the EnergyBar looks like it is part way through drawing the increase in the value, so the first 10% is a solid colour and only the next 20% is partially coloured. I can't run the solutions project for some reason - I think it might be because there isn't a GDQuest Practices plugin in the project. 3 0 Apr. 30, 2024
  • L6.P2 | why can't I use "set_" to update coin and energy?andrea-putortiHey there, I wrote the code as I did previously in *ship.gd*: ```gdscript func set_energy(new_energy: int) -> void: energy = new_energy get_node("UI/EnergyBar").value = energy func set_coin_count(new_coins: int) -> void: coins = new_coins get_node("UI/CoinsCount").text = "x" + str(coins) func _on_area_entered(area_that_entered: Area2D) -> void: if area_that_entered.is_in_group("coin"): set_coin_count(new_coins + 1) elif area_that_entered.is_in_group("energy"): set_energy(new_energy + 20) ``` But I got those errors: > Identifier "new_coins" not declared in the current scope. > Identifier "new_energy" not declared in the current scope. What's the difference with this (which works)? ```gdscript func _on_area_entered(area_that_entered: Area2D) -> void: if area_that_entered.is_in_group("coin"): coins += 1 get_node("UI/CoinsCount").text = "x" + str(coins) elif area_that_entered.is_in_group("energy"): energy += 20 get_node("UI/EnergyBar").value = energy ``` During the course, this last code (*energy += 20*), which works in the practice, got changed into the first code that does not work in the practice. That's why I'm a bit confused. Does it have something to do with the *_ready* function or some backend code? Either way, I think this should be more clear when explained in course and practice (a warning that you should code it quite differently than earlier), otherwise the logic would suggest to practice as you did during the course right before. Another small problem is that I couldn't seem to find a way to see the UI in the dock and therefore I just had to guess it was "*CoinsCount*" when typing. Thanks! 6 0 Apr. 26, 2024
  • UI values are not updating with L6.P2leafI'm scratching my head on this one, I cannot seem to have the signals trigger the function at all, no UI value is updating and I've tried using `print()` to view in the output, nothing shows. Also, I've tried to link the entire script with a code block but it seems that if too much text is placed in it breaks the post field and I lose my post. I've tried posting the text and highliting it and converting it into a code block, but unforunately it loses all return/enter spaces and is a continuous line of code across the text field. So just going to post it raw.. I am receiving these warnings, but I've checked the functions, they seem to be right. Unless I'm missing something here? [Ignore]Line 45 (UNUSED_PARAMETER):The parameter "area_that_entered" is never used in the function "_on_area_entered()". If this is intended, prefix it with an underscore: "_area_that_entered". [Ignore]Line 48 (NARROWING_CONVERSION):Narrowing conversion (float is converted to int and loses precision). Here's the script extends Area2D signal target_reached var max_speed := 1200.0 var velocity := Vector2(0, 0) var steering_factor := 10.0 var target_position := Vector2(0, 0) var coins := 0 var energy := 20 func _ready() -> void: area_entered.connect(_on_area_entered) set_process(false) func set_target_position(new_target_position: Vector2) -> void: target_position = new_target_position set_process(true) func _process(delta: float) -> void: var desired_velocity := position.direction_to(target_position) * max_speed var steering := desired_velocity - velocity velocity += steering * steering_factor * delta position += velocity * delta if velocity.length() > 0.0: get_node("Sprite2D").rotation = velocity.angle() if position.distance_to(target_position) < 10.0: set_process(false) target_reached.emit() func set_energy(new_energy: int) -> void: energy = new_energy get_node("UI/EnergyBar").value = energy func set_coins(new_coin_count: int) -> void: coins = new_coin_count get_node("UI/CoinsCount").text = "x" + str(coins) func _on_area_entered(area_that_entered: Area2D) -> void: if is_in_group("energy"): energy += 20.0 get_node("UI/EnergyBar").value = energy elif is_in_group('coin'): coins += 1 get_node("UI/CoinsCount").text = coins 7 0 Apr. 24, 2024
  • Can't See GDQUEST tab for this workbookwell-lit-gazelleFor some reason the GDQUEST tab is not visible in this workbook so I am unable to do the practices. It worked for the workbook for the previous module but not this one. Has anyone else had this problem? 1 0 Apr. 20, 2024
  • L6.P1 Error: Invalid get index 'position' (on base: 'previously freed').gnomerunnerI had placed coin close to ship in practice test and I got error at line 30 in test.gd `Invalid get index 'position' (on base: 'previously freed')` I went over practice code and instructions couple of times but all looked good. I then moved coins to some other random places and error resolved. Failed: [https://i.imgur.com/FM6AvVw.png](https://i.imgur.com/FM6AvVw.png) Passed: [https://i.imgur.com/niwkLMD.png](https://i.imgur.com/niwkLMD.png) 3 0 Apr. 09, 2024
  • Think i broke the "Create Coin" Practice...ChunkyBitesI drag & drop the coin.gd script onto the coin node, but when i run the scene it keeps telling me the script is not attached. (It does say the coin is in the scene, and the coins do get collected and the ui updated.) I tried both instantiating the coin.tscn, and making a new coin with area2D + new script myself. So i think either i'm using the wrong script, or i've broken something on accident, lol. Clicking Reset or reloading the whole project it doesn't fix it either. Tbh i find the instructions on the practices pretty confusing (which scene and script do i put where? what is provided, what do i create from scratch?), and i'm not even a complete beginner. For people unfamiliar with Godot, this could use some more in depth pointers. 3 0 Apr. 04, 2024
  • Unable to complete L6.P1 on macOSThatEnbyKikiI'm using the 0.3.1 2d pack and Godot 4.2.0 on macOS 11.7.10. When attempting to run L6.P1, I get the following error: `Invalid get index 'list' (on base: 'null instance')` The stack frames show the errors are at lines 65 and 125 of "ui_test_panel.gd" 4 0 Apr. 03, 2024
  • How do I move nodes in the viewport?gorohaSection **"Add a gem count to the ship's UI"**, note **"How do I move nodes in the viewport?"**, it mentioned the 2nd option using **Select** tool, I think that the text is missing hold the **Alt** key (**Opt** key in MacOS) when click and drag the node. Please correct me if I'm wrong. Thank you. 2 0 Mar. 15, 2024
  • What is <Include file="ship_with_gems.gd" />?MuseDoesHi, I'm at the point in L6 which is called "Refactor the ship's script to handle both health packs and gems". Its asking me to write code I don't understand. I believe its displaying the wrong code actually. It starts off by telling us to write a new variable and gives the code: <Include file="ship_with_gems.gd" anchor="gem_count" /> It goes on to have us write more lines that are this: <Include file="ship_with_gems.gd" anchor="set_gem_count_definition" /> <Include file="ship_with_gems.gd" anchor="set_gem_count_value" /> <Include file="ship_with_gems.gd" anchor="set_gem_count_text" /> But it then explains that the last line as if the code should be something entirely else: In this line of code: 1. `get_node("UI/GemCount")` finds and returns a reference to the *GemCount* node. 2. `.text =` accesses the `text` property of the `Label` node and assigns it a new value. 3. `"x" + str(gem_count)` converts the `gem_count` variable to a `String` value. I've been following along with all of the lessons but this one has me completely lost. Am I seeing the right codes? 4 0 Mar. 13, 2024
  • L6.P2: Not updating after 1 coin pickupnear-octopusThe code I have written for this exercise is as follows: ```gdscript func _on_area_entered(area_that_entered: Area2D) -> void: if area_that_entered.is_in_group("coin"): coins += 1 get_node("UI/CoinsCount").text = "x" + str(coins) elif area_that_entered.is_in_group("energy"): energy += 20.0 get_node("UI/EnergyBar").value = energy ``` Running the tests results in the following: [https://i.imgur.com/LgLp9JS.png](https://i.imgur.com/LgLp9JS.png) All tests pass, however there are 3 coins in the main scene, not 1. Therefore, my coin counter should read as 3. I'm not sure what is causing this not to happen though? Interestingly all of the tests pass too, which is possibly an oversight of the exercise's test cases. 8 0 Mar. 09, 2024
  • L6.P1 'The coin scene has the provided script attached' (Not passing)AJ StudiosI get all the checkmarks green except for this one: *'The coin scene has the provided script attached'.* It says: The coin has the wrong script attached. I attached the 'coin.gd' script provided to the root node (Area2D) in the coin scene but is still giving me that error. Also, the ship is not adding the coins collected it shows x0 but the ghost ship is showing x4 What did I miss? By the way, I was able to pass L6.P2 without a problem, I'm just getting the aforementioned error from L6.P1 3 0 Mar. 06, 2024
  • Preference for scaling nodesBarabonesWhile making the gem item, I wanted to tweak the collision area. I went up and selected the scale mode tool, and while messing with that, noticed that the radius doesn't actually change at all. Would it actually make a difference if I resize items like collision nodes via radius or scale? 1 0 Mar. 06, 2024
  • L6.P1 Everything works but nothing is passingMartinBCoins are in the practice scene. coin.gd is attached Coin has a collision shape Sprite2D shape node is set as a child of the coin Area2D node Coin has the texture assigned. A moment ago all but the first thing passed but now none are passing. 3 0 Feb. 29, 2024
  • Inherited scenes and composition questionsiDieHello, I've been tinkering a bit with this lesson's code and tried the following: 1 Use inherited scenes to increase reuse: - I create an `item` scene which was basically the same as the `gem` and `health_pack` scenes, reusing the existing script `item.gd` - Exported 2 variables from `item.gd` : `health_boost` and `gem_count` - Added the logic to apply the effects on the ship from `item.gd` using the exported variables - Created an inherited scene `super_gem` which has a different sprite texture and specific `health_boost` and `gem_count` values 2 Use a common item scene to be reused with composition - In this case, I basically reused the `item` scene created in the first case but exported an additional variable `sprite_texture` - Then I create a new scene `super_health` with a `Node2D` as root, added a new instance of `item` as child with specific `sprite_texture`, `health_boost` and `gem_count` values In all cases, the behaviour is the same as the content of the lesson but it allows a bit more reuse. The first case is easy to implement and adjust but it uses inheritance (which is often considered as worse than composition) while the second uses composition only but seems more difficult to manage since you can (almost) only modify the exported values (in my case, I would need another exported value to adjust the radius of the collision circle for instance). My questions are: - What do you think of those approaches (pros and cons): creation of different scenes and only reuse the script vs inherited scene vs composition with an item scene? - Do you see other/better patterns ? Thanks in advance for the insights! 2 0 Feb. 26, 2024
  • Putting healing & gem count logic in Child Node of PickupMarcJI'm experimenting a bit with the code and I'd like to try putting the healing and gem logic inside a child node of the item pickup scenes instead of the ship.gd script. So for example in the health_pack I would add a child node HealingEffect with a function apply_effect(effect_target: Ship) that would increase the ship health and the gem would have a child node GemIncrementEffect with the same function that increased the ship's gem count and the Item.gd script's on_area_entered function would call the respective child nodes apply_effect function. The questions I have are : 1. Is there a way to cast the parameter area_that_entered from Area2D to Ship so that I can call the Ship's setter functions? 2. Is there a way for the Item nodes to detect an itemEffect child node and access it without requiring it to have a specific name? I know this isn't material that's been covered yet so if it's too much to answer here or a future module will cover it anyways I'd just like to know if it's a reasonable approach or if there's a reason it wouldn't be a good idea in gdscript. Thanks 2 0 Feb. 21, 2024
  • L6.P2RudiI can't seem to get that test to pass. I can see the ship and a shadow, not sure which is which. Both are collecting the coins and the UI is updating. But it doesn't pass. 8 0 Feb. 21, 2024
Site is in BETA!found a bug?