Ball Clicker Game ///Need Help

I’ve been working on this game for some time and I can’t seem to make it so when I touch one of the balls it give me a point. So far I only get a point when the balls touch each other. How can I fix this…I’m really new to this language so I have no real idea of what to do.

``````function setup()
x=10
y=100
speedX=20
speedY=25
x2=100
y2=350
speedX2=20
speedY2=25
score=0
end

function draw()
distance=math.sqrt((x-x2)^2+(y-y2)^2)
speedX=-speedX
speedX2=-speedX2
speedY=-speedY
speedY2=-speedY2
score=score+1
print("point",score)
function collide(contact)
if contact.state == BEGAN then
print("HIT!")
end

end

end
background(255, 90, 0, 255)
fill(0, 52, 255, 255)
x=x+speedX
speedX=-speedX
end
y=y+speedY
speedY=-speedY
end

fill(98, 255, 0, 255)
x2=x2+speedX2
speedX2=-speedX2
end
y2=y2+speedY2
speedY2=-speedY2
end
end
``````

This is what I have so far

@KatzNDA First, when you post code, put 3~s on a line before and after your code so it show properly. Click on the gear icon at the upper right of your code and select edit and look at the ~'s I added. Second, the function collide should be by itself and not in the draw function. Third, if you want to touch the balls, you need to use the touched function. See the build in reference for its use.

@KatzNDA - have you read any tutorials on Lua (the language behind Codea)? Do you know the main Lua functions, and how tables work?

If not, you aren’t ready to program a game. You can’t learn a programming language from scratch, by making a game. And we don’t have time to hold your hand every time you have a problem which you could have avoided by doing some reading.

When I started with Codea, I spent weeks just reading about it before I started making anything with it - and I already had programming experience.

This is for a class I don’t have a choice in the matter

@KatzNDA If that’s the case, then look thru some of the other posts for examples of code to see how the functions are used. The basic functions are setup(), draw(), touched(), collide().

@KatzNDA - ok, I’m not trying to be hard on you. We are happy to help fix problems, but it’s just that we have lots of kids who buy Codea and want to have an app on the store next week, and expect us to write most of the code for them.

I suggest if it’s for a class, that you say that at the beginning, because we’ll understand. You should also tell us what your assignment is.