Page 1 of 1

Another idea & some pointers, please

Posted: Mon Jan 21, 2013 2:33 am
by Massively Locked
I was working on the Storage Rental biz which only succeeded in making me pull out my hair by the fistful. So I took a little detour to work on another idea only to find that all roads lead to the same place. It's the "choices" parameter of the "runScreen" thingamabob. I've got the "choicesKey" working as you can see below, but "choices" continues to thumb its nose at me. I copied the example in the wiki practically letter by letter but still no joy. If someone can enlighten me on what I need to do to get it to work, I'd be much obliged.

Code: Select all

this.name = "Anaconda's offer";
this.version = "0.00001";
"use strict";

// this max's out the market supply of food or whatever commodity
this.shipDockedWithStation = function(station) {
	station.setMarketQuantity("Food", 127);
	}
// this adds a listing to the Interface screen
this.guiScreenChanged = function(to, from) {
	player.ship.dockedStation.setInterface("AnacOffer",{
		title: "Commodities offer from trader",
		category: "Trade",
		summary: "Public offer from Anaconda Such&such",
		callback: this._AnacOffer.bind(this)
		});
	}
// this is the screen where you view the details of the offer; accept or decline or whatever else
this._AnacOffer = function() {
	mission.runScreen( { title: "Public offer",
		choicesKey: "YerResponse",
		exitScreen: "GUI_SCREEN_INTERFACES"
		},
		function (choice) {
			if (choice === "1-Y") {
				player.credits = player.credits - 56;
				manifest.food = manifest.food + 8;
				};
			if (choice === "2-N");
			}
		);
	mission.addMessageText("Msg posted to all traders in-station");
	mission.addMessageText("From Cmdr So&so of the Anaconda, Such&such");
	mission.addMessageText("I have 8 containers of food and the station is not buying any more");
	mission.addMessageText("Will sell to any trader for 7 credits per.  Buyer must take full offer");
	}

Missiontext.plist
{
"YerResponse" = {
	"1-Y" = "Accept the offer";
	"2-N" = "Decline the offer";
	};
}
Here's the premise of my new idea: every now & again, some ginormous ship like the Anaconda will pull into a station just before you. He'll dump & max out the station's market of some commoditiy. He still has some more but needs to empty his hold so he can fill it with whatever and fly off to whereever. So he puts the remaining containers up for offer to any traders who happen to be in-station (namely, You). You can then accept this offer, scoff at such nonsense or negotiate a better price. If you do buy his surplus, you'll obviously have to go elsewhere to sell them or wait until the station sheds some of its current supply.

Big thanks to The Devs for the shiny new Interface screen! I'm just starting to think of the possibilities with it.

Re: Another idea & some pointers, please

Posted: Mon Jan 21, 2013 6:14 am
by Wildeblood

Code: Select all

// this max's out the market supply of food or whatever commodity
this.shipDockedWithStation = function(station) {
	station.setMarketQuantity("Food", 127);
	}
// this adds a listing to the Interface screen
this.guiScreenChanged = function(to, from) {   <----------------- Bogus!
	player.ship.dockedStation.setInterface("AnacOffer",{ <----------------- Bogus!
		title: "Commodities offer from trader",
		category: "Trade",
		summary: "Public offer from Anaconda Such&such",
		callback: this._AnacOffer.bind(this)
		});
	}

Code: Select all

this.shipDockedWithStation = function(station) {
   // this max's out the market supply of food or whatever commodity
	station.setMarketQuantity("Food", 127);
   // this adds a listing to the Interface screen
	station.setInterface("AnacOffer",{
		title: "Commodities offer from trader",
		category: "Trade",
		summary: "Public offer from Anaconda Such&such",
		callback: this._AnacOffer.bind(this)
		});
	}

Re: Another idea & some pointers, please

Posted: Tue Jan 22, 2013 3:57 am
by Massively Locked
Thanks, Wildeblood- I always seem to hit on the most roundabout way of doing things in code. :)

I finally got that choices thingy working! Unless I'm mistaken, it looks like thanks go to Spara, so Thank you, Spara!

Re: Another idea & some pointers, please

Posted: Wed Jan 23, 2013 5:45 am
by Wildeblood
*Bump* How's it progressing?

Re: Another idea & some pointers, please

Posted: Wed Jan 23, 2013 9:09 am
by Massively Locked
Slooowwwwly. Veeerrrryyyyy sloooowwwly.

One of my big problems is that I still have trouble wrapping my head around this whole 'Object Oriented' business. A perfect example is how I'll see a property or method like setInterface and think, "cool- let me use that." So I'll put it on a line all by itself like this:

Code: Select all

setInterface (title:"My screen",category:"Blue Screens",summary:"This will go to my Blue Screen Of Dreams")
Of course it's not going to work. And half an hour later, I finally realize why it's not working.

Another problem is my penchant for reinventing the wheel. I needed an random number generator. It seemed like the best option was scrambledPseudoRandomNumber. But- it always yields the same result from the same salt. So I went to the clock/time properties/methods, mashed them together in creative ways, used the result as the salt for the scrambledPseudoRandomNumber and voila- my very own randomly random number generator! I was quite proud of my accomplishment and went off for a tea break. When I sat back down at my machine, I started looking through someone's code (Thargoid's, I think). And there I came across:

Code: Select all

Math.random()
<facepalm> I guess better late than never...

And I can't for the life of me figure out how the hell I got here. It wasn't that long ago when I was happily cruising the spaceways, buying computers and furs on the cheap then unloading them for a nice profit, fending off pirates and other low-lifes who had the gall to demand that I eject my legitimately-bought cargo. And now... now... I'm writing and debugging JS code trying to figure out where I left out a comma (or an entire object) or what I should or shouldn't have capitalized.

Help me... someone, help me, please......

Re: Another idea & some pointers, please

Posted: Wed Jan 23, 2013 9:23 am
by Diziet Sma
Massively Locked wrote:
And I can't for the life of me figure out how the hell I got here. It wasn't that long ago when I was happily cruising the spaceways, buying computers and furs on the cheap then unloading them for a nice profit, fending off pirates and other low-lifes who had the gall to demand that I eject my legitimately-bought cargo. And now... now... I'm writing and debugging JS code trying to figure out where I left out a comma (or an entire object) or what I should or shouldn't have capitalized.

Help me... someone, help me, please......
<chuckles>

Now you know why we call it The Dark Side.. :twisted:

Cookies are on the plate over in the corner. Try not to stand between EV and the cookie-plate. :wink:

Re: Another idea & some pointers, please

Posted: Wed Jan 23, 2013 9:25 am
by Smivs
Massively Locked wrote:
And I can't for the life of me figure out how the hell I got here. It wasn't that long ago when I was happily cruising the spaceways, buying computers and furs on the cheap then unloading them for a nice profit, fending off pirates and other low-lifes who had the gall to demand that I eject my legitimately-bought cargo. And now... now... I'm writing and debugging JS code trying to figure out where I left out a comma (or an entire object) or what I should or shouldn't have capitalized.

Help me... someone, help me, please......
Smivs hands Massively Locked another Darkside Cookie... :D

Re: Another idea & some pointers, please

Posted: Wed Jan 23, 2013 9:49 am
by Massively Locked
nom, nom, nom
<stops for a moment & wonders about these cookies he's been wolfing down>
<shakes head>
nom, nom, nom...

BTW, good to see you back, Smivs! Hope yer feeling better.

Re: Another idea & some pointers, please

Posted: Wed Jan 23, 2013 9:53 am
by GGShinobi
Massively Locked wrote:
Help me... someone, help me, please......
:lol: LOL :lol:
:twisted: We are all lost! We are all going down together!!! :twisted:

Uuuh I really need to sleep... :? *feeling dizzy*

Re: Another idea & some pointers, please

Posted: Wed Jan 23, 2013 10:54 am
by Thargoid
Massively Locked wrote:
When I sat back down at my machine, I started looking through someone's code (Thargoid's, I think). And there I came across:

Code: Select all

Math.random()
<facepalm> I guess better late than never...

And I can't for the life of me figure out how the hell I got here. It wasn't that long ago when I was happily cruising the spaceways, buying computers and furs on the cheap then unloading them for a nice profit, fending off pirates and other low-lifes who had the gall to demand that I eject my legitimately-bought cargo. And now... now... I'm writing and debugging JS code trying to figure out where I left out a comma (or an entire object) or what I should or shouldn't have capitalized.

Help me... someone, help me, please......
You now understand why I chose both my avatar and my user name here. OXP coding is quite addictive when you get into it-an evil business :twisted:

Re: Another idea & some pointers, please

Posted: Thu Jan 24, 2013 8:09 am
by Switeck
Don't be afraid to post code here that doesn't work or doesn't work as intended.
It seems easier for someone else to find a missing comma than to find it yourself.

Re: Another idea & some pointers, please

Posted: Thu Jan 24, 2013 9:13 am
by Eric Walch
Massively Locked wrote:
It seemed like the best option was scrambledPseudoRandomNumber. But- it always yields the same result from the same salt.
You'll learn fast what to use when.
scrambledPseudoRandomNumber, as you now found out, was invented to generate 'random' numbers that are always the same for a given system. Useful to only add stations in certain systems and consistently over time. :P
The salt was added to prevent all oxp selecting the same 'random' choice for a given system.