(WIP) Elite Trader
Moderators: winston, another_commander
- Reval
- ---- E L I T E ----
- Posts: 402
- Joined: Thu Oct 29, 2020 3:14 am
- Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.
Re: (WIP) Elite Trader
How to pass an array to a function - is that possible in JS?
Edit: I just want the function to return the total of the elements in the array.
Edit: I just want the function to return the total of the elements in the array.
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
Re: (WIP) Elite Trader
When you assign an array (or an object) to a variable, you are assigning a reference for the array (or object) to that variable.
Function parameters in JS are, if memory serves, passed by value, i.e., copied, but for parameters that are arrays or objects that means copying the reference to the array or object.
Beware that if the copy or the original variable are "reset" by assigning an empty array to it, the original and copy will not be referencing the same array any more... "reset" the array by assigning 0 to its length property to avoid that.
- Reval
- ---- E L I T E ----
- Posts: 402
- Joined: Thu Oct 29, 2020 3:14 am
- Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.
Re: (WIP) Elite Trader
OK. So would this behave as expected? (it doesn't seem to be doing so)
so I'm not changing the passed array in the function, just using its contents.
Code: Select all
// Total price - passes price array
this._etGetTotPrice = function(which) {
var result = 0;
for (var t=0; t<20; t++) result += which[t];
return result;
}
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
Re: (WIP) Elite Trader
It should, I don't see anything wrong with it
- Reval
- ---- E L I T E ----
- Posts: 402
- Joined: Thu Oct 29, 2020 3:14 am
- Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.
Re: (WIP) Elite Trader
How do I get the current system name as a string? - I've tried System.name and it returns "System". Also, System.mainPlanet returns "undefined".
Edit: Even Station.name only returns "Station".
Edit: Even Station.name only returns "Station".
Last edited by Reval on Fri Nov 13, 2020 6:22 pm, edited 1 time in total.
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
Re: (WIP) Elite Trader
Look at the static methods for System.
- Reval
- ---- E L I T E ----
- Posts: 402
- Joined: Thu Oct 29, 2020 3:14 am
- Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.
Re: (WIP) Elite Trader
Thanks. They're very confusing. I infer from what there is on the Wiki that first you must somehow get the system ID and then use that ID to get the name of the system (Inera, Raale, Tionisla or whatever), correct?
Edit: System.systemNameForID(System.ID) gives me errors, as did just systemNameForID(System.ID)
Edit: System.systemNameForID(System.ID) gives me errors, as did just systemNameForID(System.ID)
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
Re: (WIP) Elite Trader
Try System.systemNameForID(system.ID)Reval wrote: ↑Fri Nov 13, 2020 6:27 pmThanks. They're very confusing. I infer from what there is on the Wiki that first you must somehow get the system ID and then use that ID to get the name of the system (Inera, Raale, Tionisla or whatever), correct?
Edit: System.systemNameForID(System.ID) gives me errors, as did just systemNameForID(System.ID)
- Reval
- ---- E L I T E ----
- Posts: 402
- Joined: Thu Oct 29, 2020 3:14 am
- Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.
Re: (WIP) Elite Trader
That little 's' fixed it So could you explain the difference between System and system. When should I use the first and when the second? And does this difference apply to all the other objects and properties?
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
Re: (WIP) Elite Trader
I infer system is a global variable (a property of the global object) with a reference to the current system object, while System is the class name of that object, used to access the static methods (there are similar Class names to access static methods of Ship, EquipmentInfo and SistemInfo)
Keep a bookmark for Oolite JavaScript Reference, it will come in handy time and time again.
Keep a bookmark for Oolite JavaScript Reference, it will come in handy time and time again.
- Reval
- ---- E L I T E ----
- Posts: 402
- Joined: Thu Oct 29, 2020 3:14 am
- Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.
Re: (WIP) Elite Trader
Elite Trader, version 0.2 Beta
OK. I think I've taken this little proof-of-concept about as far as I care to for now. Any more would just be overcomplicating things. Probably time for a version 1.0 release.
If anyone would like to give it a last-minute test, I'd be grateful for any bug reports...
http://wiki.alioth.net/img_auth.php/e/e ... Trader.oxz
CHANGES:
There's a little bit more immersion now with some of the messages.
Implemented an inventory check on starting the game.
Player is asked to unload and re-buy stock if the initial bought price does not tally.
OK. I think I've taken this little proof-of-concept about as far as I care to for now. Any more would just be overcomplicating things. Probably time for a version 1.0 release.
If anyone would like to give it a last-minute test, I'd be grateful for any bug reports...
http://wiki.alioth.net/img_auth.php/e/e ... Trader.oxz
Code: Select all
"use strict";
this.name = "Elite Trader";
this.author = "Reval";
this.description = "A profitable Market trade scores toward Elite";
/* Version 0.2 Beta
This OXP takes no account of cargo contracts,
special deals, scoops of drifting cargo in space,
or of gems or precious metals.
NB. If the game loads with full holds, the first score is missed.
*/
this.playerSoldCargo = function(commodity, units, price) {
// selling preliminaries - update quantity and price
if (this.$etLastPrice[commodity]>0) {
this.$etSoldUnits += units;
this.$etSoldPrice += price * units;
}
// see if we made a profit
this.$etMadeProfit = ((this.$etSoldPrice > this.$etBoughtPrice) && (this.$etLastPrice[commodity] > 0));
// conditions for scoring
this.$etOKtoScore = ((units > 2) && (!this.$etDone) && (this.$etBoughtUnits>0) && (this.$etMadeProfit));
// decrement the manifest by # of units and price
if (this.$etLastPrice[commodity]>0) {
this.$etBoughtUnits -= units;
this.$etBoughtPrice -= this.$etLastPrice[commodity] * units;
}
// display ship's cargo and its purchase value
if (price==this.$etLastPrice[commodity])
player.consoleMessage("In hold: "+this.$etBoughtUnits+" pods ( "+formatCredits(((this.$etBoughtPrice)/10),true,true)+" )");
// credit a "market killing" on first profitable sell
if (this.$etOKtoScore) {
player.score ++;
player.consoleMessage("You made a killing!");
// for simplicity, only one score per station
this.$etDone = true;
// otherwise acknowledge a skillful trade if we're not just unloading
} else if (this.$etMadeProfit && (price!=this.$etLastPrice[commodity]) && (this.$etStation!=this.$etLastStation))
player.consoleMessage("Nice trade!");
}
this.playerBoughtCargo = function (commodity, units, price) {
// buying preliminaries - record quantity and price
this.$etBoughtUnits += units;
this.$etBoughtPrice += price * units;
this.$etLastPrice[commodity] = price;
// display ship's cargo and its purchase value
player.consoleMessage("In hold: "+this.$etBoughtUnits+" pods ( "+formatCredits(((this.$etBoughtPrice)/10),true,true)+" )");
}
this.guiScreenChanged = function(to, from) {
if (to == "GUI_SCREEN_MARKET") {
// suggest a G.E.T. presence on the market floor
player.consoleMessage("The "+System.systemNameForID(system.ID)+" Guild of Elite Traders", 5);
// show hold-status on entering Market
var pods = this._etPodCount();
player.consoleMessage("In hold: "+pods+" pods ( "+formatCredits(((this.$etBoughtPrice)/10),true,true)+" )");
// advise player to unload and re-buy cargo after game-load
if ((pods>0) && (this.$etBoughtPrice<=0)) player.consoleMessage("Elite Trader: Please sell cargo and re-buy.",5);
} else
if (to == "GUI_SCREEN_MANIFEST") {
// suggest the G.E.T. presence on the Manifest screen
player.consoleMessage("Under the aegis of the "+System.systemNameForID(system.ID)+" G.E.T", 10);
}
}
this.shipDockedWithStation = function(station) {
this.$etLastStation = this.$etStation;
this.$etStation = station;
this.$etLastSystem = this.$etSystem;
this.$etSystem = System.systemNameForID(system.ID);
// System's G.E.T. welcomes the commander on arrival
player.consoleMessage("The "+this.$etSystem+" Guild of Elite Traders welcomes you!"/* We trust your passage from "+this.$etLastSystem+" passed peacefully."*/, 5);
// clear flags and sold-quantities on docking
this.$etDone = false;
this.$etMadeProfit = false;
this.$etSoldUnits = 0;
this.$etSoldPrice = 0;
}
this.startUp = function() {
log(this.name, "Initialising OXP " + this.name);
// declare & initialize globals
this.$etDone = false;
this.$etMadeProfit = false;
this.$etOKtoScore = false;
this.$etSoldUnits = 0;
this.$etSoldPrice = 0;
this.$etBoughtPrice = 0;
this.$etBoughtUnits = 0;
this.$etSystem = "";
this.$etLastSystem = "";
this.$etNextSystem = "";
this.$etStation=0;
this.$etLastStation=0;
this.$etLastPrice = new Array();
for (var c=0; c<20; c++) this.$etLastPrice[c]=0;
}
// # of cargo pods in ship's hold
this._etPodCount = function() {
var result = 0;
for (var i=0; i<manifest.list.length; i++) {
var q = manifest.list[i].quantity;
if (q > 0) result+= q;
}
return result;
}
There's a little bit more immersion now with some of the messages.
Implemented an inventory check on starting the game.
Player is asked to unload and re-buy stock if the initial bought price does not tally.
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
- Reval
- ---- E L I T E ----
- Posts: 402
- Joined: Thu Oct 29, 2020 3:14 am
- Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.
Re: (WIP) Elite Trader
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
- Reval
- ---- E L I T E ----
- Posts: 402
- Joined: Thu Oct 29, 2020 3:14 am
- Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.
Re: (WIP) Elite Trader
Elite Trader, version 1.1
Now in the Manager and on the Wiki.
More info HERE.
NEW IN VERSION 1.1:
Immersive G.E.T. messages at every stage of the voyage.
Successful trading brings useful rewards.
Trade well!
Now in the Manager and on the Wiki.
More info HERE.
NEW IN VERSION 1.1:
Immersive G.E.T. messages at every stage of the voyage.
Successful trading brings useful rewards.
Trade well!
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
- Reval
- ---- E L I T E ----
- Posts: 402
- Joined: Thu Oct 29, 2020 3:14 am
- Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.
Re: (WIP) Elite Trader
Elite Trader, version 1.2
Now in the Manager and on the Wiki.
More info HERE.
NEW IN VERSION 1.2:
Minor cosmetic enhancements.
On Arrival Screen, speed-reward status message is not shown if another OXP resets the ship's maxSpeed (Masslock Compensator is a known culprit).
Trade well!
Now in the Manager and on the Wiki.
More info HERE.
NEW IN VERSION 1.2:
Minor cosmetic enhancements.
On Arrival Screen, speed-reward status message is not shown if another OXP resets the ship's maxSpeed (Masslock Compensator is a known culprit).
Trade well!
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.
- Reval
- ---- E L I T E ----
- Posts: 402
- Joined: Thu Oct 29, 2020 3:14 am
- Location: At home in the Xexedi Cluster, driving an FE Asp II, Laenina's Flux.
Re: (WIP) Elite Trader
Elite Trader, version 1.3
Now in the Manager and on the Wiki.
More info HERE.
NEW IN VERSION 1.3:
Cosmetic enhancements (contextual comms messages).
Destroying other ships--as opposed to damaging them to aid escape--brings System G.E.T. disapprobation and a bout of penance (no Elite score or rewards for that system).
Trade well!
Now in the Manager and on the Wiki.
More info HERE.
NEW IN VERSION 1.3:
Cosmetic enhancements (contextual comms messages).
Destroying other ships--as opposed to damaging them to aid escape--brings System G.E.T. disapprobation and a bout of penance (no Elite score or rewards for that system).
Trade well!
Dor 'call me Grocer' Reval (a Xexedian Laver) was always considered a little backward.