Oops, error in the psuedo code, doh. In my actual code I used : when calling.
I just found the error though, it was indeed because of the : and . but not where I called the function but where I set the function I used : instead of .
I guess now I know when to use which, although I’m not exactly clear on the underlying difference between : and .
When you write B = ball(), Codea returns the “address” of the ball it has created and stores it in B. It is just a number, nothing more.
When you then write B:state(), the colon tells Codea to send the address in B as the first parameter, so B:state() is EXACTLY the same as ball.state(B). That is all the colon does, ie pass the address of a particular ball as the first parameter.
Try this
A=class()
function A:init(a)
self.a=a
end
function A:mult(b)
return self.a * b
end
function setup()
c = A(5)
print(c:get(2)) --prints 10
d = A(7)
print(d:get(3)) --prints 21
print(A.get(c,2)) --prints 10
print(A.get(d,5) --prints 35
end