Setting active class from an array.

Hello friends,

I have a spellbook component to which spells are added when the player discovers them.
I’m struggling to work a function to go through the spellbook and just cycle through all of the spells setting each one - after a key press to the active spell.

i;e Spellbook contains two spells. Frostbolt and fireball. You currently have frostbolt active but want to change to fireball, press a button and this happens, press it again and it goes back to the frostbolt or keeps going through if you have more spells but eventually returns to the first - I guess index.
Similar to how you would change your spells in Dark Souls - by pressing UP on D-pad.

I understand I’ll want to loop through this array but I’m not sure which kind of loops and how to break it for each key press.

Thanks in advance.

Try this:


Just ensure there is at least 1 spell before you use it, ofc.

2 Likes

Hail Everynone,

That works. I will expand further for my system.

Thanks friend.

2 Likes