Who's do I get these functions to refer to the same 'Apple'?

I have an apple value placed randomly throuought the field. When my blob, comes near it, I want the apple to dissipear, (him eating it). The problem arises when I can’t get it to refer to the same apple sprite, it seems to randomly choose.

The code in Question:


function setup()
    
end

function draw()
    
    background(40, 40, 50)

    sprite("Dropbox:blobbyBlue", CurrentTouch.x, CurrentTouch.y)
    
   Apple = sprite("Dropbox:Apple", appleX, appleY)
            
end

appleX = math.random (1,560)
appleY = math.random (1,560)

function eat ()

gone = 0

    if CurrentTouch.x == appleX then
        end
    gone, gone= spriteSize (Apple)
end

Try putting your code in between two sets of three ~'s

@Adam9812 - your code has several problems.

I suggest you do some tutorials or read some ebooks here, to learn more about Codea.

https://bitbucket.org/TwoLivesLeft/core/wiki/

@Adam9812 Welcome to Codea. You can use three (~) before and after your code to correctly format it.

Just using your code but this is one way to do it.

function setup()
    appleX = math.random (1,560)
    appleY = math.random (1,560)
    bug = readImage("Planet Cute:Enemy Bug")
    gone = false

end

function draw()

    background(40, 40, 50)

    sprite("Planet Cute:Character Boy",CurrentTouch.x,CurrentTouch.y)

    if not gone then sprite(bug,appleX,appleY) end
    eat()

end



function eat ()


    local w,h = bug.width/2,bug.height/2
    local top = appleY + h
    local bottom = appleY - h
    local left = appleX - w
    local right = appleX +w
    local x,y = CurrentTouch.x,CurrentTouch.y
    
    if x >= left and x <= right and y >= bottom and y<= top then
        print("Touched")
        gone = true
    end
    
end

```

Thanks!