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.

  • 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. 1 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 ``` 6 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? 1 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. 1 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. 1 0 Dec. 02, 2024
Site is in BETA!found a bug?