Download files straight from the game/program?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
MarcoPolo0306
Prole
Posts: 5
Joined: Wed Jun 20, 2018 12:46 am

Download files straight from the game/program?

Post by MarcoPolo0306 » Wed Jun 20, 2018 12:51 am

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!

User avatar
master both
Party member
Posts: 253
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: Download files straight from the game/program?

Post by master both » Wed Jun 20, 2018 4:12 pm

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

MarcoPolo0306
Prole
Posts: 5
Joined: Wed Jun 20, 2018 12:46 am

Re: Download files straight from the game/program?

Post by MarcoPolo0306 » Wed Jun 20, 2018 9:53 pm

Thanks, but I wanted to save it to the computer. I'll check the wiki, hopefully I find something there.

MarcoPolo0306
Prole
Posts: 5
Joined: Wed Jun 20, 2018 12:46 am

Re: Download files straight from the game/program?

Post by MarcoPolo0306 » 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. :)

User avatar
master both
Party member
Posts: 253
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: Download files straight from the game/program?

Post by master both » Wed Jun 20, 2018 11:23 pm

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

MarcoPolo0306
Prole
Posts: 5
Joined: Wed Jun 20, 2018 12:46 am

Re: Download files straight from the game/program?

Post by MarcoPolo0306 » Thu Jun 21, 2018 11:57 pm

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?

KayleMaster
Party member
Posts: 199
Joined: Mon Aug 29, 2016 8:51 am

Re: Download files straight from the game/program?

Post by KayleMaster » Fri Jun 22, 2018 8:00 am

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."

Post Reply

Who is online

Users browsing this forum: Exabot [Bot] and 41 guests