I have seen an example of how this is supposed to work (i think), but I seem to be doing something wrong.
the goal is have a trigger that decreases the number of spells memorized as i cast them.
This is what I have so far:
<triggers>
<trigger
enabled="y"
expand_variables="y"
group="spellcounter"
match="^You utter the words\, \'([a-zA-Z ]+)\'$"
regexp="y"
send_to="12"
sequence="100"
>
<send>
spell_cast = "%1"
memc = 0;
memt [spell_cast] = memt [spell_cast] or {}
mt = { __index =
function (tbl, key)
tbl [key] = {} -- add sub table
return tbl [key] -- return as missing value
end }
setmetatable (memt, mt)
memt [spell_cast].mem = memt [spell_cast].mem - 1
memc = memt [spell_cast].mem
Note (" *** ".. memc .." of " .. spell_cast .." left ***")
end</send>
</trigger>
</triggers>
Everything works as long as the spell is in the table. If the spell is not then I get a Nil error. The memt table is already set and populated through another trigger based on information from the mud; however, sometimes a character is able to cast a spell even if it is not memorized.
I tried to use a metatable as shown in another thread, but I do not seem to have it working right because I still get the error.
the goal is have a trigger that decreases the number of spells memorized as i cast them.
This is what I have so far:
<triggers>
<trigger
enabled="y"
expand_variables="y"
group="spellcounter"
match="^You utter the words\, \'([a-zA-Z ]+)\'$"
regexp="y"
send_to="12"
sequence="100"
>
<send>
spell_cast = "%1"
memc = 0;
memt [spell_cast] = memt [spell_cast] or {}
mt = { __index =
function (tbl, key)
tbl [key] = {} -- add sub table
return tbl [key] -- return as missing value
end }
setmetatable (memt, mt)
memt [spell_cast].mem = memt [spell_cast].mem - 1
memc = memt [spell_cast].mem
Note (" *** ".. memc .." of " .. spell_cast .." left ***")
end</send>
</trigger>
</triggers>
Everything works as long as the spell is in the table. If the spell is not then I get a Nil error. The memt table is already set and populated through another trigger based on information from the mud; however, sometimes a character is able to cast a spell even if it is not memorized.
I tried to use a metatable as shown in another thread, but I do not seem to have it working right because I still get the error.