Accessing a specific value from an array with randomized values

So, another question now, you see, when the GRID lab research is completed, it is pushed to the company.researchCompleted array. So, I’m making an event with the trigger which searches in that array that specific lab research, so it checks if it’s there to execute the rest. The problem is, that the array is randomized, thanks to the user’s choices, he may research something else first. I tried to make a for loop, which keeps checking until the i is equal to company.researchCompleted.length . But as I see, normal researches go there as well. So, any other ways?

What I’m trying to do: Make an event’s trigger to check if the Codename: GRID has been researched.

So… the way you did doesn’t work?

1 Like

You know, that array has mixed stuff.

I know what array is.
I hope.
It’s like
[1, 2, 69] etc.

Can’t you put GameManager.company.researchCompleted.indexOf(Research.grid) in the trigger function of the event?

2 Likes

I have defined as a global variable on the top of the file:

var company = GameManager.company

The trigger doesn’t show errors.

To use pure JavaScript, use a for loop.

for (var value in GameManager.company.researchCompleted) { 
     // Value is the content of the currently selected index.
}
1 Like

So, I just put the value, which is contained in that array? Cool, you learn something every day.
Thanks Stian! :smile:

No problem!

1 Like

You could also use a filter:

var foundItem = GameManager.company.researchCompleted.filter(function (item) {
       return item.id === "ID_YOU_WANT";
});
1 Like

Thanks as well, but I’m gonna try Stian’s code first. Seems a bit easier, but i’ll try yours as well, but seems more advanced.

I’m using pure JavaScript, I would recommend kristof’s code.

Also, its a lot faster. The one Kristof is suggesting.

1 Like

I know that GDT isn’t a pure website at all, never knew about the in thingy.

Excuse me? What do you mean by GDT being a website?

1 Like

It runs in an offline html webpage, right?

It’s a html5 game, that uses node.js, based on the chronium webkit that runs html 5 and nodejs without the use of a normal browser, so yeah technically it’s an offline website.

1 Like