View Single Post
  #6  
Unread 06-10-2012, 11:27 AM
Kunter Kunter is offline
The Undefeated
Interface Author - Click to view interfaces
 
Join Date: Jun 2012
Posts: 7
Quote:
Originally Posted by Garan
In addition to what the authors above noted, you have a number of problems in the Disease function. First, you are using the same name for a function and a variable within that function (I suspect you have a VB background and are trying to assign the return value). Unfortunately in Lua what will happen with your code is the first time the function gets called, it gets reassigned to a numeric value and will become invalid as a function the next time you try to call it.

Consider the code:
Code:
import "Turbine"
function Disease()
        Disease = 0.5
end
Turbine.Shell.WriteLine("Type before call:"..type(Disease));
local tmpVal=Disease();
Turbine.Shell.WriteLine("tmpVal:"..tostring(tmpVal));
Turbine.Shell.WriteLine("Type after call:"..type(Disease));
The above code demonstrates the two problems with your function, first the output:
Code:
Type before call:function
tmpVal:nil
Type after call:number
shows that "Disease" is indeed changed from a function to a number after it is called. Second, the value returned by Disease() is "nil". This is because you must explicitly use the "return" statement to return a value.

The below code demonstrates using a local value for the return value, initializing it to the default and explicitly returning it. Note that you should always create variables with the narrowest possible scope, so the return value is scoped as local to the function to avoid conflict with any other variable with the same name.
Code:
-- assumes that "EffectList" is properly assigned an instance of an EffectList and that "charge" is properly defined
function Disease()
    local retVal=0;
    if (EffectList:Contains(charge)) then -- This is line 30
        retVal = 0.5;
    end
    return retVal;
end
Ok, I get the return thing, but how to define "charge"?
I mean it's the name of the buff the plugin should look for, whats wrong about this?


Ok, just a try concerning moebius post:
What about this line:
if (EffectList:Get(EffectList:GetCount()) == "charge") then
The Get function needs the Index of the effect, cause it's the last added effect I use Get count (schould return a number/index of last added effect).
EffectList:Get returns an effect, but how can I get the name of the effect, so I can compare it to the strin "charge"?
if (EffectList:Get(EffectList:GetCount()):GetName() == "charge") then

Last edited by Kunter : 06-10-2012 at 11:45 AM.
Reply With Quote