I started recently in game programming in general and im doing a top down vamp survivors style game.
The problem I have is that I dont understand how to acess my spells functions from my spell manager. I´ve tried doing an spell manager that appends the active spells to an array called active_spells and calls the cast() function in a for loop for every spell in active_spells.
My spell manager is a child Node of my player Node, and the ability im trying to append is an area2D which has an script with all the logic and its cast() function.
What isn’t working? Could you post an error message, what you expect to happen, and what really happens? Pasting your script or parts of it may be necessary
Truth be told, you need to design a spell system and think about who and what can be accessed. A Spell Manager should have access to all spells and also the position of the player and the position of the mouse cursor.
If you want the Spell Manager as a child of the player, then you would need the Spell Manager to have access to all spells. I would maybe consider creating an autoload called SpellCollection with a method called SpellCollection.get_spell_by_id(int) -> Spell
and the returned spell is then processed by the Spell Manager.
The title of the topic says you can’t make the spell manager work, which implies you are already using a self-crafted spell system but encountered a problem. From your description, I don’t see any real errors.
Where did you declare the spell functions?
Why can’t your spell manager access them?
Right now I assume that:
You have a base class called Spell
The base class has an area2D child and a cast() method.
All spells that exist inherit from the base class Spell and override area2d and the cast() method.
After you added all spells to your spell manager as children, you can then loop through all spells and then trigger their individual cast() methods and then remove the spell children from the spell manager
I managed to make my spell manager acess the spell, but I think it is not the right approach because the actual spell texture is instantiated in the game on loading, as I added the spell scene as a child of the spellSlot after trying of loading it in other ways. Im now thinking if I could make a global script with the scenes of all the spells, and load them with the spell manager acessing the global.spellCollection. Could that work? Thank you for replying
Theoretically it should work but to be honest, I would like to have every spell handle themselves.
If the spell has been added to the spellSlot, then the spellManager can activate them.
Each Spell has their own physics process that handles their own execution and cooldown.
I believe the SpellManager should only be responsible for accessing all spells, populating spell slots and upgrading the spells.