sby said:
hey modguy, i put together a new modtemplate that i use to handle the typical settings and initialization stuff. just wanted to run it by you first to see if you agree on how i did things
The settings loader should automatically try the mod folder and upon failing, the settings folder.
You've got it to load a file based on the file name, and then using a fixed name. I'd rather you used a fixed name instead of dynamically pulling the name as this is what's causing issues.
It works, and that's fine, but it makes more sense to cut down on the number of methods being used so that users are clear on what needs to be done.
You're currently using the "name it the same as the swf" style, why not just hardcode the name of the SWF as filename? It would give the same result.
So something like this:
import flash.utils.Dictionary;
var main;
var modSettingsLoader:Class;
var cMC:MovieClip = new MovieClip();
var setsettingsfilename = "mysettings";
var triedsetfilename = false;
var testoption:Number = 0;
function initl(l)
{
main = l;
var msl = new modSettingsLoader(setsettingsfilename,settingsLoaded);
msl.addEventListener("settingsNotFound",settingsNotFound);
cMC.addEventListener(Event.ENTER_FRAME, doCheck);
main.registerUnloadFunction(doUnload);
main.unloadMod();
}
function settingsLoaded(e)
{
var dict:Dictionary = e.settings;
for (var key:Object in dict)
{
var val:Object = dict[key];
if (this.hasOwnProperty(key))
{
this[key] = val;
main.updateStatusCol(key + " = "+ val,"#00ff00");
}
else
{
main.updateStatusCol("invalid setting: "+key,"#FF0000");
}
}
main.traceDebug("testoption:"+testoption);
main.monitorDebug("testoption monitored: ",this,"testoption");
}
function settingsNotFound(e)
{
main.updateStatusCol(e.msg,"#FF0000");
}
function doCheck(e)
{
testoption++;
}
function doUnload()
{
main.clearDebug();
cMC.removeEventListener(Event.ENTER_FRAME, doCheck);
}
EDIT:
sby said:
also, just found an amazing way to cut out those annoying switch statements:
when i have the variable the same name as the key (in most cases i do) i can assign it through this way quite easily. this will cut down so much clutter in those high-settings mods xD.
I seen your implementation of hasOwnProperty, I didn't even know that was a thing so it was pretty neat seeing it used.
I use switches for a few reasons. Sometimes I don't have a variable with the same name, and sometimes I do more than just assign the value.
If you like to work in stages (init, load, parse, process, unload) then this fits fine.
I prefer to work with things on a per-case basis, not because I want to but because it helps debug situations where input/output is unexpected. And that happens a lot.
Mod-Tsun
Also 5.19 is ready, put a lot of time in to fixing some bugs so hopefully I'll minimize issues.
Upload in a bit.
EDIT2:
Uploaded.