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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

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

Post 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)
My avatar code for the curious :D V1, V2, V3.
User avatar
zorg
Party member
Posts: 3435
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 11 guests