Help with Spell casting

Hello! I am making a small little project that involves magic and spell casting, and im unsure where to start. Im trying to have chat spells where if you say a spell and click you can cast the spell (like in Harry Potter games)

The main questions i have is that how will i make spells not case sensitive? I know there are specific functions in the string library but i am unsure of which ones to use.

I also dont really know how i’d identify if whatever the player chats is a spell or not. I was thinking i could loop through a table of spell names and do something like

if msg == spellName then

I am unsure if this is practical or not. Help and advice on where to start would greatly be appreciated. Thank you for your time

1 Like
local spells = {
     ["Freeze"] = function(Args)
     end,
     ["Fire"] = function(Args)
     end
}

You could store them in a dictionary like this, and then check if they said one of the words, and if they did - call its value - the function.

1 Like

How exactly would i call the value? Ive never used dictionaries like this before :sweat_smile:

Example:

spells.Freeze(Args)
1 Like

Oh another question! how do i check if they say one of the words? My first thought is

if msg == spells[Freeze] then

but this might be tedious to write for every spell. Are there any other ways to check?

Just loop through the spells dictionary and if the check them all at once.

For spellname, v in pairs (spells) do
    if msg ==spellname then
        spells[spellname](args)
    end
end
1 Like