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

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

Moderators: another_commander, winston

Post Reply
dybal
Competent
Competent
Posts: 48
Joined: Mon Feb 10, 2020 12:47 pm
Location: São Paulo, Brasil

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

Post 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!

User avatar
phkb
Commodore
Commodore
Posts: 2505
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

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

Post 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";

dybal
Competent
Competent
Posts: 48
Joined: Mon Feb 10, 2020 12:47 pm
Location: São Paulo, Brasil

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

Post 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.

User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 302
Joined: Mon May 30, 2016 3:54 am

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

Post 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
Trying to survive behind the controls of a Caduceus Psi XT in Alpha test :lol:

dybal
Competent
Competent
Posts: 48
Joined: Mon Feb 10, 2020 12:47 pm
Location: São Paulo, Brasil

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

Post 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'])

another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 5451
Joined: Wed Feb 28, 2007 7:54 am

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

Post by another_commander »

Try expandDescription("[commodity-name liquor_wines]").

User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 302
Joined: Mon May 30, 2016 3:54 am

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

Post 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:
Last edited by montana05 on Thu Mar 19, 2020 2:12 pm, edited 2 times in total.
Trying to survive behind the controls of a Caduceus Psi XT in Alpha test :lol:

dybal
Competent
Competent
Posts: 48
Joined: Mon Feb 10, 2020 12:47 pm
Location: São Paulo, Brasil

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

Post 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

Post Reply