Another idea & some pointers, please

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

Moderators: another_commander, winston

Post Reply
User avatar
Massively Locked
Dangerous
Dangerous
Posts: 84
Joined: Tue Nov 20, 2012 12:20 pm

Another idea & some pointers, please

Post 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.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2282
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Another idea & some pointers, please

Post 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)
		});
	}
User avatar
Massively Locked
Dangerous
Dangerous
Posts: 84
Joined: Tue Nov 20, 2012 12:20 pm

Re: Another idea & some pointers, please

Post 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!
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2282
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Another idea & some pointers, please

Post by Wildeblood »

*Bump* How's it progressing?
User avatar
Massively Locked
Dangerous
Dangerous
Posts: 84
Joined: Tue Nov 20, 2012 12:20 pm

Re: Another idea & some pointers, please

Post 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......
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6311
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

Re: Another idea & some pointers, please

Post 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:
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Another idea & some pointers, please

Post 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
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Massively Locked
Dangerous
Dangerous
Posts: 84
Joined: Tue Nov 20, 2012 12:20 pm

Re: Another idea & some pointers, please

Post 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.
User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

Re: Another idea & some pointers, please

Post 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*
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: Another idea & some pointers, please

Post 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:
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2412
Joined: Mon May 31, 2010 11:11 pm

Re: Another idea & some pointers, please

Post 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.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Another idea & some pointers, please

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