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 ..
Professional Software Development Tools
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 ..
remove the "local" from your global function and it works... so use
Code: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
instead of
output enhanced with AMS Code PrettyCode: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
You could also do this:
The difference is I removed the () around the declaration of variables likeCode:-- 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
(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