But it is happening when any script is saved, not just a script that is using a periodic timer.
For example, say I was to write a script to display a dialog (a text reminder with image) on christmas day, wishing me a happy christmas - the timer would be cancelled the next time I wrote another script!
Using same function but called from a command `test'.
run command - timer increments
make edit and save - timer stops (can also edit another random script and click save)
this should not happen. Timer should only stop when the timer is killed. (which can be done in the above script by uncommenting the End() and return and then calling command.
// test
// (c) 2024
// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/endpoints/redirect.php?page=scripts for development information.
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "test";
initData.version = "1.0";
initData.copyright = "(c) 2024";
// initData.url = "https://resource.dopus.com/c/buttons-scripts/16";
initData.desc = "test";
initData.default_enable = true;
initData.min_version = "13.0";
// Add a command to Opus
var cmd = initData.AddCommand();
cmd.name = 'test'; // command name
cmd.method = 'OnClick'; // function called
cmd.desc = initData.desc;
cmd.label = initData.name; // name shown in commands list in customize dialog
cmd.noprogress = true;
}
// Allows a script to have an event called at regular intervals
function OnPeriodicTimer(periodicTimerData)
{
var x = 0;
if (Script.Vars.Exists('x'))
x = Script.Vars.Get('x') + 1;
Script.Vars.Set('x', x);
DOpus.ClearOutput();
DOpus.Output('timer called ' + x);
}
function OnClick(clickData)
{
//End();
//return;
// set timer 1 secondfg
var log = true;
DOpus.ClearOutput();
DOpus.SetTimer(100, 1000);
}
function End()
{
var success = DOpus.KillTimer(100);
DOpus.Output('End = ' + success);
if (Script.Vars.Exists('x'))
{
DOpus.Output('Deleting x');
Script.Vars.Delete('x');
}
}
On the subject of OnPeriodicTimer in the PeriodicTimerData could we have some more properties/methods to
show time left till next event of timer id
show list of timers currently running
what to do with events that have been missed (PC has been turned off, Directory Opus not open, etc) -- run handler, do not run handler, run last x amount of missed events.
Calendar & Time based methods would be useful - to be thourough there are six principal calendars in current use. These are the Gregorian, Jewish, Islamic, Indian, Chinese, and Julian Calendars .
Some way of setting how to deal with missed events - restart timer - resume timer - resume timer with missing time subtracted.
hmmm - that is not what is happening here - oh well another only happens to me issue then.
Means I cannot have a slideshow on when coding and it is pointless doing any kind of calendar background change scripts (set dates and times of changes)
video shows slideshow at 1 second interval, then a completly unrelated script is edited and saved. (the script has no OnPeriodicTimer events).
The new timer event (and any future ones, hint, hint) need to be more stable and robust, running timers cannot be interupted or cancelled because the scripts (even the script that is being called|) is being edited.
A lot of useful scripts can be created with timer and calendar events, but not if they are not stable.
As far as robustness is concerned, have added an item to the small list of ideas above (will update it if I think of any more).
Leaving the timers initiated by a script running when you modify the said script could lead to unexpected behaviors, and may even be dangerous (trigerring actions that were not the ones meant to be on previous launch). Depending on the specific use case, it might not, but that feels right to me that by default the existing timers are stopped when the initiator script is reloaded.
@Leo : I have the impression that saving a script (e.g. any script) triggers the OnInit functions of scripts that are in a package (osp) which is the case of the BackgroundChanger. I can't try and find right now if this is related to some script I previously installed and that triggers on some events, or if it's standard behavior. If it's the later, I can't really find the reason why, but the answer might be "under the hood"