Addon/Mod Loader Help

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.
Post Reply
Bigbadbeee
Prole
Posts: 5
Joined: Thu Nov 20, 2014 9:38 pm

Addon/Mod Loader Help

Post by Bigbadbeee »

Hello, I would Like to know how to Add Addon/Mod Support for my game using A fused game and the AppData Folder
Code ( Without being Fused )

Code: Select all

function LoadAddons()
	for file in io.popen("dir /b addons"):read("*all"):gmatch("(.-)\n") do
		if file ~= "." and file ~= ".." then
			--local attr=lfs.attributes("addons/" ..file)
			if file:find("%.lua$") then
				require("addons/"..file:gsub("%.lua$", ""))
			end
		end
	end
end

function love.load()
LoadAddons()
end
Would This work and what would the code look like using AppData?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Addon/Mod Loader Help

Post by Robin »

You're pretty far along, I think with clever use of the following functions, you'd be done:

[wiki]love.filesystem.enumerate[/wiki]
[wiki]love.filesystem.load[/wiki]
Help us help you: attach a .love.
Bigbadbeee
Prole
Posts: 5
Joined: Thu Nov 20, 2014 9:38 pm

Re: Addon/Mod Loader Help

Post by Bigbadbeee »

Robin wrote: [wiki]love.filesystem.enumerate[/wiki]
Now:
[wiki]love.filesystem.getDirectoryItems[/wiki]
Zeliarden
Party member
Posts: 139
Joined: Tue Feb 28, 2012 4:40 pm

Re: Addon/Mod Loader Help

Post by Zeliarden »

bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Addon/Mod Loader Help

Post by bobbyjones »

Mount is for .zips and .loves I think. You wouldn't need to mount a folder I believe. But having mods in a .zip would be cool. Does love.filesystem mounts anything you pass as a zip? Or does it check the extension?
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Addon/Mod Loader Help

Post by Inny »

Just as a general comment about adding Mod support, it usually isn't enough to just load a script and leave it to the mod makers to handle compatibility. You're going to have to commit to a mod API, i.e. a published list of functions that the mod authors will use to add their features. As a for instance, if you wanted to add a crafting recipe, you'd want an API function named RegisterCraftingRecipe, with a well known parameter list. Otherwise, the mods would just seek out the existing table and try to add stuff to it, and one mod may use table.insert, while another overwrites craftingRecipes[1], and a third replaces the table completely.
Bigbadbeee
Prole
Posts: 5
Joined: Thu Nov 20, 2014 9:38 pm

Re: Addon/Mod Loader Help

Post by Bigbadbeee »

Inny wrote:Just as a general comment about adding Mod support, it usually isn't enough to just load a script and leave it to the mod makers to handle compatibility. You're going to have to commit to a mod API, i.e. a published list of functions that the mod authors will use to add their features. As a for instance, if you wanted to add a crafting recipe, you'd want an API function named RegisterCraftingRecipe, with a well known parameter list. Otherwise, the mods would just seek out the existing table and try to add stuff to it, and one mod may use table.insert, while another overwrites craftingRecipes[1], and a third replaces the table completely.
How would I make a mod API?
P.S I know you would do something like

Code: Select all

modapi = modapi or {}
function modapi:RegisterMod()
Also how would I make sure the Mod has those functions in it and if it does Add the mod(or something like adding)?
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Addon/Mod Loader Help

Post by Inny »

Bigbadbeee wrote:How would I make a mod API?
That might get philosophical, and I'm sure lots of people have different opinions. A good tip would be to simply ask someone who would likely be the person that makes mods for your game, and come up with something you're both okay with working with. Or, just mod it yourself, i.e. make an addon that's not part of the game directly, but can be tacked on for fun (like a Hawaiian-Shirt Day mod, that makes all of your characters wear hawaiian shirts).

Of course, if you spend all of your time working on the mod api and not the game itself, and never get the game finished, then nobody will want to mod it. So, focus on the game first. Add the mod api later.
Bigbadbeee wrote: P.S I know you would do something like

Code: Select all

modapi = modapi or {}
function modapi:RegisterMod()
Also how would I make sure the Mod has those functions in it and if it does Add the mod(or something like adding)?
Again, philosophical and people's opinions will differ, but this is probably too general. Instead think of it more on a feature by feature basis. You have a list of swords in the game, have a SwordList:AddSword() function. Have a city with NPCs wandering around, GetCity("WhiteRun"):Add(Character("Anti-Nazeem")).
User avatar
I~=Spam
Party member
Posts: 206
Joined: Fri Dec 14, 2012 11:59 pm

Re: Addon/Mod Loader Help

Post by I~=Spam »

Aside from an api you will also need to sandbox the mods. (That way the mod cannot delete personal files of the user or send it across the web to someone...) This is a really good one: https://github.com/APItools/sandbox.lua
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 5 guests