Problem with my code. [Fixed]

Yes, I’m a noob. Please don’t judge me, I can’t find the answer anywhere. Anyway, the function that I’m struggling with is ball.Draw(). I have made an instance of ball called myball, and I use myball.Draw() to run it. The problem is, it says that my variables are nil (it says that there’s an error in stroke(), it expected a number and got nothing.
Code in the ball class:

Ball = class()

function Ball:init(x)
    -- you can accept and set parameters here
    self.xpos = WIDTH / 2
    self.ypos = HEIGHT / 2
    self.colourred = 0
    self.colourblue = 255
    self.colourgreen = 255
    self.colour = color(colourred, colourblue, colourgreen)
    self.ballsize = 25
end

function Ball.draw()
    stroke(Ball.colour)
    fill(Ball.colour)
    rect( xpos, ypos, ballsize, ballsize)
end

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

    end 

And yes, I probably should use a vector, I just haven’t gotten around to it.

@Okok111 First off try puttin ~~~ before and after your code so it displays nicer and easier to read.

Second, the problem is that you are setting variables “self.example” and later just using “example”

So try this:

Ball = class()

function Ball:init(x)
self.xpos = WIDTH / 2
self.ypos = HEIGHT / 2
self.colourred = 0
self.colourblue = 255
self.colourgreen = 255
self.colour = color(self.colourred, self.colourblue, self.colourgreen)
self.ballsize = 25
end

function Ball:draw()
stroke(self.colour)
fill(self.colour)
rect(self.xpos, self.ypos, self.ballsize, self.ballsize)

function Ball:touched(touch)
end

I’m still getting the same error… This is the error the bugger is giving me:

error: [string "Ball = class()..."]:14: bad argument #1 to 'stroke' (number expected, got nil)

Need to use self in the class not Ball.


--# Main
-- forum help

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
    ball = Ball()
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)
    ball:draw()

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    
end


--# ball
Ball = class()

function Ball:init(x)
self.xpos = WIDTH / 2
self.ypos = HEIGHT / 2
self.colourred = 0
self.colourblue = 255
self.colourgreen = 255
self.colour = color(self.colourred, self.colourblue, self.colourgreen)
self.ballsize = 25
end

function Ball:draw()
stroke(self.colour)
fill(self.colour)
rect(self.xpos, self.ypos, self.ballsize, self.ballsize)
end

function Ball:touched(touch)
end

As well as the changes Briarfox says, make sure you call myball:draw(), not myball.draw(). (Briarfox does this but you might not have noticed).

Thanks a ton to all of you for your help, it works now. Updating the title so that no more people end up looking at this.