[SOLVED] Return value of love.window.getMode

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
DarkblooM
Prole
Posts: 9
Joined: Fri Sep 20, 2024 9:29 pm
Location: France
Contact:

[SOLVED] Return value of love.window.getMode

Post by DarkblooM »

Hello

Consider the following line:

Code: Select all

local w, h, f = love.window.getMode()
The f variable is empty? Am I misunderstanding the behavior of the getMode method?
Last edited by DarkblooM on Sun Jan 19, 2025 3:59 pm, edited 1 time in total.
User avatar
slime
Solid Snayke
Posts: 3179
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Return value of love.window.getMode

Post by slime »

Can you post the code that checks whether it's empty? I don't think that should be possible.
User avatar
DarkblooM
Prole
Posts: 9
Joined: Fri Sep 20, 2024 9:29 pm
Location: France
Contact:

Re: Return value of love.window.getMode

Post by DarkblooM »

slime wrote: Sun Jan 19, 2025 12:52 am Can you post the code that checks whether it's empty? I don't think that should be possible.
I just do this:

Code: Select all

for i = 1, #f do
  print(f[i], type(f[i]))
end
But nothing appears on the console.

Edit:
Even something as basic as:

Code: Select all

print(#f)
Just prints 0 to the console.
User avatar
dusoft
Party member
Posts: 765
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Return value of love.window.getMode

Post by dusoft »

What platform are you on?

I see this when using print_r function that you can find around (http://lua-users.org/wiki/TableSerialization):

Code: Select all

[1] = 1920
[2] = 1080
[3]:
[stencil] = true
[depth] = 0
[x] = 0
[y] = 0
[minwidth] = 1
[minheight] = 1
[fullscreen] = true
[fullscreentype] = desktop
[display] = 1
[vsync] = 1
[msaa] = 0
[borderless] = false
[resizable] = false
[centered] = true
[highdpi] = false
[usedpiscale] = true
[refreshrate] = 60
User avatar
DarkblooM
Prole
Posts: 9
Joined: Fri Sep 20, 2024 9:29 pm
Location: France
Contact:

Re: Return value of love.window.getMode

Post by DarkblooM »

dusoft wrote: Sun Jan 19, 2025 12:16 pm What platform are you on?

I see this when using print_r function that you can find around (http://lua-users.org/wiki/TableSerialization):

Code: Select all

[1] = 1920
[2] = 1080
[3]:
[stencil] = true
[depth] = 0
[x] = 0
[y] = 0
[minwidth] = 1
[minheight] = 1
[fullscreen] = true
[fullscreentype] = desktop
[display] = 1
[vsync] = 1
[msaa] = 0
[borderless] = false
[resizable] = false
[centered] = true
[highdpi] = false
[usedpiscale] = true
[refreshrate] = 60
Linux Mint 22

It seems to be working using pairs but what bogs me is that #f is still 0.
User avatar
slime
Solid Snayke
Posts: 3179
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Return value of love.window.getMode

Post by slime »

# counts the number of array elements in a table, whereas the settings table in getMode/setMode only has named fields.
User avatar
DarkblooM
Prole
Posts: 9
Joined: Fri Sep 20, 2024 9:29 pm
Location: France
Contact:

Re: Return value of love.window.getMode

Post by DarkblooM »

I'm not sure I understand it fully but at least I now know how to work around it.
User avatar
dusoft
Party member
Posts: 765
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Return value of love.window.getMode

Post by dusoft »

DarkblooM wrote: Sun Jan 19, 2025 3:56 pm I'm not sure I understand it fully but at least I now know how to work around it.
Check some Lua tutorials on tables (and their indexes) for clarification. And while you are at it, I recommend you check also pairs vs ipairs iteration (gaps/nils vs consecutive/integers) difference. These are common issues people have coming to Lua.

E.g. compare this with your solution:

Code: Select all

function table.length(table)
    local count = 0
    for _ in pairs(table) do
        count = count + 1
    end
    return count
end
User avatar
pgimeno
Party member
Posts: 3709
Joined: Sun Oct 18, 2015 2:58 pm

Re: [SOLVED] Return value of love.window.getMode

Post by pgimeno »

The # operator will return zero unless the table has a consecutive series of numeric integer indices starting at 1 (it's not exactly true but close enough). If a table has no numeric indices, the # operator will return zero. I've been caught by that too.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 2 guests