Deciphering Javascipt/Legacy Script

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

Moderators: another_commander, winston

Post Reply
User avatar
Cholmondely
Wiki Wizard
Wiki Wizard
Posts: 692
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of Her Most Britannic Majesty
Contact:

Deciphering Javascipt/Legacy Script

Post by Cholmondely »

Whilst the Wiki does have some pages on coding and writing OXPs, I find most of it incomprehensible.

For example, trying to decipher this:

Code: Select all

"use strict";

this.name = "wildships-market";
this.author = "spara";

this.$originalResearch = {
	"food" : [0, 0, 17, -2, -2, 2, 1, 1, 0],
	"textiles" : [0, 0, 18, -1, -1, 3, 3, 3, 0],
	"radioactives" : [0, 0, 85, -3, -3, 5, 7, 7, 0],
	"slaves" : [0, 0, 40, -5, -5, 0, 31, 31, 0],
	"liquor_wines" : [0, 0, 90, -5, -5, 251, 15, 15, 0],
	"luxuries" : [0, 0, 170, 8, 8, 10, 3, 3, 0],
	"narcotics" : [0, 0, 245, 29, 8, 0, 10, 120, 0],
	"computers" : [0, 0, 170, 14, 14, 60, 3, 3, 0],
	"machinery" : [0, 0, 130, 6, 6, 40, 7, 7, 0],
	"alloys" : [0, 0, 85, 1, 1, 30, 31, 31, 0],
	"firearms" : [0, 0, 85, 13, 13, 5, 7, 7, 0],
	"furs" : [0, 0, 80, -9, -9, 100, 63, 63, 0],
	"minerals" : [0, 0, 32, -1, -1, 60, 3, 3, 0],
	"gold" : [0, 0, 105, -1, -1, 66, 7, 7, 1],
	"platinum" : [0, 0, 190, -2, -2, 55, 31, 31, 1],
	"gem_stones" : [0, 0, 55, -1, -1, 250, 15, 15, 2],
	"alien_items" : [0, 0, 95, 15, 0, 0, 7, 0, 0]
}
This is the code for the market on one of the Kiota stations.

1) What does "use strict"; mean? Why is it there?

2) "food" : [0, 0, 17, -2, -2, 2, 1, 1, 0],
What do each of these numbers actually DO? There are 9 of them!

I've been unable to find explanations for these questions on the wiki, or scouring through this BB!
Denizen of the Dark and Dismal Deserts of Digebiti.

Milo wrote Dancing the Gavotte
User avatar
Cmdr James
Commodore
Commodore
Posts: 1319
Joined: Tue Jun 05, 2007 10:43 pm
Location: Berlin

Re: Deciphering Javascipt/Legacy Script

Post by Cmdr James »

Unless you are planning to learn javascript, you can just accept that "well written javascript generaly has use strict at the top". It is more or less a signal to the javascript system that the javascript contained has to be valid.

The commodities info is detailed here: http://wiki.alioth.net/index.php/Commodities.plist
User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 592
Joined: Mon May 30, 2016 3:54 am
Location: lurking in The Devils Triangle (G1)

Re: Deciphering Javascipt/Legacy Script

Post by montana05 »

Cholmondely wrote: Fri Apr 02, 2021 1:50 pm 1) What does "use strict"; mean? Why is it there?
Regarding "use strict" I hope this will help you a bit:

https://www.w3schools.com/js/js_strict.asp
Trying to survive behind the controls of a Caduceus Psi XT in Alpha test :lol:
User avatar
Cholmondely
Wiki Wizard
Wiki Wizard
Posts: 692
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of Her Most Britannic Majesty
Contact:

Re: Deciphering Javascipt/Legacy Script

Post by Cholmondely »

Cmdr James wrote: Fri Apr 02, 2021 6:47 pm The commodities info is detailed here: http://wiki.alioth.net/index.php/Commodities.plist
Yes, I looked at that page. That's why I started this thread. I fail to understand how it answers my second question above. If I had decades of experience in programming, I'm sure it would be obvious to me. But I don't.

And there is nothing on the page that looks like : "food" : [0, 0, 17, -2, -2, 2, 1, 1, 0],

so I don't even know if it is talking about the same thing. Is it?
Denizen of the Dark and Dismal Deserts of Digebiti.

Milo wrote Dancing the Gavotte
hiran
Dangerous
Dangerous
Posts: 77
Joined: Fri Mar 26, 2021 1:39 pm
Location: Munich, Bavaria

Re: Deciphering Javascipt/Legacy Script

Post by hiran »

Cholmondely wrote: Sun Apr 04, 2021 8:06 pm
Cmdr James wrote: Fri Apr 02, 2021 6:47 pm The commodities info is detailed here: http://wiki.alioth.net/index.php/Commodities.plist
Yes, I looked at that page. That's why I started this thread. I fail to understand how it answers my second question above. If I had decades of experience in programming, I'm sure it would be obvious to me. But I don't.

And there is nothing on the page that looks like : "food" : [0, 0, 17, -2, -2, 2, 1, 1, 0],

so I don't even know if it is talking about the same thing. Is it?
I found this part helpful:
Each market is an array of 17 commodities, each in itself an array of 10 items:

1) The name of the commodity
2) Units available at a market (this is calculated at each marketplace)
3) Price per unit at a market (this is calculated at each marketplace)
4) The base price per unit MARKET_BASE_PRICE
5) An adjustment to price based on the economy MARKET_ECO_ADJUST_PRICE
6) An adjustment to units availble based on the economy MARKET_ECO_ADJUST_QUANTITY
7) The base quantity available to a market MARKET_BASE_QUANTITY
8) A 'mask' which defines how the price varies MARKET_MASK_PRICE
9) A 'mask' which defines how the quantity varies MARKET_MASK_QUANTITY
10) The unit of quantity (0 == tons, 1 == kilos, 2 == grams)
That means you should be looking at the commodity 'food', and it should be an array of 10 values as listed on that page.
The fact that you only have 9 numbers might mean either that the key 'food' is already the first value, or that the last value is optional and therefore should have a default value.

Also the page does not mention all the values/their usage, such as the masks.
User avatar
Cholmondely
Wiki Wizard
Wiki Wizard
Posts: 692
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of Her Most Britannic Majesty
Contact:

Re: Deciphering Javascipt/Legacy Script

Post by Cholmondely »

hiran wrote: Sun Apr 04, 2021 9:30 pm
Cholmondely wrote: Sun Apr 04, 2021 8:06 pm
Cmdr James wrote: Fri Apr 02, 2021 6:47 pm The commodities info is detailed here: http://wiki.alioth.net/index.php/Commodities.plist
Yes, I looked at that page. That's why I started this thread. I fail to understand how it answers my second question above. If I had decades of experience in programming, I'm sure it would be obvious to me. But I don't.

And there is nothing on the page that looks like : "food" : [0, 0, 17, -2, -2, 2, 1, 1, 0],

so I don't even know if it is talking about the same thing. Is it?
I found this part helpful:
Each market is an array of 17 commodities, each in itself an array of 10 items:

1) The name of the commodity
2) Units available at a market (this is calculated at each marketplace)
3) Price per unit at a market (this is calculated at each marketplace)
4) The base price per unit MARKET_BASE_PRICE
5) An adjustment to price based on the economy MARKET_ECO_ADJUST_PRICE
6) An adjustment to units availble based on the economy MARKET_ECO_ADJUST_QUANTITY
7) The base quantity available to a market MARKET_BASE_QUANTITY
8) A 'mask' which defines how the price varies MARKET_MASK_PRICE
9) A 'mask' which defines how the quantity varies MARKET_MASK_QUANTITY
10) The unit of quantity (0 == tons, 1 == kilos, 2 == grams)
That means you should be looking at the commodity 'food', and it should be an array of 10 values as listed on that page.
The fact that you only have 9 numbers might mean either that the key 'food' is already the first value, or that the last value is optional and therefore should have a default value.

Also the page does not mention all the values/their usage, such as the masks.
Righty-ho!

So for: "food" : [0, 0, 17, -2, -2, 2, 1, 1, 0],

2) there are 0 Units available at a market (this is calculated at each marketplace)
3) Price per unit at a market (this is calculated at each marketplace) is 0cr
4) The base price per unit MARKET_BASE_PRICE is 17
5) adjustment to price based on the economy MARKET_ECO_ADJUST_PRICE is -2
6) adjustment to units available based on the economy MARKET_ECO_ADJUST_QUANTITY is -2
7) The base quantity available to a market MARKET_BASE_QUANTITY is 2
8) A 'mask' which defines how the price varies MARKET_MASK_PRICE is 1
9) A 'mask' which defines how the quantity varies MARKET_MASK_QUANTITY is 1
10) The unit of quantity (0 == tons, 1 == kilos, 2 == grams)[/quote] is tons

The only bit which makes sense to me is #10.

#2: Possibly there is no food for sale on a research Kiota station,

but:

#3: The price per unit of food is never 0cr.
#4: Neither is the basic price per unit 17cr.

And as regards the rest of it, my command of Ancient Chaldaean just isn't up to it, I'm afraid!
Denizen of the Dark and Dismal Deserts of Digebiti.

Milo wrote Dancing the Gavotte
User avatar
Nite Owl
Deadly
Deadly
Posts: 204
Joined: Sat Jan 20, 2018 4:08 pm
Location: In The Dark

Re: Deciphering Javascipt/Legacy Script

Post by Nite Owl »

Near the bottom of that commodities.plist page is a link to download the OOLITE COMMODITY CALCULATOR by Frame. It is an HTML page that allows you to input your own values for all of the numbers that are confusing you. It will then calculate the results and show them to you. Play around with it for awhile and it may become clearer how this out of date system works and what the numbers actually do. The formulas shown on the original commodities.plist page can be a bit confusing to those of us with a bit of a math deficiency, never was my best subject.

Note that as of Oolite v1.82 this method of calculating commodity prices and quantities has been depreciated in favor of an even more heavily math based system by Cim that gets put into a dockable's shipdata.plist. This old method is still usable however via a clever bit of scripting by Spara. Links to THAT SCRIPTING can also be found near the bottom of the commodities.plist page.

This old method makes sense to me after playing around with the Commodity Calculator. The new method uses some numbers whose origins remain unclear. See THIS POST for unanswered examples of what remains unclear. Good Luck.
Humor is the second most subjective thing on the planet

Brevity is the soul of wit and vulgarity is wit's downfall

Good Night and Good Luck - Read You Soon
hiran
Dangerous
Dangerous
Posts: 77
Joined: Fri Mar 26, 2021 1:39 pm
Location: Munich, Bavaria

Re: Deciphering Javascipt/Legacy Script

Post by hiran »

Douglas Adams in The Hitchhiker's Guide To The Galaxy wrote: There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable. There is another theory which states that this has already happened.
Post Reply