Am I missing something for modding?

So, this is my first ever mod, it’s really simple but I seem to be doing something wrong, I followed the instructions here ( https://github.com/greenheartgames/gdt-modAPI/wiki/Advanced-Modding#changing-game-code-behavior ) to patch a function. Here’s the code so far:

var originalMethod = b.finishCurrentMission;
var bar = function(){
   staff.forEach(function(){
	technologyFactor += 5
	designFactor += 5

originalMethod();
})
}
b.finishCurrentMission = bar;
};

It gives me an error on launch saying that “b is not defined”. I assume this meant the “b.” part of the function is not calling/operating correctly. I am a bit of a novice here so any help would be much appreciated.

Also, my JSON package file is working fine. The game recognizes my mod.

Ok i assume this is a mod that let’s you have more technology and design per staff member, when you finished your current mission? (That’s how i see it from my perspective lol :stuck_out_tongue:)

Also, did you try to remove the b. part? (Just something that flew in my mind)

You are correct. It’s very basic at the moment.
I have tried a few different changes like that, but nothing really helped. I therefore assume it’s more fundamental in the way I’m trying to actually reference the module (which is called b.finishCurrentMission in the sourcecode, but I don’t know whether b. actually does something active or is just a variable name).

Even stranger: when I remove all the [b.]'s; it still says: “Uncaught ReferenceError: b is not defined” for js:2 (line2)

The ‘b’ you are using is a variable used in the source code of the game. As your mod has no idea what ‘b’ means (as it is not using the variables from the source code), you need to replace it with what ‘b’ represents, which is something along the lines of GameManager.

EDIT: From what I can see from the game’s source code, b does actually represent GameManager. Try replacing ‘b’ with GameManager.

3 Likes

Thank you very much. That’s resolved that issue. It’s now complaining about the JSON package, but it seems that the js file is working, cheers guys.

EDIT: Never mind, it’s still doing it

EDIT1: Ok, so I fixed that and the JSON I think, it’s now saying: “Uncaught SyntaxError: Unexpected end of input … [in line 0]” Any ideas about that?

1 Like

That’s most likely caused by inadequate formatting, i.e. you haven’t closed off your functions properly. Is the code you pasted above the entire code, or just a segment?

1 Like

That was the full code, but I just realized that I started the whole thing with “(function(){” which makes no sense. I’ve amended it and the program actually runs! (horay) but the stops halfway through saying that the “Foreach” thing is wrong. I think I can fix that though. Thank you so much for your help, I’ll publish the full code when it’s working 100%.

It makes perfect sense to start your code with (function(){, it makes sure that your code does not interfere with the actual game. You just have to remember to close it.

Thanks for your help everyone, the finished code is quite long, so if your are desperate to see it, find it the mod folder here: http://steamcommunity.com/sharedfiles/filedetails/?id=529321951