Page 1 of 1

[SOLVED] - [string "ImageData.lua"]:38: bad argument #1 to 'max' (number expected, got nil)

Posted: Fri Mar 31, 2023 1:30 pm
by Bigfoot71
Hi :)

I think there is a problem with the Image:mapPixel method or I am missing something too big, I kept getting this error for no apparent reason when I wanted to generate a texture:

Code: Select all

[string "ImageData. lua"]:38: bad argument #1 to 'max' (number expected, got nil)
I then reduced the problem as much as possible, removing all the function calls, calculations, etc., and so I ended up with this very small piece of stupid code which is apparently the cause of the error:

Code: Select all

renderBuffer:mapPixel(function (x, y)
    if y < 300 then
        return 0, .1, .5
    elseif y > 300 then
        return 0, .5, .1
    end
end)
I tried with love 11.3 and 11.4 in doubt but still the same.

An idea ?

Edit: I wasted so much time on this that I was going crazy :crazy:
It's just that when Y is 300 nothing is returned, but the error was confusing, sorry ^^

A possible solution:

Code: Select all

renderBuffer:mapPixel(function (x, y)
    if y < 300 then
        return 0, .1, .5
    elseif y > 300 then
        return 0, .5, .1
    end
    return 0, 0, 0, 0
end)

Re: [SOLVED] - [string "ImageData.lua"]:38: bad argument #1 to 'max' (number expected, got nil)

Posted: Sat Apr 01, 2023 3:20 am
by zorg
Alternatively, consider the fact that <= and >= exist as logical comparison functions as well; either using <= and > or < and >= would fix it as well.