Help I’m really stuck ! I am just trying to get the left circle to move the square Left and the right circle to move the square right

function setup()
print("Hello World!")
x = 400
y = 400
o = 200
p = 400
c = 300
b = 300
end
function draw()
background(40, 40, 50)
ellip = ellipse(x,y,50,50)
ellip2 = ellipse(o,p,50,50)
strokeWidth(5)
rect(c,b,50,50)
end
function touched(ellip)
if ellip.state==BEGAN then
v1=vec2(ellip.x,ellip.y)
if v1:dist(vec2(x,y))<50 then
c = c + 20
end
end
end
function touched(ellip2)
if ellip2.state==BEGAN then
v1=vec2(ellip2.o,ellip2.p)
if v1:dist(vec2(o,p))<50 then
c = c - 20
end
end
end

function setup()
x = 400
y = 400
o = 200
p = 400
c = 300
b = 300
end
function draw()
background(40, 40, 50)
ellip1 = ellipse(x,y,50,50)
ellip2 = ellipse(o,p,50,50)
strokeWidth(5)
rect(c,b,50,50)
end
function touched(t)
if t.state==BEGAN then
v1=vec2(t.x,t.y) -- touch x,y position
-- check left ellipse
if v1:dist(vec2(o,p))<50 then
c = c - 20
end
-- check right ellipse
if v1:dist(vec2(x,y))<50 then
c = c + 20
end
end
end

@ewan - first, you are making things very difficult for yourself by not indenting your code properly.

The problem is that ellipse is not an object, it is a drawing command. You need to put your values in a table instead, as in

ellip=vec2(x,y)
ellip2=vec2(o,p)
--then you can draw with
ellipse(x,y,50,50)
--and handle touches with ONE touched function
function touched(t)
if vec2(t.x,t.y):dist(ellip)<50 then
--do something
elseif vec2(t.x,t.y):dist(ellip2)<50 then
--do something
end
end

@ewan You’ll find plenty of help here. One suggestion is to format your code to make it easier to read which will help you find errors as your code gets bigger. Compare your formatting to mine.

With all your help I learnt how to expand it so you can use up and down ! .Also I’m gonna check out your ebooks Ignatz ( I think I’m gonna need them ).

function setup()
x = 700
y = 100
o = 600
p = 100
c = 300
b = 300
r = 200
l = 150
g = 200
h = 50
end
function draw()
background(40, 40, 50)
ellip1 = ellipse(x,y,50,50)
ellip2 = ellipse(o,p,50,50)
ellip3 = ellipse(r,l,50,50)
ellip4 = ellipse(g,h,50,50)
strokeWidth(5)
rect(c,b,50,50)
end
function touched(t)
if t.state==BEGAN then
v1=vec2(t.x,t.y) -- touch x,y position
-- check left ellipse
if v1:dist(vec2(o,p))<50 then
c = c - 20
end
-- check right ellipse
if v1:dist(vec2(x,y))<50 then
c = c + 20
end
if v1:dist(vec2(r,l))<50 then
b = b + 20
end
if v1:dist(vec2(g,h))<50 then
b = b - 20
end
end
end

@ewan Nice going, you’re on your way to bigger and better things. A suggestion, your variables, x,y,o,p,r,l,g,h could have been x1,y1,x2,y2,x3,y3,x4,y4 to match your ellip names. As you write larger code, try to make your variable name more meaningful.