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 »

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: 262
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: Download files straight from the game/program?

Post 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
MarcoPolo0306
Prole
Posts: 5
Joined: Wed Jun 20, 2018 12:46 am

Re: Download files straight from the game/program?

Post by MarcoPolo0306 »

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 »

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: 262
Joined: Tue Nov 08, 2011 12:39 am
Location: Chile

Re: Download files straight from the game/program?

Post 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
MarcoPolo0306
Prole
Posts: 5
Joined: Wed Jun 20, 2018 12:46 am

Re: Download files straight from the game/program?

Post 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?
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Re: Download files straight from the game/program?

Post 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."
Attachment Studios
Prole
Posts: 6
Joined: Wed Oct 07, 2020 5:34 am

Re: Download files straight from the game/program?

Post by Attachment Studios »

Hi!

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

Thanks,
~Attachment Aditya
User avatar
dusoft
Party member
Posts: 492
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Download files straight from the game/program?

Post by dusoft »

User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Download files straight from the game/program?

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 67 guests