Why does this simple code not work, trying to pass values to class for sprite display

I can’t work out why this simple code will not work. I have created a class called mysprite which I am trying to pass position/size values to. Printing the self values indicates that the values in the initial setup are being stored however the static image name in the draw function of mysprite will only position itself at 0,0.

What fundamental concept am I missing?

  function setup()

 s1 = mysprite(10,20,30,40)
 s2 = mysprite(50,50,500,100)
end

 function draw()
 s1:draw()
 s2:draw()
 end

function touched(touch) 
end

mysprite = class()

 function mysprite:init(a,b,x,y)
-- you can accept and set parameters here
self.a = a
self.b = b
self.x = x
self.y = y
end

function mysprite:draw()
-- Codea does not automatically call this method
print(self.x)
print(self.y)
print(self.a)
print(self.b)
sprite("Platformer Art:Block Brick",self.x,self.y,self,a,self.b)
end

 function mysprite:touched(touch)
-- Codea does not automatically call this method
end

t2i8

Line #31 you have self,a instead of self.a

@Briarfox can’t tell you how many times I’ve put a comma instead of a full stop on the iPad keyboard…

@Luatee I do the same. I’m so use to it now that it’s the first thing I check.

Thanks for the quick responses to my obvious error, I assume that this kind of typo would not raise an runtime error.

:slight_smile:

the other VERY common typo is a.func() instead of a:func(). throws a ´self is ni? error.

@Jvm38: Yep. Especially so since that’s the more common notation in other languages :expressionless: