Page 1 of 1

WIP In System Trader (Triage thread)

Posted: Thu Feb 21, 2013 9:59 pm
by Dr.Tripsa
trying to get this working but getting an error

Station.setMarketPrice: Invalid arguments ("Food", "190-2") -- expected Price must be between 0 and 1020 decicredits.

Code: Select all

"use strict";
this.name        = "In_System_Trader"; 
this.author      = "DrTripsa"; 
this.copyright   = "2013 Rob Hess";
this.licence     = "CC BY 3.0"; 
this.description = "In system trader support"; 
this.version     = "1.0";

//1.0 Basic changes, re-calculate prices/quantities when player leaves main station

this.shipLaunchedFromStation = function(station)
{
     if (station.isMainStation)
	 {
		 
		 var RAND_MULT = (system.scrambledPseudoRandomNumber(clock.minutes) * 255);
		 station.setMarketPrice("Food",(station.market.food.marketBasePrice + (RAND_MULT & station.market.food.marketMaskPrice) + ( system.economy * station.market.food.marketEcoAdjustPrice)));
		 station.setMarketQuantity("Food",(station.market.food.marketBaseQuantity + (RAND_MULT & station.market.food.marketMaskQuantity) + ( system.economy * station.market.food.marketEcoAdjustQuantity)) );
	 }
}
The end result will be a new market with each launch (of the player) from the main station, based correctly on economy etc
as you can see the number is currently not in range, but I'm unsure has to how to fix this.

any help would be greatly appreciated.

Re: WIP In System Trader (Triage thread)

Posted: Thu Feb 21, 2013 10:38 pm
by submersible
Dr.Tripsa wrote:
trying to get this working but getting an error

Station.setMarketPrice: Invalid arguments ("Food", "190-2") -- expected Price must be between 0 and 1020 decicredits.

Code: Select all

		 station.setMarketPrice("Food",(station.market.food.marketBasePrice + (RAND_MULT & station.market.food.marketMaskPrice) + ( system.economy * station.market.food.marketEcoAdjustPrice)));
Guessing here;

I think the last + is stringwise (concatenation not addition) , so instead of 190 + -2 = 188 ; you get "190" + "-2" giving "190-2".

Go back to the documentation for those properties and be certain they are really numbers.

you could try wrapping things in Number() to explicitly cast into numeric.

Edit: slightly clarify +

Re: WIP In System Trader (Triage thread)

Posted: Thu Feb 21, 2013 10:47 pm
by cim
submersible wrote:
Go back to the documentation for those properties and be certain they are really numbers.
They're mostly strings. This is probably a bug.

Re: WIP In System Trader (Triage thread)

Posted: Thu Feb 21, 2013 10:47 pm
by Dr.Tripsa
station.setMarketPrice("Food",Number(station.market.food.marketBasePrice + (RAND_MULT & station.market.food.marketMaskPrice) + ( system.economy * station.market.food.marketEcoAdjustPrice)));
gives a now error

Invalid arguments ("Food", NaN) -- expected Price must be between 0 and 1020 decicredits.

apparently Number() is Not a Number?!

Re: WIP In System Trader (Triage thread)

Posted: Thu Feb 21, 2013 11:00 pm
by Dr.Tripsa
Well submersible and cim had it! THANKS!!!!


now to do all the others...

Re: WIP In System Trader (Triage thread)

Posted: Thu Feb 21, 2013 11:14 pm
by Wildeblood
I question the purpose: changing the prices every time you launch means having the opportunity of making money without going anywhere, not even as far as another station within sight. Just launch, re-dock.

Re: WIP In System Trader (Triage thread)

Posted: Fri Feb 22, 2013 2:14 am
by Dr.Tripsa
Wildeblood wrote:
I question the purpose: changing the prices every time you launch means having the opportunity of making money without going anywhere, not even as far as another station within sight. Just launch, re-dock.
Prices remain within system average range so any profit by trading with the main station alone will be meager at best, it's a fair question, but one I considered carefully in making this OXP.

This has been released https://bb.oolite.space/viewtopic.php?f=4&t=13702!

Re: WIP In System Trader (Triage thread)

Posted: Sat Feb 23, 2013 11:59 pm
by Dr.Tripsa
next hurdle has to do with the upcoming update,
apparently I am somehow using descriptions.plist wrong?

here is the plist

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>istgreet</key>
   <array>
       <string>"Welcome back, Commander..."</string>
       <string>"Still in this backwater system, Commander?..."</string>
       <string>"Oh you're back Commander, is it tuesday already..."</string>
       <string>"Back already eh? Bet you can do those spacelanes in your sleep..."</string>
       <string>"Aww, miss me already Commander?..."</string>
   </array>
   <key>istinvite</key>
   <array>
       <string>"You should speak with my cousin"</string>
	   <string>"You should speak with my old friend"</string>
	   <string>"You should speak with my Fathers brothers cousins former roomate"</string>
	   <string>"You should speak with my boss"</string>
	   <string>"You should speak with my underling"</string>
	   <string>"You should speak with my minion"</string>
	   <string>"You should speak with my former lover, whom I am awkwardly still friends with,"</string>
	   <string>"You should speak with my clone"</string>
	   <string>"You should speak with my Latin dance instructor"</string>
	   <string>"You should speak with my sentient houseplant"</string>
	   <string>"You should speak with my conjoined twin"</string>
	   <string>"You should speak with my friends friend"</string>
   </array>
   <key>istoffer</key>
   <array>
       <string>"They owe me a favor."</string>
       <string>"They need a good pilot."</string>
       <string>"What about? Getting out of this arse end of space of course!"</string>
       <string>"They've got need of someone... descrite."</string>
       <string>"They need a fast ship, and no Naval entanglements, if you catch my drift."</string>
	   <string>"They owe me... especially after last night, erm... don't ask."</string>
   </array>
</dict>
</plist>
here is the code that uses it

Code: Select all

this.shipEnteredStationAegis = function(station)
{
     //Give player a hint that the friends they have made might have deals for them
	 //for a test, we'll remove the randomness
	 //var RAND_MULT = (system.scrambledPseudoRandomNumber(clock.minutes) * 255);
	 if(this.IN_SYSTEM_TRADER_REP >= 0)
		 {
		     //periodically we give the player a hint... friend of a friend etc
			 var message = [istgreet] + " " + [istinvite] + " " + [nom] + " " + [istoffer];
			 player.commsMessage(message);
		 }
}
and here is the error

Code: Select all

17:53:19.802 [script.javaScript.exception.notDefined]: ***** JavaScript exception (In_System_Trader 1.05): ReferenceError: istgreet is not defined
what am I doing wrong?

Re: WIP In System Trader (Triage thread)

Posted: Sun Feb 24, 2013 12:20 am
by Wildeblood

Code: Select all

 <string>"Welcome back, Commander..."</string>

Code: Select all

 <string>Welcome back, Commander...</string>
Although it might be something else, as well. I wouldn't bother using descriptions.plist, myself.

Re: WIP In System Trader (Triage thread)

Posted: Sun Feb 24, 2013 12:41 am
by Dr.Tripsa
it looks like support for [item in descriptions.plist] is only in legacy scripting...
I may have to hardcode it.. ick

Re: WIP In System Trader (Triage thread)

Posted: Sun Feb 24, 2013 1:19 am
by submersible
Dr.Tripsa wrote:
it looks like support for [item in descriptions.plist] is only in legacy scripting...
I may have to hardcode it.. ick
Or not - have you tried

Code: Select all

expandDescription("[istoffer]")

Re: WIP In System Trader (Triage thread)

Posted: Sun Feb 24, 2013 1:38 am
by Dr.Tripsa
I can't seem to find reference to that function on the wiki, but I've found a work around for now
btb

1.05 released :)

EDIT: found it... well there is always 1.06

Re: WIP In System Trader (Triage thread)

Posted: Sun Feb 24, 2013 12:09 pm
by Diziet Sma
Minor spelling point.. "descrite" should be "discrete". :wink:

Re: WIP In System Trader (Triage thread)

Posted: Sun Feb 24, 2013 12:56 pm
by Eric Walch
You probably found it by now, but look again at:

Code: Select all

var message = [istgreet] + " " + [istinvite] + " " + [nom] + " " + [istoffer];
"[" is not a valid JS command. It should be

Code: Select all

var message = "[istgreet]" + " " + "[istinvite]" + " " + "[nom]" + " " + "[istoffer]";
or just:

Code: Select all

var message = "[istgreet] [istinvite] [nom] [istoffer]";
And remember those names are globally shared among other oxps, so make them more unique.