Help with a Javascript exception

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

Moderators: winston, another_commander

Post Reply
Astrobe
---- E L I T E ----
---- E L I T E ----
Posts: 609
Joined: Sun Jul 21, 2013 12:26 pm

Help with a Javascript exception

Post 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.
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2687
Joined: Thu Jun 20, 2013 10:22 pm
Location: On the moon Thought, orbiting the planet Ignorance.

Re: Help with a Javascript exception

Post 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.
User avatar
Lone_Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 546
Joined: Wed Aug 08, 2007 10:59 pm
Location: Netherlands

Re: Help with a Javascript exception

Post 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 .
OS : Arch Linux 64-bit - rolling release

OXPs : My user page

Retired, reachable at [email protected]
Astrobe
---- E L I T E ----
---- E L I T E ----
Posts: 609
Joined: Sun Jul 21, 2013 12:26 pm

Re: Help with a Javascript exception

Post 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.
ocz
Deadly
Deadly
Posts: 175
Joined: Tue Nov 10, 2015 1:59 pm

Re: Help with a Javascript exception

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