Debug Report script

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6632
Joined: Wed Feb 28, 2007 7:54 am

Debug Report script

Post by another_commander »

For any of you interested in testing trunk and/or provide bug reports, I recommend that you copy the code below and save it as script.js inside the Config subdirectory of an OXP folder, like DebugReport.oxp. This is the code written originally by Ahruman to test the handlers supported by Oolite, to which I have added as more and more handlers were being created. It should contain some kind of reaction (log or otherwise) to almost every handler that we currently have. Additionally, it gives good information for things like what killed the player etc., which can be very useful for debugging. Feel free to add to it as more things become available, or in case I have forgotten things.

Code: Select all

/*	ahruman-test.js
	JavaScript test.oxp
	
	A script which responds to every event supported by Oolite 1.72 (except
	tickle, which is commented out - see bottom of file).
	This was originally written by dajt, but almost all the original script
	has been replaced.
*/
this.name			= "JavaScript-test";
this.author			= "Jens Ayton";
this.copyright		= "This work is hereby placed in the public domain.";
this.description	= "A test OXP written using JavaScript. Based on a test script by dajt. Some further additions by another_commander";
this.version		= "2.1";


this.hyperspaceCountdownTimer = null; 
this.hyperspaceCountdownSecondsRemaining = 0; 


// Called after all OXPs are launched, before the game has begun.
this.startUp = function()
{
	log("jstest.startUp", "Script startUp called.");
	log("jstest.oolite.versionString", "Oolite version: " + oolite.versionString);
}


// Called when saved game is loaded, or player respawns after dying.
this.reset = function()
{
	log("jstest.reset", "Script reset called.");
}


function append(string, suffix)
{
	log("Appending \"" + suffix + "\" to string \"" + string + "\".");
	
	if (string != "") string += ", ";
	string += suffix;
	return string;
}


// Called when alert status changes.
this.alertConditionChanged = function()
{
	var alertName;
	switch (player.alertCondition)
	{
		case 0:
			alertName = "docked";
			break;
		
		case 1:
			alertName = "green";
			break;
		
		case 2:
			alertName = "yellow";
			break;
		
		case 3:
			alertName = "red";
			break;
		
		default:
			alertName = "unknown value " + player.alertCondition;
	};
	
	var alertState = "";
	if (player.alertTemperature) alertState = append(alertState, "cabin temperature high");
	if (player.alertMassLocked) alertState = append(alertState, "mass locked");
	if (player.alertAltitude) alertState = append(alertState, "altitude low");
	if (player.alertHostiles) alertState = append(alertState, "hostiles present");
	if (alertState == "") alertState = "clear";
	
	log("jstest.alert", "Player alert condition changed to " + alertName + " (" + alertState + ")");
}


// Called before launch tunnel effect.
this.shipWillDockWithStation = function()
{
	log("jstest.dock.begin", "Player is docking.");
}


// Called at end of docking tunnel effect.
this.shipDockedWithStation = function()
{
	log("jstest.dock.complete", "Player docked at " + player.ship.dockedStation.name + ", which " + (player.ship.dockedStation.isMainStation ? "is" : "is not") + " the system's main station.");
}


// Called before launch tunnel effect.
this.shipWillLaunchFromStation = function()
{
	log("jstest.launch.begin", "Player is launching.");
}


// Called after launch tunnel effect.
this.shipLaunchedFromStation = function()
{
	log("jstest.launch.complete", "Player \"" + player.name + "\" has launched in a " + player.ship.name + " into galaxy " + galaxyNumber + ", planet " + system.ID + " (\"" + system.name + "\"), govt = " + system.government + " (" + system.governmentDescription + "), economy = " + system.economy + " (" + system.economyDescription + "), tech level = " + system.techLevel);
	this.clockReport();
}


// Called when player initiates witchspace countdown.
this.didBeginJumpCountDown = function(type)	// Type is one of: "standard", "galactic". Others may be added in future.
{
	log("jstest.witchSpace.started", "Silly walk to " + type + " witchspace started.");
}


// Called if player cancels witchspace countdown.
this.didCancelJumpCountDown = function()
{
	log("jstest.witchSpace.cancelled", "Rain dance cancelled on account of rain.");
}


// Called at end of witchspace countdown, if unsuccessful.
this.didFailToJump = function(reason)	// Reason is one of: "blocked", "too far", "insufficient fuel". Others may be added in future.
{
	switch (reason)
	{
		case "blocked":
			reason = "A station ate the chicken."
			break;
		
		case "too far":
			reason = "Our chicken isn't big enough."
			break;
		
		case "insufficient fuel":
			reason = "Bad news ain't bad enough.";
	}
	
	log("jstest.witchSpace.failed", "Chicken-waving failed. Who ate the chicken? Reason: " + reason);
}


// Called at end of witchspace countdown, if successful, or on entring wormhole.
this.shipWillEnterWitchspace = function(cause)	// cause is one of: "standard jump", "galactic jump", "wormhole". Others may be added in future.
{
	this.scriptedMisjumpBeingExecuted = false;
	log("jstest.witchSpace.begin", "Player is entering witchspace. Cause: " + cause);
	if (player.ship.scriptedMisjump == true)
	{
		if (cause == "standard jump")
		{
			log("jstest.witchspace.begin", "Scripted misjump is active. Player will end up in witchspace.");
			this.scriptedMisjumpBeingExecuted = true;
		}
	}
	this.stopHyperspaceCountdownTimer();
	if (system.name == "Rainza") // GH from Rainza will lead to Oresrati, as the legend dictates.
	{
		if (cause == "galactic jump")
		{
			log("jstest.witchSpace.begin", "Player is executing intergalactic jump from Rainza, G7. Setting jump destination to Oresrati, G8.");
			player.ship.galacticHyperspaceBehaviour="BEHAVIOUR_FIXED_COORDINATES";
			player.ship.galacticHyperspaceFixedCoords=[16, 255, 0]; // Oresrati, G8.
		}
	}
}


// Called at beginning of witchspace tunnel effect; the destination system is already set up at this time.
this.shipWillExitWitchspace = function()
{
	log("jstest.witchSpace.arrive", "Player is exiting witchspace.");
}


this.playerEnteredNewGalaxy = function(galaxyNumber)
{
	log("jstest.witchSpace.arriveToNewGalaxy", "Player has arrived on galaxy " + galaxyNumber + ".");
	if (system.name == "Oresrati") // We are at Oresrati, reset GH properties.
	{
		Player.ship.setGalacticHyperspaceFixedCoords(96, 96);
		Player.ship.galacticHyperspaceBehaviour("BEHAVIOUR_STANDARD");
	}
}


// Called after witchspace tunnel effect.
this.shipExitedWitchspace = function()
{
	log("jstest.witchSpace.complete", "Player exited witchspace into galaxy " + galaxyNumber + ", planet " + system.ID + " (\"" + system.name + "\"), govt = " + system.government + " (" + system.governmentDescription + "), economy = " + system.economy + " (" + system.economyDescription + "), tech level = " + system.techLevel);
}


// Called when auto-docking sequence begins (but not for insta-dock).
this.didStartAutoPilot = function()
{
	log("jstest.autoPilot.on", "Player enabled autopilot.");
}


// Called when player cancels auto-docking sequence.
this.didAbortAutoPilot = function()
{
	log("jstest.autoPilot.cancelled", "Player cancelled autopilot.");
}


// Station says player can't dock on account of being naughty.
this.didRecieveDockingRefusal = function()
{
	log("jstest.autoPilot.refused", "Station refused autopilot docking.");
}


// Escape pod launched.
this.didLaunchEscapePod = function()
{
	log("jstest.escapePod", "Player ejected... the sissy.");
}


// Player died.
this.shipDied = function(whom, why)
{
	log("jstest.died", "Player has suffered an existence failure.");
	log("jstest.died", "Killed by " + whom + " by means of " + why);
	this.stopHyperspaceCountdownTimer();
}

// Clock report.
this.clockReport = function()
{
	log("clockReport.clockString", clock.clockString);
}


this.playerBoughtEquipment = function(equipmentKey)
{
	log("playerBoughtEquipment","Player has bought equipment: " + equipmentKey);
}


this.equipmentDamaged = function(equipmentKey)
{
	log("equipmentDamaged", "Equipment " + equipmentKey + " damaged.");
}


this.playerRequestedDockingClearance = function(result)
{
	if (result == "DOCKING_CLEARANCE_GRANTED")
		log("playerRquestedDockingClearance", "Player has received docking clearance.");
	else
		log("playerRequestedDockingClearance", "Docking clearance result: " + result);
}


this.hyperspaceCountdownTimerFunc = function () 
{ 
    //log("hyperspaceCountdownTimer", "Hyperspace in " + this.hyperspaceCountdownSecondsRemaining + " seconds."); 
    this.hyperspaceCountdownSecondsRemaining--; 
} 


this.stopHyperspaceCountdownTimer = function () 
{ 
    if (this.hyperspaceCountdownTimer) 
    { 
        this.hyperspaceCountdownTimer.stop(); 
        this.hyperspaceCountdownTimer = null; 
    } 
} 


// Called when player initiates witchspace countdown. 
this.playerStartedJumpCountdown = function (type, delay) 
{ 
    // Get number of whole seconds until jump. 
    this.hyperspaceCountdownSecondsRemaining = Math.floor(delay); 
    
    // Get fractional part of delay, if any. 
    var initialDelay = delay - this.hyperspaceCountdownSecondsRemaining; 
    
    if (initialDelay == 0) 
    { 
        // If no fractional time, call countdown function immediately 
        // and use timer for subsequent seconds. 
        this.hyperspaceCountdownTimerFunc(); 
        initialDelay = 1.0; 
        this.hyperspaceCountdownSecondsRemaining--; 
    } 
    
    // Call timer function every 1.0 seconds after initialDelay. 
    this.hyperspaceCountdownTimer = 
        new Timer(this, this.hyperspaceCountdownTimerFunc, initialDelay, 1.0); 
} 


this.playerCancelledJumpCountdown = function () 
{ 
    this.stopHyperspaceCountdownTimer(); 
} 


this.playerJumpFailed = function (reason) 
{ 
    this.stopHyperspaceCountdownTimer(); 
} 


this.playerTargettedMissile = function (missile)
{
	if (missile)
	{
		log("playerTargettedMissile", "Player has targetted incoming missile " + missile);
	}
	else
	{
		log("playerTargettedMissile", "Player attempted to target incoming missile, but area scan indicates no incoming.");
	}
}


this.playerBoughtNewShip = function (newShip)
{
	log("playerBoughtNewShip", "Player has bought a new " + newShip.displayName);
}


// Called periodically, more or less.
/*this.tickle = function(status)
{
	log("jstest.idle", "Ping! Status is: " + status);
}*/


log("jstest.loaded", "Script loaded.");
This should make your Latest.log much more descriptive and could help us work out problems faster. Hope you find it useful.
Last edited by another_commander on Mon Aug 17, 2009 12:52 pm, edited 4 times in total.
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"

Post by Diziet Sma »

Thanks a_c! I've added it to my trunk addons..

If anyone adds to it, could they please post the additions to this thread for us non-scripter types?
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
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6632
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

Thanks Diziet, I just updated it a little bit with a couple of corrections for galactic hyperspace behaviour.

Please note that this script is strictly for testing. If you just want to play the game, maybe it's best to leave it out. Otherwise, be sure you understand what it does before starting to report bugs in the game that could be expected behaviour as a result of installing this script. This is directed to the more experienced OXPers and testers.
User avatar
Lestradae
---- E L I T E ----
---- E L I T E ----
Posts: 3095
Joined: Tue Apr 17, 2007 10:30 pm
Location: Vienna, Austria

..

Post by Lestradae »

Wow, that looks like a VERY useful new utility. I'm off playing with the shiny new toy :D

8)

L
Post Reply