When writing a function its important to understand how
parameters work. A parameter is a place holder telling you the programmer what type of information should be to passed to it.
As an example let's create a function called Shapes and add to it over time to understand how a function works.
Now that we have the basics of the function defined lets create a few
parameters for it. In this example we'll use the parameters
round &
square.
Lua:
function Shapes(round, square)
end
If we think beyond the scope of programming logic just for this example we can get a better idea of what is going on here. So lets do that now and think in general terms rather than logical. When we pass information to a function its called an
argument, this argument must fit a function's parameter in the order that the parameters are defined.
So if we
call or invoke the Shape's function we would need to pass it 2 arguments, so lets do that now lets pass the argument's ball & box.
Normally a ball is round and a box is square, if we were to set the argument list as box, ball we will end up with an unwarranted outcome.
So to look at your 1st issue you have
Lua:
function test3(creature,variant)
testa:execute(creature, variant)
end
function onCastSpell(creature, variant)
addEvent(test1, 10, creature:getId())
addEvent(test2, 5000, creature:getId())
addEvent(test3, 2000)
In the code above you have 3 addEvent's calling 3 different functions labeled test1, test2, test3 at different intervals. AddEvent's parameters are defined as this
Lua:
addEvent(function name, time or interval, parameter list)
In the 1st 2 addEvent call's you are sending the creature id to test1 & test2 however in test3 you aren't sending any information and according to the definition of test3 the function requires an argument of creature & variant . testa I won't even comment on since I don't know what the whole script looks like.
In your 2nd example
Lua:
function test3(variant)
local creature = Creature(cid)
testo:execute(creature, variant)
end
function onCastSpell(creature, variant)
addEvent(test3, 2000,variant)
There is just 1 addEvent and it is calling test3 at a time or interval of 2 seconds while you are passing variant to test3, test3 is calling Creature and asking for the cid which is not defined or has not been defined.
So let's clean your code example's up and assuming that testa is a combat object we will include that in the new version of the script.
Lua:
-- test3 2 parameter's require a creature id (cid) and a variant (var)
function test3(cid, var)
local creature = Creature(cid)
-- check if creature has been created
if creature then
-- if it has execute (assuming testa is a combat object)
testa:execute(creature, var)
end
end
function onCastSpell(creature, variant)
-- invoke or call addEvent passing it test3 (function name), have it execute in 2 seconds (2000),
-- and pass test3 the arguments creature:getId() & variant
addEvent(test3, 2000, creature:getId(), variant)
return true
end