Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Function Parameter Bug

in Bugs Posts: 9

Here is a test app I made:

-- Bug

Cc = class()

function Cc:init(x,t,c,tr)
    -- you can accept and set parameters here
    print(x+t+c+tr)
end

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
    b = Cc()
    b:init(28,372,2,2938)
end


When I run it it displays an error:

attempt to perform arithmetic on a nil value (local x)

I really don't know what is happening O_o

Tagged:

Comments

  • Posts: 547

    Cc = class() function Cc:init(x,t,c,tr) -- you can accept and set parameters here print(x+t+c+tr) end -- Use this function to perform your initial setup function setup() print("Hello World!") b = Cc(28,372,2,2938) -- this is how you init an instance of a class, you don't need to call the 'init' function, it does that automaticly end

    edited code and put explanation in comment :) hope this helped

  • edited August 2015 Posts: 9

    Thanks! :-)

Sign In or Register to comment.