Page 1 of 1

Help with a Javascript exception

Posted: Wed Mar 23, 2016 6:34 pm
by Astrobe
I'm trying to hack an existing script, namely script.js from extra planets. My goal is to add a parameter for oxpConfig that allows the user to have the moons farther away from the planet, because they are too often unbelievably close to the planet in my opinion.

I've added three lines:

Code: Select all

this.oxpcSettings = {
	Info: {Name:"System Redux",EarlyCall:true,EarlySet:true,Notify:true,
		InfoE:"Exclude systems. If set SystemRedux is bypassed in these systems.\nChanges may require restart / reload."
	},
	SInt0: {Name:"max_moons",Def:0x3,Max:0x4,Desc:"Max number of moons"},
	SInt1: {Name:"max_planets",Def:0x4,Max:0x4,Desc:"Max number of planets"},
	SInt2: {Name:"orbit_mul", Def:0x1, Max:0x4, Desc:"Base moon orbits"}, /* <---- THIS ONE */
	EInt0: {Name:"exSys",Def:0x0,Max:0x7,Desc:["Lave","Diso","Tianve"]}
};

Code: Select all

this.startUp = function() {
	//4 moons are currently defined in the planetdata.
	this.max_moons = 3;//max number of moons around a planet. There's no limit here.
	this.max_planets = 4;//maximum number of extra planets per system. extra planets might have moon. There's no limit here.
	this.extraPlanetMoonsProbability = 0.1;//the probablitity for an extra planet to have moons.
	this.orbit_mul=1; // Scale for orbit radius (moons) // <----- THIS ONE
	
	this.exSys = 0;//for oxp config	
	this.excl = [[],[],[],[],[],[],[],[]];//excluded systems
	this.systemDone = false;//flag so that system gets populated only once
	this.runOnce = true;//controls the sorting of the pools
}

Code: Select all

	function addMoons(planet_position, planet_radius, seed) {
		//number of moon sizes defined in planetinfo.plist
		var moonSizes = 4;
		
		//number of moons to be added. extremes have probability weight of 0.5, others 1.
		var numberOfMoons = Math.round(system.scrambledPseudoRandomNumber(seed) * max_moons);
		
		//orbits. lowest is 2.5 * planet radius. station is usually at 2 * planet radius.
		var moonOrbits = new Array();
		for (var i = 0; i < max_moons; i++) moonOrbits.push(i);
		var baseMoonOrbit = planet_radius * (2.5 * this.orbit_mul); // <----- THIS ONE (well, I only changed that one)
		var moonOrbitDifference = 30000;
In the logs, I get the exception:
19:18:28.208 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (System Redux 0.7): TypeError: this.orbit_mul is undefined
I of course don't have a clue about what I did wrong. The new setting appears correctly in OXP config, except it shows a bad default value; but I believe it is because it's not present in the saved parameters yet.

Re: Help with a Javascript exception

Posted: Wed Mar 23, 2016 9:42 pm
by Redspear
Scripting beginner here but... shouldn't the last one be orbit_mul rather rhan this.orbit_mul???
c.f. * max_moons in the same script.

Re: Help with a Javascript exception

Posted: Wed Mar 23, 2016 11:01 pm
by Lone_Wolf
good catch, redspear.

Astrobe : you are trying to change script.js from "Additional Planets SR Base" oxp ?

Look for these lines ( linenumber 117 & 118) :

Code: Select all

//inner functions need this
	var max_moon = this.max_moons;
add a line there like this :

Code: Select all

	var orbit_mul = this.orbit_mul;
In the addMoons( ) part use orbit_mul instead of this.orbit_mul .

Re: Help with a Javascript exception

Posted: Thu Mar 24, 2016 12:08 pm
by Astrobe
Oh, silly me. I did notice the max_moon thing but I interpreted it as an optimisation (one sees that kind of thing in Lua for instance) and never read the comment just above it.

Thanks for the help.

Re: Help with a Javascript exception

Posted: Thu Mar 24, 2016 2:08 pm
by ocz
@Astrobe:
Great the problem could be resolved this quickly.

I don't want to sound nitpicky, it certainly isn't a big issue and I ain't a mod, but the thread title doesn't say much about its content. Also the problem is fixed. Changing the thread's title to something like "Scripting problem with Additional Planets SR Base OXP [solved]" or something along the lines, would be great and maybe a help for people with a similar problem. You'll never know. :D