1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

My Mod won't load through $INIT$

Discussion in 'Help' started by DrZombi, Aug 23, 2016.

  1. DrZombi

    DrZombi Casual Client Content Creator

    Joined:
    Jul 10, 2016
    Messages:
    144
    Likes Received:
    45
    Hi community,

    I'm trying to create my own Mod to add some triggers to DialogueActions but after building the file, I can't load it through the $INIT$ folder. I can load the Mod through the GUI and it works, but if I put it in the $INIT$ folder, even at the end of the file, I'll always end up with a "Mod Loading Failed" Error...

    I suspected a delay needed between the loading of DA and my mod but I tried the same loading sequence with Coli's Mod CustomAutomation (from which my mod is derivated), and there is no problem to load his mod just after DA through the $INIT$ folder.

    So I'm very frustrated because the mod does work when loaded through the GUI but I can't figure out why it won't load at startup. I'm posting here in hope that experienced modders with a good knowledge of the SDT/Loader Architecture will know what could be the problem.

    In case you need it, here is the code of my mod. I removed the specific functions I created to keep it short because I think that this is not relevant to troubleshoot this problem but if you need my complete code, no problem, just ask:

    Code:
    package
    {
        import flash.display.MovieClip;
        import flash.utils.Dictionary;
    
        public dynamic class MoreTriggers extends MovieClip
        {
           
            private const API_DA:String = "DialogueActions";
            public var register:Function;
            private var _apiDict:Dictionary = new Dictionary();
            public var dialogueAPI:Dictionary;
            private var DAFound:Boolean = false;
            public var main;
            public var g;
    
            public function initl(l) : void
            {
                main = l;
                g = l.g;
    
                _apiDict["apiRegister"] = detectAPI;
                l.registerAPI("DA_Extension", _apiDict, true);
                main.unloadMod();
            }
           
            private function detectAPI(apiName:String, apiDict:Dictionary) : void
            {
                if(apiName == API_DA)
                    doStuff();
            }
           
            public function apiNotify() : void
            {
                doStuff();
            }
           
            private function doStuff() : void{
               
                dialogueAPI = main.getAPI(API_DA);
    
                if (!DAFound){
                    if (dialogueAPI == null){
                        main.updateStatusCol("DialogueActions API not found!","#FF0000");
                        return;
                    } else {
                        DAFound = true;
                        if (!addTriggers()){
                            main.updateStatusCol("Dictionary Load Failed","#FF0000");
                            main.unloadMod();                       
                        } else {
                            main.updateStatusCol("MoreTriggers loaded successfully","#00FF00");
                        }
                    }
                }
            }
           
            private function addTriggers():Boolean{
               
                register = dialogueAPI["registerTrigger"].getFunction();
               
                register("TONGUE_ADD", 0, tongueAdd, this, []);
                register("TONGUE_REMOVE", 0, tongueRemove, this, []);
                register("UPDATE_RESISTANCE", 1, UpdateRes, this, []);
                register("HIDE_HIS_LEFT_ARM", 0, hideHisLeftArm, this, []);
                register("SHOW_HIS_LEFT_ARM", 0, showHisLeftArm, this, []);
                register("TOGGLE_LOADER_ARM", 1, toggleLoaderArm, this, []);
                register("TOGGLE_NIPPLES", 1, toggleNipples, this, []);
               
                return true;
            }
    
    ...
    
     
  2. stuntcock

    stuntcock Club Regular Staff Member Moderator

    Joined:
    Jun 5, 2012
    Messages:
    1,514
    Likes Received:
    352
    This code throws runtime exceptions due to missing functions. Please post the complete code (or a compiled mod) so that we can bypass the surface-level stuff and troubleshoot the mod interactions.
     
  3. DrZombi

    DrZombi Casual Client Content Creator

    Joined:
    Jul 10, 2016
    Messages:
    144
    Likes Received:
    45
    Here you are,

    The .as and the .swf. For now I've still not found anything relevant through my searches around the forum and guides... Many thanks for having a look at it, that's greatly appreciated :)

    For your information, I use FlashDevelop (latest version) in which I created a new AS3 Project for Flash 11 (which is the flash_sa I use for SDT).

    EDIT: I forgot to mention it but if you want to have a deeper comprehension of what I'm trying to do (for testing purposes for example), you may find the detailed use of each trigger in the posts I made when I originally added those triggers directly into DA: Pim_gd's Mods - DialogueActions v4.03 (22 Aug 2016)

    But if you really need to test the triggers, you can just throw them randomly at the start of any dialogue, they have almost all easy to spot/immediate effects.
     

    Attached Files:

    Last edited: Aug 23, 2016
  4. stuntcock

    stuntcock Club Regular Staff Member Moderator

    Joined:
    Jun 5, 2012
    Messages:
    1,514
    Likes Received:
    352
    I'm unable to reproduce this problem.

    I've placed MoreTriggers.swf immediately after SDTDialogueActionsv4.02.swf in the Mods\$INIT$\Mods.txt file. Tried again with pim_gd's new 4.03 file. Same result: no loading error.

    Tried with your 4.03 and 4.04 files; got an error. This is as expected, since I was indirectly trying to register the new triggers twice.

    I can get it to crash (undefined reference exception) if I try to load MoreTriggers.swf before dialogueActions.

    There is a three-second timeout for the loading of a Character Folder (such as $INIT$). It's possible that you're encountering this error simply because your $INIT$ folder is heavily populated. Please review the Mods\$INIT$\Mods.txt file and comment-out some of the less crucial items by adding a semicolon at the beginning of each line. If the test seems conclusive (i.e. the error goes away), then it would be prudent to review the file more carefully; some of those temporary exclusions might become permanent. The goal would be to reduce your average loading-time until it's short enough to avoid any "Mod Loading Failed" errors.

    The "Mod Loading Failed" error can also be triggered by a missing or renamed SWF file - often a vanilla import. That's probably not the culprit in this case, but it wouldn't hurt to do a few "clean" restarts (without loading the MoreTriggers mod in any way) just to be certain that the error doesn't appear spontaneously.

    In case you're new to Flash debugging: if you click the "Dismiss All" button after seeing an exception, then the debugger app will silently discard all subsequent exception messages for the remainder of the app's lifespan. This behavior persists even if you restart Loader.swf via the File menu. Hence, you might be encountering an actual exception, with the "Mod Loading Failed" notification being a secondary consequence. If you've done the "Dismiss All" thing, then you must close down the Flash Player projector window and reopen it (and then open Loader.swf) in order to proceed with debugging.

    P.S. If you're not sure what I mean by "debugger" then you should download the Flash Player Projector content debugger and use it whenever you're testing any mods.

    Not a problem. I usually rely on the lightweight compiler (because it's "too simple to fail") and it's true that the lightweight compiler produces a smaller version of MoreTriggers.swf (1.39 kB vs 2.44 kB). However, I doubt that the problem here is related to your code or the structure of your mod file. It's probably something environmental.
     
  5. Pim_gd

    Pim_gd Swell Supporter

    Joined:
    Jan 25, 2013
    Messages:
    717
    Likes Received:
    44
    Code:
            public function registerTrigger(name:String, argumentCount:int, callback:FunctionObject):void {
                if (!hasTrigger(name, argumentCount)) {
                    var triggerArray:Array = registeredTriggers[name];
                    if (triggerArray == null) {
                        triggerArray = new Array();
                        registeredTriggers[name] = triggerArray;
                    }
                    triggerArray[argumentCount] = callback;
                } else {
                    throw new Error("IllegalStateException: Already have such a trigger ["+name+"] with "+argumentCount+" arguments.");
                }
            }
    
    DialogueActions will throw an error if the trigger cannot be registered. The debugger should be able to tell you about this error - failing that, you can try wrapping everything in try catch:

    Code:
    try {
     ... 
    } catch (e:Error) { 
     main.updateStatusCol("Error: "+e.message+", "+e.errorID, "#FF0000");
    }
    
    Oh and uhhh

    Code:
    main.main.updateStatusCol("Dictionary Load Failed","#FF0000");
    
    That's not gonna work. "main.main" doesn't exist. Try just using "main".
     
  6. DrZombi

    DrZombi Casual Client Content Creator

    Joined:
    Jul 10, 2016
    Messages:
    144
    Likes Received:
    45
    @stuntcock :

    Which is both a pleasure to hear and a total WTF lol ^^

    I agree that this could be a problem but in this case why could I load Colin's Mod without any problem in the same conditions when it's a far bigger mod ? The truth is probably elsewhere, but I do keep a note on that 3 seconds time-out !

    Thanks ! I am totally new to flash and I will definitely have a look at this, thanks !

    Well... Did you regenerate totally my mod with the compiler or did you test directly the .swf I posted here ?
    Because I just recompiled the mod with the Lightweight compiler and now it loads at startup with no problem ! (And I did not have to comment out other mods by the way). I really wonder what is the difference between the 2 generated codes but I'll stick to the lightweight compiler from now on !!

    Many thanks for pointing this out, I did download this compiler and tested it on another mod but I would never have thought about this possibility !!

    @Pim_gd :

    Ah ah yes ! The classical copy/paste stupidity ! I did spot that when I pasted the code in the codebox of the OP and I forgot to correct it in the file┬Ębefore uploading it to you.
    Don't worry it is corrected :)

    That seems highly not probable but could it be this error which caused the mod to not load well at startup ? I'll retry a compilation with flashdevelop without this error just to see...
    ...
    And it still fails. So it is really a compilation difference. That's crazy but OK, good enough for me :)
     
  7. DrZombi

    DrZombi Casual Client Content Creator

    Joined:
    Jul 10, 2016
    Messages:
    144
    Likes Received:
    45
    In case anyone is interested and/or have the same problem, I finally solved it and am now able to compile with Flash Develop and the Mod loads well at startup in the $INIT$ folder.

    What have I done ? I just downloaded the whole source of Dialogue Actions, renamed the project and replaced the files in src with my .as classes. And now it runs perfectly. So the problem was absolutely not in the code, but rather in the way I created my project in Flash Develop.

    (I tried to compare my project and the DA project but in every menu I went, I never found out where the difference were. That's why I finally replaced everything except for the project file. And it works :tongue::grin:)
     
    fleet likes this.