Page 1 of 1

How to get the displayName for a commodity in the Main Station Market?

Posted: Wed Mar 18, 2020 4:49 pm
by dybal
Greetings!

Prior to 1.81, the objects in system.mainStation.market had a property displayName.

This is the object for I get for liquor_wines from system.mainStation.market in 1.88:

Code: Select all

{
 "quantity_random":"0.38",
  "capacity":127,
  "key":"liquor_wines",
  "trumble_opinion":"0.95",
  "quantity":38,
  "classes":["oolite-consumer","oolite-edible","oolite-farming"],
  "quantity_average":"20",
  "quantity_unit":"0",
  "price_random":"0.05",
  "price_economic":"0.24",
  "name":"[commodity-name liquor_wines]",
  "legality_import":"0",
  "peak_export":"7",
  "peak_import":"0",
  "sort_order":"500",
  "legality_export":"0",
  "price_average":"291",
  "quantity_economic":"0.88",
  "price":224
  }
 
How can I get the displayName for a Main Station Market commodity in the current version? I didn't find anything in the JavaScript Reference Object Model!

Re: How to get the displayName for a commodity in the Main Station Market?

Posted: Wed Mar 18, 2020 8:45 pm
by phkb
dybal wrote: Wed Mar 18, 2020 4:49 pm

Code: Select all

"name":"[commodity-name liquor_wines]"
This line is key. If you look in the "descriptions.plist" file, you should find a line like this:

Code: Select all

	"commodity-name liquor_wines"	= "Liquor/Wines";

Re: How to get the displayName for a commodity in the Main Station Market?

Posted: Thu Mar 19, 2020 11:49 am
by dybal
phkb wrote: Wed Mar 18, 2020 8:45 pm
dybal wrote: Wed Mar 18, 2020 4:49 pm

Code: Select all

"name":"[commodity-name liquor_wines]"
This line is key. If you look in the "descriptions.plist" file, you should find a line like this:

Code: Select all

	"commodity-name liquor_wines"	= "Liquor/Wines";
Yep, _I_ can look for the file in, probably in the Resources/Config directory, and look it up... but how do I make _the OXP Javascript code_ do that?

I didn't find any way to access those definitions from the Javascript code... if it can't be done, I have two options:

- display the commodity name: liquor_wines will be displayed as "liquor_wines" (or do some mod of it, like substituting " " for "_" and capitalizing first letters; "Liquor Wines")
- hardcode the commodity names (that's how HyperCargo is today), and break forward compatibility with OXP created commodities like Witchfire Whisky and Quirium Fuel.

Re: How to get the displayName for a commodity in the Main Station Market?

Posted: Thu Mar 19, 2020 12:33 pm
by montana05
dybal wrote: Wed Mar 18, 2020 4:49 pm
Yep, _I_ can look for the file in, probably in the Resources/Config directory, and look it up... but how do I make _the OXP Javascript code_ do that?
Not sure if it works but you can try

Code: Select all

expandDescription[liquor_wines]
after slicing the name a bit

Re: How to get the displayName for a commodity in the Main Station Market?

Posted: Thu Mar 19, 2020 1:03 pm
by dybal
montana05 wrote: Thu Mar 19, 2020 12:33 pm
dybal wrote: Wed Mar 18, 2020 4:49 pm
Yep, _I_ can look for the file in, probably in the Resources/Config directory, and look it up... but how do I make _the OXP Javascript code_ do that?
Not sure if it works but you can try

Code: Select all

expandDescription[liquor_wines]
after slicing the name a bit
It didn't work... tried with:

Code: Select all

expandDescription['liquor_wines']
expandDescription['[commodity-name liquor_wines]']
expandDescription['commodity-name liquor_wines']
All return undefined ('[commodity-name liquor_wines]' is the content of system.mainStation.market['liquor_wines'])

Re: How to get the displayName for a commodity in the Main Station Market?

Posted: Thu Mar 19, 2020 1:09 pm
by another_commander
Try expandDescription("[commodity-name liquor_wines]").

Re: How to get the displayName for a commodity in the Main Station Market?

Posted: Thu Mar 19, 2020 1:15 pm
by montana05
dybal wrote: Thu Mar 19, 2020 1:03 pm
It didn't work... tried with:

Code: Select all

expandDescription['liquor_wines']
expandDescription['[commodity-name liquor_wines]']
expandDescription['commodity-name liquor_wines']
All return undefined ('[commodity-name liquor_wines]' is the content of system.mainStation.market['liquor_wines'])
I am using

Code: Select all

var CrewName = (CrewRank + " " + expandDescription("[nom]"));
and it's working well, forget about the commodity-name, it needs to be the exact name.

EDIT:
My bad, I didn't see A_C message before, obviously commodity-name is part of the exact name. Next time I better claim my computer back from my kids before posting detailed advice. :oops:

Re: How to get the displayName for a commodity in the Main Station Market?

Posted: Thu Mar 19, 2020 2:02 pm
by dybal
another_commander wrote: Thu Mar 19, 2020 1:09 pm
Try expandDescription("[commodity-name liquor_wines]").
That worked! (my bad, should have tried a function call instead of an object property...)

Thanks a lot, folks!

Now I can get rid of the hardcoded descriptions in HyperCargo :D