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.

  • Question on resources and inheritanceilliterate-spiderI personally like resources. Not only is it very fun for me but I get the idea alot better. Honestly i still dont know how to use the script after overriding it. Anyways my question is if I master resources very well would I still need to use inheritance? Even if inheritance is better for simple games with not alot of levels or items/weapons. Thanks in advance! 2 0 Apr. 24, 2025
  • Stuck lolilliterate-spiderHi I am taking my time on this one and thinking really hard. Trying to implement the array of weapon scenes and switching them from the weapon node on the player. What I used and what i got so far. ```gdscript var weapons : Array[PackedScene]= [preload("res://weapons/charged_ice.tscn"), preload("res://weapons/continuous_fire.tscn"), preload("res://weapons/shotgun.tscn")] func _physics_process(delta: float) -> void: .... if Input.is_action_just_pressed("gun_1"): weapon.queue_free() var continue_fire = weapons[0].instantiate() weapon_anchor.add_child(continue_fire) elif Input.is_action_just_pressed("gun_2"): weapon.queue_free() var shotgun = weapons[1].instantiate() weapon_anchor.add_child(shotgun) ``` 1. So gun_1 works fine no problem if I switch from gun_1 to gun_2 then I get cannot call method 'queue_free' on a previously freed instance. im guessing you cannot queue free back to back then. 2. Also if I used gun_2 from the start it switches fine but it wont shoot. I used your firespray script just to see if my gun_2 would work it didnt Can I get hint or a direction on where to look? Thanks guys =D 4 0 Apr. 22, 2025
  • Weapon Swap Trouble (and resolution?)chubby-frogI have been stuck on trying to resolve this for the past couple days on my own, but I keep hitting a dead end because I don't think I understand what is happening behind the scenes. 1. I created the autofire weapon from this lesson extending the Weapon class 2. I created in the Player script an array of the two weapons (regular and autofire), a weapon toggle Input, and a function to add and remove the weapons in the order of the array to cycle through them (swapping weapons scenes instead of just only scripts) **The problem**: I get the following errors when I try to run the LEVEL scene and click the shoot button, (the bullets are currently coded from the previous lessons to instantiate to the "current scene". This error does not occur when running the PLAYER Scene for some reason, so I assumed the code logic of the weapon switch was working properly. -E 0:00:00:940 weapon.gd:17 @ shoot_bullet(): Failed to instantiate scene state of "", node count is 0. Make sure the PackedScene resource is valid. -E 0:00:00:940 weapon.gd:18 @ shoot_bullet(): Parameter "p_child" is null. I noticed that the moment I started instantiating the weapons from the Player script, there were issues with instantiating the bullets to the current scene *when the current scene is the Level*. I even tested starting the player without any weapons, and only instantiating the regular weapon on the ready function of the Player script while running the LEVEL scene--same error. The one thing that worked for me is putting all of the scenes and scripts in the same folder, in which moving the level scene ***to*** ***the player folder*** actually allowed the scene to run properly. I had remembered from the Lesson 5:7 there was the warning to make sure: **The code assumes that the `gem.tscn` file is in the same folder as the script. If you get an error, make sure the `gem.tscn` file is in the same folder as the `random_item_placer.gd` script.** To my understanding, the preloaded scene needed to be in the same folder as the script that it was being instantiated from. But in this case, the WEAPON script is instantiating the bullets and adding as children to the LEVEL scene -----So my final question is, does the ***destination*** scene (node that will have the instantiated scene as a child) have to be in the same folder as the script that is instantiating the scene and scene being instantiated: 1. bullet scene being instantiated in weapon script, added as child of LEVEL (current scene) 2. Weapon Scene being the script where instantiation is coded and home of the preloaded bullet scene reference 3. Player script being where weapons are preloaded and instantiated from, to the anchor as the parent (this caused the error in the first place) Right now I have all the scenes and scripts involved in the weapon switch in the same folder, which is working, but not sure what is absolutely required? If the file location actually has a major affect on this, I am starting to think that it might be smarter to organize by file type than by game systems--or if even that method of organizing would have its limitations for something like this? 2 0 Apr. 06, 2025
  • My solution to Ice charge weaponsSootyHere is my solution to the challenge. After checking the solution, I didn't like how if you had a time of 3 and a damage of 2 , the result would be 8. So I modified it. It seems to work watching the numbers being output in the console ```gdscript extends Weapon var current_charge : float = 0.0 var charge_value : float = 1.0 var max_charge : float = 3.0 var charge_damage : float = 2.0 @onready var gpu_particles_2d: GPUParticles2D = %GPUParticles2D func _physics_process(delta: float) -> void: if Input.is_action_pressed("action_shoot"): gpu_particles_2d.emitting = true if current_charge < max_charge: current_charge += clampf(charge_value,0.0,max_charge) * delta print(current_charge) if Input.is_action_just_released("action_shoot"): gpu_particles_2d.emitting = false _shoot() current_charge = 0 func _spawn_bullet ()-> void: var _new_bullet : Node = bullet_scene.instantiate() get_tree().current_scene.add_child(_new_bullet) if current_charge < 1.0: current_charge = 1.0 _new_bullet.damage = floor(charge_damage * current_charge) print(_new_bullet.damage) _new_bullet.global_position = global_position _new_bullet.global_rotation += global_rotation _new_bullet.max_range = max_range _new_bullet.speed = speed _new_bullet.scale = Vector2.ONE * current_charge _new_bullet.rotation += randf_range(-random_angle/2.0, random_angle/2.0) ``` 3 0 Mar. 23, 2025
  • Issue with second weaponkazaHi! I'm getting little confused on creating a second weapon. Here is the thing: - I've created the second scene, a copy of weapon scene and I keep the main node (Node2D) with two sprites (of hands), I put a Timer, but I attached a new script on the root node that extends of Weapon and inside it i've coded only the _*physics*_proccess. What happens is that regardless i don't instantiate the second weapon, same way the engine is calling _*physics*_process of the secondary weapon. I'm doing something wrong? What i miss? Tks in advance. 8 0 Feb. 23, 2025
  • Why divide the max_spread_angle by 2?silent-meerkatwhy did you do randf_range(-max_spread_angle / 2.0, max_spread_angle / 2.0) instead of setting the max_spread_angle to PI/6 ? 1 0 Feb. 17, 2025
  • What is a good way of creating ice bulletsperiodic-spoonbillPersonally I created a new node with the same system as the 'normal' bullets (but with different sprites and sounds) and then I attached the same script as the 'normal' bullets to it. It seems a bit makeshift, so not sure if that's a good way to do it or if I should have just made bullet more generalised. 3 0 Feb. 06, 2025
  • How do I use the created scripts?ram876Hello! I have a problem understanding the assignment. In the challenges, you prompt to create a script and write the logic of a new weapon there. I have 2 questions. 1) If I'm only writing a script with new logic, how do I use it when shooting? In this case, do I need to create an exported variable for the weapon, first removing it from the player's scene, and then, when selecting pickups, load this script using load/preload? 2) Judging by your examples of solving challenges, you have created not only a script, but a whole scene with your script. Did you mean that in the challenges? 6 0 Jan. 06, 2025
  • Accessing nodes elsewherePaulI decided to spice up the automatic shooting weapon by making it fire really fast but have a heat build-up mechanic. I got this to work but I think I've either forgotten an important lesson or I've not fully understood accessing/getting references to nodes elsewhere in the scene tree. Here's a short demo of what I mean: [https://youtu.be/Tc7qLQdVm4g?si=plzQ8L76fkHdBHau](https://youtu.be/Tc7qLQdVm4g?si=plzQ8L76fkHdBHau) So, it works. I want the 'heat' `ProgressBar` node part of the Player, alongside the health bar in my node structure, but I want to handle the overheating mechanics in the weapon with the rest of the weapon code, nested deeper down in the Player scene. I was struggling to work out the best way to do this - it seems like a simple thing but for some reason I'm puzzled by it. I got it to work using: ```gdscript @onready var heat_bar: ProgressBar = get_node("../../../HeatBar") ``` to get a reference to the heat bar from the weapon (up several levels, then across). Would this be the best way to achieve this? By using a relative path rather than absolute, it certainly seems less prone to breaking later on, but I'm still not sure if this would be the recommended method. 2 0 Dec. 31, 2024
  • An error in the bullet spread scriptKetanI noticed that in the "shotgun" version of the weapon wasn't playing any sound when shooting and I did some research, apparently the `shoot_audio` var was always null Turns out you can't access export variables from an extended scene, I tried to load it at runtime but Godot at the moment doesn't support loading .wav files at runtime The only solution I found was to add a new @onready var in the shotgun weapon scene with a new AudioStreamPlayer node, I'm curious if the there're any other ways I could solve this? 2 0 Dec. 24, 2024
  • Charging Ice ParticlesMarcJI've added the charging particles for the ice fist but when I looked at your version of the code I see you used an AnimationPlayer to start the particles. I assumed that you used it to intensify the particles as you charge but when I tried it I found that the particles restarted if you changed any of the values and from a bit of reading it seems that's the expected behavior. So I'm just curious to know what you are doing with the AnimationPlayer? 6 0 Dec. 22, 2024
Site is in BETA!found a bug?