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.

  • no sound is played when I collect my itemsPixAngelAll is in the title. I still have the same code as you : ```gdscript func set_item(value : Item): item = value if sprite_2d != null and item != null: sprite_2d.texture = item.texture if audio_stream_player_2d != null: audio_stream_player_2d.stream = item.so ``` I added in my func _ready connection : ```gdscript body_entered.connect(func(body : Node) -> void: if body is Player: item.use(body) audio_stream_player_2d.play() queue_free() ) ``` Did i miss something? 8 0 Jan. 16, 2025
  • How can I make the sprite change in the editor?DMKAs in your questions and troubleshooting, even if you change the texture property of the healing item, it will not be changed in the editor. But creating a setter function in the HealingItem script is impossible, so how should I go about doing this? 1 0 Jan. 15, 2025
  • Found a typoDMK> For a single kind of item, for example, if you exclusively make healing items in your game, **exploring** properties like which image... exploring -> exporting Also, a space is missing in: > Notice how the `use()` function is [empty]() in the base `Item` resource. This is because the base item resource only defines a generic **[type](https://school.gdquest.com/glossary/type)and.....** 1 0 Jan. 15, 2025
  • Challenge idea: consume health items only when they actually heal the playerHardRockWith a minor modification to the `use()` function (there are probably other ways as well) this is an easy change to make and adds a bit of extra quality of life for the player, since they won't have to avoid healing items when they are at max HP. 1 0 Jan. 05, 2025
  • Crash due to animationram876Hello! I've encountered an error that I don't understand. I added an idle animation for the pickup sprite. If you add pickup to the level, then everything works fine. But after restarting, the editor crashes if you switch to this scene. I realized that the problem with enabling animation was only after much trial and error. When running from the command line, it outputs the following information: ```gdscript CrashHandlerException: Program crashed with signal 11 Engine version: Godot Engine v4.3.stable.official (77dcf97d82cbfe4e4615475fa52ca03da645dbd8) Dumping the backtrace. Please include this when reporting the bug to the project developer. [1] error(-1): no debug info in PE/COFF executable [2] error(-1): no debug info in PE/COFF executable [3] error(-1): no debug info in PE/COFF executable [4] error(-1): no debug info in PE/COFF executable [5] error(-1): no debug info in PE/COFF executable [6] error(-1): no debug info in PE/COFF executable [7] error(-1): no debug info in PE/COFF executable [8] error(-1): no debug info in PE/COFF executable [9] error(-1): no debug info in PE/COFF executable [10] error(-1): no debug info in PE/COFF executable [11] error(-1): no debug info in PE/COFF executable [12] error(-1): no debug info in PE/COFF executable [13] error(-1): no debug info in PE/COFF executable [14] error(-1): no debug info in PE/COFF executable [15] error(-1): no debug info in PE/COFF executable [16] error(-1): no debug info in PE/COFF executable [17] error(-1): no debug info in PE/COFF executable [18] error(-1): no debug info in PE/COFF executable [19] error(-1): no debug info in PE/COFF executable -- END OF BACKTRACE -- ``` And sometimes, after several restarts, the scene starts, but the idle animation does not start, and the following message is constantly printed on the command line: ```gdscript ERROR: Condition "!has_animation(p_name)" is true. at: make_animation_instance (scene/animation/animation_mixer.cpp:1909) ``` My pickup script is almost identical to yours. 4 0 Dec. 31, 2024
  • Bullet Boosterram876Hello! I couldn't figure out how to make a booster that increases the damage for bullets. Bullets are created dynamically on the stage and I do not know how to write the use() function in this case. I tried writing `var bullet :=player.get_node("WeaponPivot/WeaponAnchor/Weapon")` in the booster. And storing the bullet in a variable in weapon. But I couldn't get this variable in the booster. What should I do in these situations? 5 0 Dec. 30, 2024
  • Something odd about the example provided in the lessonCptnNuggetsHi there, a question related to your example about the use of ressources. You propose this code : ```gdscript class_name Pickup extends Area2D @export var item: SpeedItem = null ``` But that means constraining the item variable to the SpeedItem class. Doesn't that goes against the design pattern you propose ? Shouldn't it be this instead : ```gdscript class_name Pickup extends Area2D @export var item: Ressource = null ``` I'm curious if I misunderstood something or if it's just a typo ? Furthermore, to enhance readability (for me, not saying it's better ^^ just the way my mind works), would the following be possible ? Create a class "Item extends Ressource" which would implement properties and functions shared between all items (ie, in your example, use() and display_image) with properties set to null and functions to "pass". Then, for each item type, the class would extend the "Item" class instead of the general "Ressource" one, and overload the functions as needed ? Would this be a valid approach ? Would there be drawbacks ? The 2 adantages I see are that this Item class would inform on necessary functions/properties when creating a new Item further down the line, plus the Pickup class would then be more readable like this : ```gdscript class_name Pickup extends Area2D @export var item: Item = null ``` 4 0 Dec. 20, 2024
  • Did you used the set_deferred() in pickup script, because the monitoring property is related to physics/collision?◆ LPI was confused because we didn't use anything in the _physics_process() here. But it did helped in stopping the player character from unintentional healing because it could keep entering the pickup's area while the pickup audio is playing. 4 0 Dec. 18, 2024
  • Update texture in editor via @toolKetan```gdscript @tool extends Area2D class_name Pickup @export var item: Item = null: set = set_item @onready var sprite_2d: Sprite2D = $Sprite2D @onready var audio_stream_player: AudioStreamPlayer = $AudioStreamPlayer ``` ```gdscript func _ready() -> void: set_item(item) body_entered.connect(func(body: Node2D) -> void: if body is Player: set_deferred("monitoring", false) item.use(body) queue_free()) func set_item(value: Item) -> void: item = value if sprite_2d != null: sprite_2d.texture = item.texture if audio_stream_player != null: audio_stream_player.stream = item.pickup_sound ``` 9 0 Dec. 17, 2024
  • @onready variables being nullnasty-beeSomething strange just happened to me. Although my scene, script and resources were setup correctly (I double checked and even compared to the solution), Godot gave me an error ("invalid access to property or key 'texture' on a base object of type 'Nil'). I know this means that the @onready variable wasn't referring properly to the sprite, but I could not figure out what the issue was. I ended up restarting the engine, and somehow the issue just fixed itself! The script that was giving me an error before the restart was now working perfectly, without changing anything. This brings me to ask a few questions: 1) I noticed that in your script, you check if the variables are null in the ready function. At first I didn't understand why you would do this since the ready function is supposed to run only when all the children are ready. Is the line added to prevent errors like the one I had or is there another reason? ```gdscript if _sprite_2d != null: _sprite_2d.texture = item.texture if _audio_stream_player != null: _audio_stream_player.stream = item.sound_on_pickup ``` 2) It's not the first time restarting the engine has solved an issue for me. It seems I'm not the only one, as I've seen plenty of people on Reddit suggesting restarting as a solution to encountering a strange bug. This honestly scares me a little. Are my players also going to experience similar issues and need to restart the game, or are these bugs only present while I'm developing the game and playtesting? 2 0 Dec. 15, 2024
  • Using @tool to update the spritePaulI fancied having a go with using `@tool` to get the sprite to update in the editor. I couldn't really remember how this went, and with a bit of looking I determined you have to use a setter function to force the update in the editor. But I was really struggling with the syntax or how to go about actually doing it. I'm thinking you'd need the setter function on the `item` resource (since this is what we are setting the new properties in). Something like: ```gdscript @export var item: Item = null : set = set_item_properties ``` However `item` has a number of properties (`healing_amount`, `item_visual`, `item_sound` in my case as it's the healing item). I couldn't work out how I write a setter function that can take multiple properties, so far I think we've only handled setters on say an `int`, where you know what will be expected. I tried a few things which all just resulted in errors. 9 0 Dec. 14, 2024
  • health bar doesn't update immense-swallowHi, I followed the code, but I'm unsure why my health bar only updates when attacked by the mob but not when picking up items.I feel confused about the Setter function. Could you explain this part in more detail? And is it possible to reduce the time gap between the player's death and reloading the game?Thank you. 2 0 Dec. 10, 2024
  • How to make it so the Healing Pickup resource has pre-defined texture.DargorWith this format, you can set the texture for the Sprite node in the inspector. But how do I make it so that the Healing Pickup always uses the same texture, so that I don't have to choose the texture every time I assign it to the Pickup scene? I tried assigning the texture to a variable inside the Health Pickup script (var image = preload("texture location") and then assigning it to the texture var in the ready function (texture = image) so that the set_item function in the Pickup scene assigns the image, but it doesn't work. 4 0 Dec. 02, 2024
Site is in BETA!found a bug?