View Full Version : function calling error
please can any one help me to find the reason of the error in my function calling example which i did?
this function calling example hase been attached..
please i want quikly respond..
thanks ..
Desrat
04-22-2007, 03:58 AM
remove the "local" from your global function and it works... so use
01 -- A function that accepts one value and returns one value
02 function mntestfunction(testvalue)
03 -- Put function script here
04 mnvalue = testvalue; -- Access testvalue
05 -- if statment test
06 if (mnvalue==1) then
07 -- Do something here
08 result_value= "OK";
09 elseif (mnvalue==2) then
10 -- Do something else here
11 result_value= "Very Good";
12 elseif (mnvalue~=1 or mnvalue~=2 ) then
13 -- Do something else here
14 result_value= "Not Good";
15 end -- end if statment
16 ---------
17 return result_value; -- Return result_value
18 end
19
output enhanced with AMS Code Pretty (http://www.indigorose.com/forums/showthread.php?t=19409)
instead of
01 -- A function that accepts one value and returns one value
02 function mntestfunction(testvalue)
03 -- Put function script here
04 local mnvalue = testvalue; -- Access testvalue
05 -- if statment test
06 if (mnvalue==1) then
07 -- Do something here
08 local result_value= "OK";
09 elseif (mnvalue==2) then
10 -- Do something else here
11 local result_value= "Very Good";
12 elseif (mnvalue~=1 or mnvalue~=2 ) then
13 -- Do something else here
14 local result_value= "Not Good";
15 en d-- end if statment
16 ---------
17 return result_value; -- Return result_value
18 end
19
output enhanced with AMS Code Pretty (http://www.indigorose.com/forums/showthread.php?t=19409)
Jonas DK
04-22-2007, 04:09 AM
You could also do this:
-- A function that accepts one value and returns one value
function mntestfunction(testvalue)
-- Put function script here
local mnvalue = testvalue; -- Access testvalue
-- if statment test
if mnvalue==1 then
-- Do something here
result_value="OK";
elseif mnvalue==2 then
-- Do something else here
result_value="Very Good";
elseif mnvalue ~= 1 or 2 then
-- Do something else here
result_value="Not Good";
end-- end if statment
---------
return result_value; -- Return result_value
end
The difference is I removed the () around the declaration of variables like
(mnvalue = 1) becomes mnvalue = 1
you dont need the () also the mnvalue ~= 1 or 2. you can easaly compare the same variable to more then one value, you dont need to test the variable twice.
Thise are just design notes, they have no effect on the executet script but as saied above all you have to do is remove the local from the variable name.
cheers,
Jonas
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.