Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

legality_export reports as a string, not an integer/number

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4726
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

legality_export reports as a string, not an integer/number

Post by phkb »

It appears the legality_export is being referred to as a string. I did a quick run through using this code:

Code: Select all

this.$myFunction = function () {
    var market = player.ship.dockedStation.market;
    for (prop in market) {
        log(this.name, "type " + Object.prototype.toString.call(market[prop].legality_export));
    }
}
and the result was

Code: Select all

type [object String]
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2311
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: legality_export reports as a string, not an integer/numb

Post by Wildeblood »

This is the problem you've been trying to interest me in, that I've been studiously ignoring? You say because it's a string, not an integer, when used as a boolean "0" tests as true where 0 would test as false?

I ignored your PM the other day because I looked at that function of yours and didn't think it was testing what you think it is testing. OTOH, if your function there is right it implies I've forgotten even more than I thought I had, which is a lot.

So either way I'm not game to change the script in Undocumented Launch until someone spoon feeds me the exact fix necessary. :oops:
"So anti-globalist, he's practically a flat-earther."
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4726
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: legality_export reports as a string, not an integer/numb

Post by phkb »

I understand if you're not interested. You don't have to be! It just seems like a bug. It might not be (I'm not 100% sure), but if it is, I don't like bugs. Bugs must be squished. With extreme prejudice. (Take that, evil bug).

And yes, doing a boolean test of a string containing "0", "1" or "2" all returns true.
User avatar
Lone_Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 546
Joined: Wed Aug 08, 2007 10:59 pm
Location: Netherlands

Re: legality_export reports as a string, not an integer/numb

Post by Lone_Wolf »

phkb,

try typeof market[prop].legality_export instead of Object.prototype.toString.call(market[prop].legality_export))
OS : Arch Linux 64-bit - rolling release

OXPs : My user page

Retired, reachable at [email protected]
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2311
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: legality_export reports as a string, not an integer/numb

Post by Wildeblood »

Lone_Wolf wrote:
phkb,

try typeof market[prop].legality_export
instead of Object.prototype.toString.call(market[prop].legality_export))
Yes, that's what I thought, too. But as I said, I'm too long out of it to be sure.
"So anti-globalist, he's practically a flat-earther."
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: legality_export reports as a string, not an integer/numb

Post by cim »

Where there's a very direct translation from plist to core structure to JS structure like that, everything is a string, and you should use parseInt or parseFloat if it needs to be read as a number.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4726
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: legality_export reports as a string, not an integer/numb

Post by phkb »

cim wrote:
Where there's a very direct translation from plist to core structure to JS structure like that, everything is a string
Ah! That explains it! Thanks, cim!
Post Reply