Eric,
It appears that the delay whilst the snapshot is being saved prevents a one-shot Timer tied to a different worldScript from firing...is this to be expected? I thought I was being clever with this script - obviously not.....
When the main worldScript wants to take a snapshot it creates a frameCallback...
Code: Select all
this.explorerClub_callback = addFrameCallback(this.explorerClub_freezePlayer.bind(this));
The callback function is this....(there is some extra logging compared to the version that Gimi has used).
Code: Select all
this.explorerClub_freezePlayer = function()
{ if (!this.explorerClub_originalPosition)
{
this.explorerClub_originalPosition = player.ship.position;
this.explorerClub_originalOrientation = player.ship.orientation;
player.consoleMessage("Explorers' Club record of "+System.systemNameForID(system.ID)+".",this.explorerClub_releasePlayer);
this.snapshotTimer = new Timer(this,worldScripts["explorer_club_snapshot.js"].explorerClub_snapshot,this.explorerClub_snapshotDelay);
this.removeCallbackTimer = new Timer(this,this.explorerClub_removeCallback,this.explorerClub_releasePlayer);
log(this.name,"Time:"+clock.absoluteSeconds + " "+this.removeCallbackTimer);
}
player.ship.position = this.explorerClub_originalPosition;
player.ship.orientation = this.explorerClub_originalOrientation;
if (this.explorerClub_snapshotTaken)
{
this.removeCallbackTimer.stop();
delete this.removeCallbackTimer;
this.explorerClub_removeCallback();
log(this.name,"Callback removed without resort to Timer");
}
}
The snapshot function itself is in the other worldScript.
Code: Select all
"use strict";
this.name = "explorer_club_snapshot.js";
this.author = "capt murphy";
this.copyright = "2011 capt murphy";
this.licence = "CC BY-NC-SA 3.0";
this.description = "Worldscript that takes a snapshot of system visited.";
this.version = "1.3";
// this worldScript does not include any eventhandlers. The function is called when appropriate from explorer_club.js. takeSnapshot is isolated in it's own script as it can sometimes result in JS timeout, and we don't want to crash the main script.
this.explorerClub_snapshot = function()
{
log(this.name,"Test of this.name in explorer_club_snapshot.js");
var filename = "Explorers_Club_snapshot_of_"+System.systemNameForID(system.ID);
worldScripts["explorer_club.js"].explorerClub_snapshotTaken = takeSnapShot(filename);
}
The timer that's failing to fire is
this.removeCallbackTimer
even when the delay is only .1 second more than the delay for
this.snapshotTimer
, which should result in the timer ending the frameCallback before the takeSnapShot function has returned true even on my fast test machine (the snapshot takes about .3 seconds to save on my machine).
I've also tried
this.snapshotTimer = new Timer(worldScripts["explorer_club_snapshot.js"],worldScripts["explorer_club_snapshot.js"].explorerClub_snapshot,this.explorerClub_snapshotDelay);
as an alternative construction for the first timer as I noticed with the original construction
log(this.name,"Test of this.name in explorer_club_snapshot.js");
was reporting back that this.name was "explorer_club.js", rather than "explorer_club_snapshot.js". But it doesn't make any difference to the timer failing to fire.