Problem with x values

There is an error with the x values, i dont know whats wrong with it :frowning:

-- ap1

-- Use this function to perform your initial setup
function setup()
        Timer = 0
    watch("Timer")
    game=Game(WIDTH/2,HEIGHT/2,768,768)
    jobs=Jobs()
    appel=Appel()
    scoreboard=Scoreboard(WIDTH-100,HEIGHT-100,0)
    
    
end


function draw()

    background(255, 255, 255, 255)
    sprite("Documents:TapirProductions",WIDTH/2,HEIGHT/2,768,768)

    
    if Timer >= 0 then
        Timer = Timer + 0.01
    end
    
    if Timer == 0.01 then
        sound(DATA, "ZgFAPjBLQE5oU1hAKyRFPgAAgD9tc/E+fwBAf0BASUBAZ0A7")
    end
    
    if Timer > 1 then
        sprite("Documents:Appeltjes Vangen",WIDTH/2,HEIGHT/2,768,768)
        Timer = Timer - 0.01
    end
    
    if Timer > 1.001 then
        game:draw()
        jobs:draw()
        appel:draw()
        scoreboard:draw()
    
        if appel.x == jobs.x + 50 and appel.x == jobs.x - 50 and appel.y == jobs.y + 50 and appel.y == job.y - 50 then
            scoreboard.i = scoreboard.i + 1
    end
end
    
        pushStyle()
    spriteMode(CORNER)
    sprite("Documents:Tpc",0,0,138,20)
    popStyle()
    
end

function touched(touch)

    if touch.x>=600 and touch.x<=600 +50 and touch.y>=200 and touch.y<=200 +50 and touch.state==BEGAN then
        Timer = Timer + 0.01
    end
    
end
error: error: [string "-- ap1..."]:41: attempt to perform arithmetic on field 'x' (a nil value)

This is line 41:

if appel.x == jobs.x + 50 and appel.x == jobs.x - 50 and appel.y == jobs.y + 50 and appel.y == job.y - 50 then
  • keeper1902

Sorry for the weird lay-out btw, dont know how to fix it

Hi @Keeper1902 - the error seems straightforward. It looks like jobs.x hasn’t been defined yet. It is difficult to see exactly where the problem is since you didn’t include the code for the Jobs class.

To make code appear properly on the forum you need to put three tildas at the start and three at the end.

I reformatted your code using fences - take a look at the source to see how to do it for next time.

What do you mean by using

if appel.x == jobs.x + 50 and appel.x == jobs.x - 50 and appel.y == jobs.y + 50 and appel.y == job.y - 50 then

it is impossible to let jobs.x+50 and jobs.x-50 equal to a same value at same time.