Example Mod will load, but not trigger events

Continuing the discussion from Complete: method not triggering at all in Events:

I am new to modding and wanted to see what the example files included with Game Dev Tycoon looked like in the actual game. I made a package.json file forexamples.js and moved the entire example package as is into the mods folder so it would launch as a mod. I’m able to load the mod, but I don’t know if it’s working properly.
I set isRandom: false to force the example event with the kid spying to launch as soon as the first game is being developed, but nothing happens. I’ve tried it with no changes, leaving ‘isRandom: true’, but that never launches even by the time I move into the first office.
var myRandomEvent = { id: eventId, isRandom: false, //if you want to test this event, you can set this to false and it will trigger during dev. of the first game. maxTriggers: 1, trigger: function (company) { //only in first office and only while a game is in development. //most events that fire during game-dev work better if they don't fire right at the start or right at the end, that's why we use isGameProgressBetween return company.currentLevel == 1 && company.isGameProgressBetween(0.2, 0.9); },

You are defining your myRandomEvent mod but you also need to add it to the game via a GDT.addEvent(myRandomEvent) call.

See last line in:

What I posted was a snippet from the example.js to show that I changed the isRandom to false. I set up example.js in its entirety as a mod and tried to use it with no changes except that isRandom. The event never triggers.
This is the entire file.

var Examples = {};
(function () {
Examples.addTopic = function () {
GDT.addTopics([
{
id: “Assassin”,
name: “Assassin”.localize(“game topic”),
genreWeightings: [1, 1, 1, .6, .6, .6],
audienceWeightings: [0.6, 0.8, 1]
}
]);
};

Examples.addPlatform = function () {
    var icon = GDT.getRelativePath() + '/examples/img/greenheartOne.png';
    GDT.addPlatform(
        {
            id: 'Greenheart One',
            name: 'Greenheart One',
            company: 'Greenheart Games',
            startAmount: 0.15,
            unitsSold: 0.358,
            licencePrize: 5000,
            published: '1/3/4',
            platformRetireDate: '4/6/2',
            developmentCosts: 10000,
            genreWeightings: [0.9, 1, 1, 0.9, 1, 0.7],
            audienceWeightings: [0.9, 1, 0.8],
            techLevel: 1,
            iconUri: icon,
            events: [
                {
                    id: '10537DA1-58F1-4F23-8854-F1E2621933BF',
                    date: '1/2/1',
                    getNotification: function (company) {
                        return new Notification({
                            header: "Industry News".localize(),
                            text: "Coming out of nowhere a company called Greenheart Games has announced that it will publish a new game console called the Greenheart One {0}.".localize().format(General.getETADescription('1/2/1', '1/3/4')),
                            image: icon
                        });
                    }
                }
            ]
        });
};
Examples.addEvent = function () {
    /*
    example event:
    when does it fire: random event, only in the first office when a game is in development
    what happens: neighbours kid spies on game dev, resulting in several options.
    */
    var eventId = "F413351E-2108-4967-A989-A7E98D4DEED5";//any string, but needs to be globally unique
    var myRandomEvent = {
        id: eventId,
        isRandom: false, //if you want to test this event, you can set this to false and it will trigger during dev. of the first game.
        maxTriggers: 1,
        trigger: function (company) {
            //only in first office and only while a game is in development.
            //most events that fire during game-dev work better if they don't fire right at the start or right at the end, that's why we use isGameProgressBetween
            return company.currentLevel == 1 && company.isGameProgressBetween(0.2, 0.9);
        },
        //because we dynamically create the notification every time the event triggers, we use getNotification
        getNotification: function (company) {
            var game = company.currentGame;
            var msg = "It seems that kids in the neighbourhood have started chatting about your upcoming game {0}. Rumour has it, that Billy, your neighbours kid, snuck into the garage and spied on some of the design papers.{n}How he managed to do this is a mystery. You could swear you were sitting in the garage the entire time!\nHow do you want to react?\n\nYou could talk to the parents to get him punished, ignore the incident or maybe invite some of the neighbours over to show them more of the game."
                .localize().format(game.title);
            //notice how we break up the story in two screens by using {n}. This creates a better flow than having one longer block of text.
            //Also, since this is a story with multiple options and the buttons can only hold a small amount of text, we explain the options beforehand.
            //the chatting among kids, creates a bit of hype.
            //since the event isn't delayed we can do this directly on the company, otherwise we could call adjustHype() on the notification object to schedule the effect with the notification.
            company.adjustHype(5 + 10 * company.getRandom());//increase hype between 5 and 15.
            return new Notification({
                sourceId: eventId,//this is important, otherwise nothing will happen when the player selects an option.
                header: "Billy, the kid".localize(),//granted, this is a silly header.
                text: msg,
                options: ["Talk to parents".localize(), "Ignore incident".localize(), "Invite over".localize()]//maximum of three choices
            });
        },
        complete: function (decision) {
            //decision is a number and will correspond to the index of the option that was chosen.
            //0=talk to parents, 1=ignore incident, 2=invite over
            //it's best if every decision has a different outcome
            var company = GameManager.company;//we fetch the company object for use later.
            if (decision === 0) {//talk to parents
                //we create a new, simple notification to tell the outcome. no sourceId or options are necessary this time.
                var n = new Notification({
                    header: "Billy, the kid".localize(),//keep the header consistent with the prior part of the story
                    text: "You talk to the parents about Billy's actions and they promise it won't happen again.".localize()
                });
                n.adjustHype(5 + 10 * company.getRandom());//increase hype between 5 and 15.
                company.activeNotifications.addRange(n.split()); //since this notificaton should be shown immediately (not one second later) we insert it into activeNotifications. calling .split() ist just good practice in case we use {n} inside the notification.
                return;
            }
            if (decision === 1) {//ignore incident
                //nothing happens at first, but in a few weeks Billy again breaks in...
                var n = new Notification({
                    header: "Vanished documents".localize(),
                    text: "You were working on some intricate design documents the other day but now you can't find them anymore. Small foot prints on the floor suggest that someone might have taken them.\nUnfortunately you have to recreate the documents (-500 cr.) - This might have been Billy's work".localize(),
                    weeksUntilFired: 1 + 2 * company.getRandom()
                });
                n.adjustCash(-500, "restoring documents");
                company.notifications.push(n);//this notification isn't shown immediately so we add it to the normal company.notifications array.
                return;
            }
            if (decision === 2) {//invite him over
                var n = new Notification({
                    header: "Billy, the kid".localize(),//keep the header consistent with the prior part of the story
                    text: "You invite Billy, his parents and a couple of other interested neighbours over and show them the game in-progress. The kids are super-excited and for weeks you hear them talk about it afterwards.".localize()
                });
                n.adjustHype(15 + 25 * company.getRandom());//increase hype between 15 and 40
                company.activeNotifications.addRange(n.split()); //since this notificaton should be shown immediately (not one second later) we insert it into activeNotifications. calling .split() ist just good practice in case we use {n} inside the notification.
                return;
            }
        }
    };
    GDT.addEvent(myRandomEvent);
};
Examples.addResearch = function () {
    GDT.addResearchItem(
    {
        id: "Swift Loading", //Must be unique
        name: "Swift loading".localize(), //Display name
        v: 4, //Tech level
        canResearch: function (company) {
            return LevelCalculator.getMissionLevel('Level Design') > 5 //The "Level Design" level has to be at least 6
        },
        category: "Level Design",
        categoryDisplayName: "Level Design".localize()
    });
};

})();

And this is the package.json I set up to run it.

{ "id": "Example", "name": "Example Mod", "version": "0.1.0", "author":"support@greenheartgames.com", "description": "Example Mod", "url":"https://github.com/greenheartgames/gdt-modAPI", "main": "./examples.js", "dependencies": { "gdt-modAPI": "0.1.x" }, "image": "image.png" }

I tried several times to make make the post format properly, but it’s simply not doing it.

Do you ever call the functions you are defining?

The method Examples.addEvent(); isn’t executed so your custom event is never added to the game.

Just add Examples.addEvent(); at the end of your examples.js file and it should work.

1 Like

I see. So this is just defining those functions but never calling them. Thanks for your patience in explaining it to me.

You can see that the calls to those methods are commented out in the main entry point for the mod API:

We wanted to include some examples in the mod API itself but obviously don’t want those examples to be actually active in the game just because someone activates the mod API. Hope this makes it clearer.

Thanks. I just assumed that those calls were in the example.js and that I was somehow not seeing them.