javascript version

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
Chimrod
Average
Average
Posts: 10
Joined: Wed May 27, 2015 7:31 am

javascript version

Post by Chimrod »

Hello,

I'm quite surprised to see comon javascript function not working : Array.filter, Array.forEach, …

What is the java(ecma) script version used in oolite ? The wiki does not specify it.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6682
Joined: Wed Feb 28, 2007 7:54 am

Re: javascript version

Post by another_commander »

This is what the Debug Console has to say about it on Windows:
Image

Edit to add: Also, at least array.forEach seems to work fine here (quick example randomly picked from the net):
Image
Chimrod
Average
Average
Posts: 10
Joined: Wed May 27, 2015 7:31 am

Re: javascript version

Post by Chimrod »

Thanks for your answer, I was getting crazy with this !

I was used to call filter, forEach with this syntax :

Code: Select all

arr.filter(function(item) {
    return …;
});
which seems works fine in a browser, but does not work in oolite.

And inded the filter, forEach require actualy a callback function with arity 3 : element, index, and a reference to the array. This code exemple works :

Code: Select all

    var stations = system.stations.filter( function(el, idx, arr) {
        player.consoleMessage("Found the station " + el.name + "(" + idx + ")");
        return el.allegiance === "neutral" || el.allegiance === "galcop" || el.allegiance === "chaotic";
    });
Post Reply