Page 1 of 1

Can't Get Files of Desktop with LOVE2D

Posted: Sat Apr 29, 2017 4:19 am
by BukkitmanMC
Hey There! I am new to the LOVE Forums even though I have programmed with this Library before, so I am pretty used to it :crazy: ! However, Right now, I am working on a game using this framework, and it supposed to access the files of your Desktop! however every string says "nil" in the files!. Also, when I ask it to print out an entire table, it only shows some stuff I don't understand like: "table: 0x03059638" :x ! can you figure out why it does that? if yes, thanks!

The Code of the only file that really has something, since I can't figure out how to add a file:

Code: Select all

function love.load()
  require "player" -- Not Really Anything Right Now

  -- Lets add Some Variables!
  -- Some Directory Suff first for Variables...
  DesktopDirectory = love.filesystem.getUserDirectory().."Desktop"
  DesktopFiles = love.filesystem.getDirectoryItems(DesktopDirectory)

  -- These are the Images!
  images = {
    background = love.graphics.newImage("gfx/desktop.png")
  }

  players = {player.new(10, 10, 10, 10, "gfx/stickman.png", true)}

  print(DesktopFiles)
end

function love.update(dt)

end

function love.draw()
  love.graphics.draw(images.background)
end

Re: Can't Get Files of Desktop with LOVE2D

Posted: Sat Apr 29, 2017 10:08 am
by pedrosgali
You are trying to print a table, that's why it says 'tableX0...'. Try

Code: Select all

for k in pairs(desktopFiles) do
  print(desktopFiles[k])
end
Don't think love can read from your desktop though without using FFI. I've not used it before, maybe someone else can help with that. :)

Re: Can't Get Files of Desktop with LOVE2D

Posted: Sat Apr 29, 2017 12:32 pm
by zorg
Löve has three ways to do filesystem stuff:
- love.filesystem functions, which are the recommended way, support utf-8 encoding, work the same on all OS-es, and can only access the game's own directory and the save directory that's set with your project's identity.
- the lua io functions, which can access any folder and file anywhere on your computer, but it doesn't really guarantee utf-8 support on all OS-es. (windows)
- Advanced stuff: Using the FFI to call the PhysFS functions löve uses directly, in a way to circumvent their "allowed folder" limitations, akin to how file and folder dropping works.

For starters, i'd recommend forgetting every other folder apart from the save folder and the game's own, and using the love.filedropped and love.directorydropped functions to "support" files elsewhere, like on the desktop.

As for tables, you need to print their contents, as pedrosgali said above, otherwise, you'll print the reference's memory location, which is pretty much useless unless you want to compare if two variables point to the same table.

Re: Can't Get Files of Desktop with LOVE2D

Posted: Sat Apr 29, 2017 8:16 pm
by BukkitmanMC
zorg wrote: Sat Apr 29, 2017 12:32 pm Löve has three ways to do filesystem stuff:
- love.filesystem functions, which are the recommended way, support utf-8 encoding, work the same on all OS-es, and can only access the game's own directory and the save directory that's set with your project's identity.
- the lua io functions, which can access any folder and file anywhere on your computer, but it doesn't really guarantee utf-8 support on all OS-es. (windows)
- Advanced stuff: Using the FFI to call the PhysFS functions löve uses directly, in a way to circumvent their "allowed folder" limitations, akin to how file and folder dropping works.

For starters, i'd recommend forgetting every other folder apart from the save folder and the game's own, and using the love.filedropped and love.directorydropped functions to "support" files elsewhere, like on the desktop.

As for tables, you need to print their contents, as pedrosgali said above, otherwise, you'll print the reference's memory location, which is pretty much useless unless you want to compare if two variables point to the same table.
Thanks! I didn't know about that before! so this will definitely be useful! guess I'll be trying to figure out how to use lua's io functions later!

Also,
pedrosgali wrote: Sat Apr 29, 2017 10:08 am You are trying to print a table, that's why it says 'tableX0...'. Try

Code: Select all

for k in pairs(desktopFiles) do
  print(desktopFiles[k])
end
Don't think love can read from your desktop though without using FFI. I've not used it before, maybe someone else can help with that. :)

Thanks for the help, but for some reason, the file names won't show up. does it have to do with the directory it is looking at?

EDIT: Thanks For The Info! :ultraglee:

Re: Can't Get Files of Desktop with LOVE2D

Posted: Tue May 23, 2017 3:58 am
by BukkitmanMC
zorg wrote: Sat Apr 29, 2017 12:32 pm Löve has three ways to do filesystem stuff:
- love.filesystem functions, which are the recommended way, support utf-8 encoding, work the same on all OS-es, and can only access the game's own directory and the save directory that's set with your project's identity.
- the lua io functions, which can access any folder and file anywhere on your computer, but it doesn't really guarantee utf-8 support on all OS-es. (windows)
- Advanced stuff: Using the FFI to call the PhysFS functions löve uses directly, in a way to circumvent their "allowed folder" limitations, akin to how file and folder dropping works.

For starters, i'd recommend forgetting every other folder apart from the save folder and the game's own, and using the love.filedropped and love.directorydropped functions to "support" files elsewhere, like on the desktop.

As for tables, you need to print their contents, as pedrosgali said above, otherwise, you'll print the reference's memory location, which is pretty much useless unless you want to compare if two variables point to the same table.
Last of all, if I were to use love.directoryDropped(), how would I use it to get the file names? I am guessing it uses love.filesystem.mount, but how would I convert it into file names in an array?

Re: Can't Get Files of Desktop with LOVE2D

Posted: Tue May 23, 2017 9:11 am
by zorg
'UniqueName' is whatever you want to call the mounted directory's root inside löve.

Code: Select all

function love.directorydropped( path )
love.filesystem.mount(path, 'UniqueName')
files = love.filesystem.getDirectoryItems('UniqueName')
end

Re: Can't Get Files of Desktop with LOVE2D

Posted: Wed May 24, 2017 2:38 am
by BukkitmanMC
zorg wrote: Tue May 23, 2017 9:11 am 'UniqueName' is whatever you want to call the mounted directory's root inside löve.

Code: Select all

function love.directorydropped( path )
love.filesystem.mount(path, 'UniqueName')
files = love.filesystem.getDirectoryItems('UniqueName')
end
Ah! Thanks! With this, I was able to get that part to work! When I get the Beta Build of the Game Complete, I might as well show the game to you all!