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.
add effect syntax update for godot 4stupid-grouseI *think* this is the right code? it gets the nodePath from the text string
```gdscript
# Adds a new instance of a status effect as a child, ensuring the effects don't stack past# `MAX_STACKS`.
func add(effect: StatusEffect) -> void:
# If we already have active effects, we may have to replace one.
# If it can stack, we replace the one with the smallest time left.
if effect.can_stack():
if _has_maximum_stacks_of(effect.id):
_remove_effect_expiring_the_soonest(effect.id)
# If it's a unique effect like slow or haste, we replace it.
elif has_node(NodePath(effect.name)):
# We call `StatusEffect.expire()` to let the effect properly clean up itself.
get_node(NodePath(effect.name)).expire()
# The status effects are node so all we need to do is add it as a child of the container.
add_child(effect)
```11May. 04, 2024
godot inherited scenesmejozzzi'm using godot 4.2 if we using inherited scenes we dont need to instantiate the container effect class right? 10May. 21, 2024
Struggling to make this work in Godot 4stupid-grouseUnderstand this is a godot 3 course so no worries if you cant help but im getting a bug on godot 4. i have the following code:
```gdscript
const StatusEffects := { "haste" : "StatusEffectHaste", "slow" : "StatusEffectSlow", "bug" : "StatusEffectBug"}# The class only exposes a function that creates and returns a new status effect based on the data# we provide.static func create_status_effect(target, data): # We can use the function to run through some `assert()` or return early if the input parameters # are incorrect. if not data: return null # You can store a reference to a class in a variable! var effect_class = StatusEffects[data.effect] var effect: StatusEffect = effect_class.new(target, data) return effect
```
and get this error Invalid call. Nonexistent function 'new' in base 'String'. and can't figure out show to create the new class. Any help would be super appreciated.20May. 05, 2024
const dictionary godot 4stupid-grousethis is the dictionary syntax for godot 4
```gdscript
const StatusEffects := {
"haste" : "StatusEffectHaste",
"slow" : "StatusEffectSlow",
"bug" : "StatusEffectBug"}
```10May. 04, 2024
Please clarify adding StatusEffectContainer to player + enemy instead of Battler.tscnopyateHere's my transcript from Discord:
hey folks, quick question about <https://gdquest.mavenseed.com/lessons/applying-status-effects>
In Battler.gd the `_status_effect_container` is null when the time_scale is set
_\[_22:32_\]_
I checked the spelling, and even let code-complete find the correct node here: `onready var _status_effect_container: StatusEffectContainer = $StatusEffectContainer`
_\[_22:32_\]_
I added a `_ready()` in the StatusEffectContainer script, with a print, but it doesn't seem to be called
_\[_22:33_\]_
I tried restarting Godot too
_\[_22:37_\]_
hmm, ok - my Battler "implementation" doesn't seem to have properly inherited from Battler.tscn, so it's missing the new StatusEffectContainer node

## opyate _—_ Today at 22:50
Fixed now. I'll dig through the previous chapters to see if there was something unclear about "new inherited scene" when creating characters

## opyate _—_ Today at 22:58
found it: <https://gdquest.mavenseed.com/lessons/designing-base-animations>
section: Creating derived battler scenes
> You could use the scene inheritance feature in Godot. I recommend to avoid it...
>
> <snip>
>
> That’s why, instead, I recommend creating new scenes, which is what we’ll do here.
_\[_22:58_\]_
so, the subsequent addition of StatusEffectContainer to Battler.tscn wasn't propagated to the player + enemy, because those were new and not inherited
_\[_22:59_\]_
What is a good solution here? Just create the StatusEffectContainer on both player + enemy? (perhaps the tut should reflect this)10Apr. 14, 2021
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.