Page 1 of 1

Download files straight from the game/program?

Posted: Wed Jun 20, 2018 12:51 am
by MarcoPolo0306
I am new to the Love game creator, but not new to Lua. I want to make a game that will download the game files from GitHub or my website. Any help would be apricated!

Re: Download files straight from the game/program?

Posted: Wed Jun 20, 2018 4:12 pm
by master both
Hi and welcome to the forums,
If you want to download files from another server you can use the socket http module that comes with Löve:

Code: Select all

local http = require "socket.http"

local logo

function love.load()
   logo = http.request("https://love2d.org/style/logo.png")
   logo = love.filesystem.newFileData(logo, "logo.png")
   logo = love.graphics.newImage(logo)
end

function love.draw()
   love.graphics.draw(logo)
end

Re: Download files straight from the game/program?

Posted: Wed Jun 20, 2018 9:53 pm
by MarcoPolo0306
Thanks, but I wanted to save it to the computer. I'll check the wiki, hopefully I find something there.

Re: Download files straight from the game/program?

Posted: Wed Jun 20, 2018 10:47 pm
by MarcoPolo0306
Alright, I found here where the data of the game is saved. I'll try copying the downloaded data where the data is saved to a %appdata%/MyGame or %appdata%/Testing file. Maybe this could help someone else who is looking on how to do this. :)

Re: Download files straight from the game/program?

Posted: Wed Jun 20, 2018 11:23 pm
by master both
MarcoPolo0306 wrote: Wed Jun 20, 2018 10:47 pm Alright, I found here where the data of the game is saved. I'll try copying the downloaded data where the data is saved to a %appdata%/MyGame or %appdata%/Testing file. Maybe this could help someone else who is looking on how to do this. :)
That's right, If you want to save the file you have to use love.filesystem.write:

Code: Select all

local http = require "socket.http"

function love.load()
   local logo = http.request("https://love2d.org/style/logo.png")
   love.filesystem.write("logo.png", logo)
end

function love.draw()
   local s = "Saved on "..love.filesystem.getSaveDirectory().."/logo.png"
   love.graphics.print(s, 10, 10) -- /Users/Nico/Library/Application Support/LOVE/u/logo.png in my case
end

Re: Download files straight from the game/program?

Posted: Thu Jun 21, 2018 11:57 pm
by MarcoPolo0306
Alright, I've used that now, but whenever I try to change the directory that the file saves in, the file won't save whatsoever. Maybe the directory needs to be valid?

Re: Download files straight from the game/program?

Posted: Fri Jun 22, 2018 8:00 am
by KayleMaster
Read this:
https://love2d.org/wiki/love.filesystem
"Each game is granted a single directory on the system where files can be saved through love.filesystem. This is the only directory where love.filesystem can write files."

Re: Download files straight from the game/program?

Posted: Sun Feb 21, 2021 4:01 pm
by Attachment Studios
Hi!

I wanted some more help regarding this topic! What if I want to save a zip, then unmount it?

Thanks,

Re: Download files straight from the game/program?

Posted: Sat Feb 27, 2021 9:48 pm
by dusoft

Re: Download files straight from the game/program?

Posted: Mon Mar 01, 2021 1:12 pm
by zorg
Attachment Studios wrote: Sun Feb 21, 2021 4:01 pm Hi!

I wanted some more help regarding this topic! What if I want to save a zip, then unmount it?

Thanks,
If the premise was that you just downloaded a zip, then you don't need to unmount it since you never mounted it in the first place.

If it was instead about mounting a zip, saving something into it (which i'm not sure is possible), then unmounting it, then that's a different thing.

Also, don't use love.filesystem.remove unless you want to actually delete the file.