Contact Function?

Greetings! Can someone please help me figure out why my contact function doesn’t seem to be working right?

In set up

ball_d = 60
    p_ball = physics.body(CIRCLE,ball_d / 2)
    p_ball.x = (math.random(200,600))
    p_ball.y = (math.random(200,600))
    p_ball.gravityScale = 1
    p_ball.restitution = .8
    p_ball.friction = 1
    p_ball.info = 'p_ball'
    p_ball.linearVelocity = vec2(math.random(400),math.random(400))
    p_ball.linearVelocity=vec2(math.random(400),math.random(400))
    
function collide (contact)
        
        if contact.state == BEGAN then
            if contact.bodyA.info == 'p_ball' or contact.bodyB.info == 'p_ball' then
                sound(SOUND_HIT, 27276)
                print("Contact")
            end
        end
    end

I’m not sure if this is all the code I need to bring so please tell if its not.
I also read this guide to help me make this but it dint seem to give the solution to my problem.
http://coolcodea.wordpress.com/2013/03/21/6-more-physics

You didn’t show enough code, so I added my own. I used your collide function.


function setup()
    b1=physics.body(CIRCLE,30)
    b1.x=300
    b1.y=900
    b1.info="p_ball"
    
    b2=physics.body(CIRCLE,30)
    b2.x=300
    b2.y=300
    b2.type=STATIC
    b2.info="p_ball"
end

function draw()
    background(40,40,50)
    fill(255)
    ellipse(b1.x,b1.y,60)
    ellipse(b2.x,b2.y,60)
end

function collide (contact)
    if contact.state == BEGAN then
        if contact.bodyA.info == 'p_ball' or contact.bodyB.info == 'p_ball' then
            sound(SOUND_HIT, 27276)
            print("Contact")
        end
    end
end

You also might want to look at this code I posted last year.

http://twolivesleft.com/Codea/Talk/discussion/1349/brownian-motion-kind-of#Item_2

@Goatboy76 - maybe you thought your ball would collide with the edge of the screen, but it won’t unless you put a physics object there.

Physics objects only collide with other physics objects

In reponse to you Ignatz, I built “walls” around the screens so that it bounces around and I can pick up the ball with a touch and throw it around.

ok, fine, just checking!

I was just being stupid, problem solved. I had two contact functions.