Page 1 of 1

Addon/Mod Loader Help

Posted: Fri May 08, 2015 7:45 pm
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?

Re: Addon/Mod Loader Help

Posted: Fri May 08, 2015 8:13 pm
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]

Re: Addon/Mod Loader Help

Posted: Fri May 08, 2015 8:20 pm
by Bigbadbeee
Robin wrote: [wiki]love.filesystem.enumerate[/wiki]
Now:
[wiki]love.filesystem.getDirectoryItems[/wiki]

Re: Addon/Mod Loader Help

Posted: Fri May 08, 2015 10:32 pm
by Zeliarden

Re: Addon/Mod Loader Help

Posted: Sat May 09, 2015 5:50 am
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?

Re: Addon/Mod Loader Help

Posted: Sat May 09, 2015 3:32 pm
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.

Re: Addon/Mod Loader Help

Posted: Sun May 10, 2015 4:34 pm
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)?

Re: Addon/Mod Loader Help

Posted: Mon May 11, 2015 2:09 am
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")).

Re: Addon/Mod Loader Help

Posted: Mon May 11, 2015 4:58 pm
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