Making researches as a group in mod-api? (2D Graphics v1, v2, v3 etc.)

I have seen the game using group: “group” for that, but if I use it in my mod (No Ultimate-Lib), it crashes the game, saying lines that contain that have an error. So, any help on that?

Anyone?

I don’t know I’m not a modder maybe some other forum member’s know?

thenwhydidyouevenreply
anyways, @FireChaos, more info pl0x

2 Likes

Like? I mean something like this:

group = “test”;
        GDT.addResearchItem(
        {
            id : “test11”,
            name : “Worse”.localize(),
            v : 6,
            canResearch : function (company) {
                return LevelCalculator.getMissionLevel(“Engine”) > 2
            },
            category : “Engine”,
            categoryDisplayName : “Engine”.localize()
            group : group,
        });
        GDT.addResearchItem(
        {
            id : “test1”,
            name : “Better”.localize(),
            v : 8,
            canResearch : function (company) {
                return LevelCalculator.getMissionLevel(“Engine”) > 3
            },
            category : “Engine”,
            categoryDisplayName : “Engine”.localize()
            group : group,
        });

I think it is the extra , after group.

the thing is that it is not working. it just says that the line containing the group is an error.

… Try removing the ,

Don’t you think I tried it? XD Same error, just made sure.

Ok, so I’m going to give you some basic Javascript revision here.

These things inside the { } are called object literals. They are a way to create objects, which are basically a way to make a group of related variables together. Each variable (called a property) inside the object literal needs to be written as:

name: <value>

So if we wanted to have a property called age, with a value of 21 inside our object, we would write:

var ourObject = {
  age: 21
};

But having an object with just one property is a bit of a waste. In the previous example, we could have done:

var age = 21;

Which would have been easier to read and use (age instead of ourObject.age).

So the real strength of objects is in allowing us to group a bunch of properties (and more advanced, other things like functions) together. To put multiple things together, we just seperate each with a comma.

var person = {
    age: 21,
    name: "Random Dude",
    heightInCm: 180
};

The important to note as far as syntax goes here, is that commas are needed after every property that has another one after it needs a comma after it. However, the last one must not have a comma after it, as a comma tells javascript to expect another property, basically.

Looking at your example, the problem is here:

GDT.addResearchItem(
        {
            // Lots of stuff
            categoryDisplayName : “Engine”.localize() // Add a comma at the end here
            group : group , // Don’t put a comma here
        });

A fixed example looks like:

GDT.addResearchItem(
        {
            // Lots of stuff
            categoryDisplayName : “Engine”.localize(), // Add a comma at the end here
            group : group // Don’t put a comma here
        });

4 Likes

Oh yeah, this should do it, I hope. Dude, you’re just amazing. Try making your own mod!

Macha, you are my new hero. It works. Can’t believe I missed a comma there. I suppose i can add consolePart the same way.

http://forum.greenheartgames.com/t/making-researches-as-a-group-in-mod-api-2d-graphics-v1-v2-v3-etc/14086/11?u=macha

http://forum.greenheartgames.com/t/wip-platform-randomiser-alpha-0-0-5/9021

:stuck_out_tongue:

1 Like

Oh… XD Fail. Try updating it using the Steam Workshop

Also done :stuck_out_tongue:

1 Like

This topic was automatically closed after 24 hours. New replies are no longer allowed.