This seems like such an elementary question, but I seem to be missing something. I have an object with a function. I pass it two parameters, and the first one is always tossed. This only occurs on non-constructor functions.
For example:
Main.file
...
ballA = Ball(x,y,w,h)
ballA.printOut(10,20)
...
~
Ball.file
...
function Ball:printOut(a,b)
print("a", a, "b", b)
end
...
~
Output:
a 20 b nil
Something similar happens when I pass a vec2 as a parameter too. I only get the y value of the vector.
Have you created the Ball class? Look at this code below, which works fine, and see if you can find what you are missing.
function setup()
myRobot = Robot()
myRobot:speak("Hello","There")
myRobot:move(vec2(50,200))
end
function draw()
background(0, 0, 0, 255)
end
--You can put the class code below in a separate file if you like
Robot = class()
function Robot:init()
print "new robot created."
end
function Robot:speak(firstword,secondword)
print("1:",firstword,"2:",secondword)
end
function Robot:move(newLocation)
print ("Moved. New location is " .. newLocation.x .. ", " .. newLocation.y)
end
Actually, you should create the function with a colon : and then call it with a colon as well. You call it with BallA.printOut(10,20) but it should be BallA:printOut(10,20)