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 .
DarkblooM
Prole
Posts: 9 Joined: Fri Sep 20, 2024 9:29 pm
Location: France
Contact:
Post
by DarkblooM » Sun Jan 19, 2025 12:37 am
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.
slime
Solid Snayke
Posts: 3179 Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:
Post
by slime » 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.
DarkblooM
Prole
Posts: 9 Joined: Fri Sep 20, 2024 9:29 pm
Location: France
Contact:
Post
by DarkblooM » Sun Jan 19, 2025 11:08 am
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:
Just prints 0 to the console.
dusoft
Party member
Posts: 765 Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:
Post
by dusoft » 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
DarkblooM
Prole
Posts: 9 Joined: Fri Sep 20, 2024 9:29 pm
Location: France
Contact:
Post
by DarkblooM » Sun Jan 19, 2025 1:48 pm
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.
slime
Solid Snayke
Posts: 3179 Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:
Post
by slime » Sun Jan 19, 2025 2:52 pm
# counts the number of array elements in a table, whereas the settings table in getMode/setMode only has named fields.
DarkblooM
Prole
Posts: 9 Joined: Fri Sep 20, 2024 9:29 pm
Location: France
Contact:
Post
by DarkblooM » 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.
dusoft
Party member
Posts: 765 Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:
Post
by dusoft » Sun Jan 19, 2025 5:10 pm
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
pgimeno
Party member
Posts: 3709 Joined: Sun Oct 18, 2015 2:58 pm
Post
by pgimeno » Mon Jan 20, 2025 9:04 am
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.
Users browsing this forum: Google [Bot] and 0 guests