First day coding... Anything! Not just Codea

Two hours into my first ever attempt at coding. Just running a tutorial to learn the basics of touch. And have gotten this far (see below) but am confused as to why this isn’t working.

– Use this function to perform your initial setup
function setup()
x = WIDTH/2
y = HEIGHT/2
end

– This function gets called once every frame
function draw()
background(30, 28, 31, 255)
ellipse(x,y,100)
end

function touched(touch)
x = touch.x
y = touch.y
end
if touch.state == BEGAN then
c = color(255, 0, 0, 255)
end
if touch.state == MOVING then
c = color(196, 183, 78, 255)
end
if touch.state == ENDED then
c = color(0, 0, 0, 255)
end

I’m sure I can hear your sniggering now.

Massively embarrassing I know, but like I say, first attempt and woul really appreciate anyone’s help.

Thanks

@Damnmoon, use 3 tildes at the start and at the end to format code in the forums.

Looks like your if touch.state are all outside the touch function. Move them inside the touch function and it should work. But it won’t do anything yet because you’ve define the c variable but haven’t used it yet anywhere. See if you can make the background change to the c color.

Or like this, change the color of the ellipse…

-- Use this function to perform your initial setup
function setup()     
x = WIDTH/2     
y = HEIGHT/2 

c = color(0, 0, 0, 255) --init c as black
end

-- This function gets called once every frame 
function draw()    
 background(30, 28, 31, 255)
fill( c)--add filling color to ellipse defined in c
    ellipse(x,y,100)    
 end    

  function touched(touch)    
 x = touch.x     
y = touch.y   
--moved that into the touched scope, as you want to change this while touching
 if touch.state == BEGAN then    
     c = color(255, 0, 0, 255)   
  end       
  if touch.state == MOVING then    
     c = color(196, 183, 78, 255) 
    end     
    if touch.state == ENDED then    
     c = color(0, 0, 0, 255)
  end
 end

That’s fantastic, thank you to both of you. I can now move a circle and change its colour. The creators of angry birds are probably crapping themselves.