I need help with moving this image

Can some one tell me what I am doing wrong here is my code

-- Ball

nameofman = "Planet Cute:Character Boy"
sizeofman = vec2(spriteSize("Planet Cute:Character Boy"))
manposition = vec2()

function setup()
    
    supportedOrientations(LANDSCAPE_ANY)
    displayMode(FULLSCREEN)
    
    manposition = vec2(WIDTH/2, HEIGHT/2)
end   
    

function touched(touch)
    
    local touchposition = vec2(touch.x, touch.y)
    
    if (touch.state == BEGAN) then
    
    end
    
    if (touch.state == MOVING) then
        if ( (manposition.x - sizeofman.x/2) < touchposition.x and
             (manposition.x + sizeofman.x/2) > touchposition.x and
             (manposition.y - sizeofman.y/2) < touchposition.y and
             (manposition.y + sizeofman.y/2) > touchposition.y ) then
            manposition = touchposition 
        end
    end
    
    if (touch.state == ENDED) then
        
    end
 

end

function draw()
    
    background(103, 118, 228, 255)
    
    
    sprite(nameofman, manposition.x, manposition.y)
end

@DJ272727 Try this. Also, when you post code, put 3~'s on a line before and after your code to show it correctly.

-- Ball

supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)

function setup()
    nameofman = "Planet Cute:Character Boy"
    w,h = spriteSize("Planet Cute:Character Boy")
    sizeofman=vec2(w,h)
    manposition = vec2(WIDTH/2, HEIGHT/2)
end   
    
function touched(touch)    
    local touchposition = vec2(touch.x, touch.y)    
    if (touch.state == BEGAN) then    
    end    
    if (touch.state == MOVING) then
        if ( (manposition.x - sizeofman.x/2) < touchposition.x and
             (manposition.x + sizeofman.x/2) > touchposition.x and
             (manposition.y - sizeofman.y/2) < touchposition.y and
             (manposition.y + sizeofman.y/2) > touchposition.y ) then
            manposition = touchposition 
        end
    end    
    if (touch.state == ENDED) then        
    end
end

function draw()    
    background(103, 118, 228, 255)    
    sprite(nameofman, manposition.x, manposition.y)
end

The problem is that Codea only sets up its graphics after it reads the code, so your command that calculates image size doesn’t work (it gives zero). It needs to go inside the setup function.

But the thing you really need to know is how to find the problem, ie how to debug. The simplest way, in Codea, is to use print statements. So put a print statement in the touched function - even if you just put print(“ok”) - to make sure it is working, then print the position of the sprite, then its size, and so on, until you find something that doesn’t look right.

Thanks for the help

Hey @DJ272727! Just a suggestion, in your if statement inside your touched function, or anywhere else in your code, you can use local variables to save you doing lots of typing, ie local man = manposition, local s = sizeofman, or local tch = touchposition so you can abbreviate as much as you want. Local variables are great!