mIRC Home    About    Download    Register    News    Help

Print Thread
preventing a script from being called redundantly #200832 13/06/08 06:24 AM
Joined: Mar 2007
Posts: 40
S
silimon Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2007
Posts: 40
Hello

I have a script that's mostly offline and I want to prevent it from being called while it's running by the user. I tried checking for a global that's only in use while the script is running, but this doesn't work because mirc periodically saves globals to remote.ini.

it looks something like this;

Code:
alias examplescript {
  if (%alreadyloaded != $null) {
    echo This script cannot be loaded when it's already running.
    halt
  }
  set %alreadyloaded $true
}
; ...imagine several aliases that link together...
alias endofsamplescript {
  unset %alreadyloaded
}


This causes a few problems, the first is that if it saves the value as $true to the remote.ini file and then mirc is closed out without the script ending properly(it unsets the variable when it ends), then mirc is reloaded and loads the variable with it as $true. The other problem is that you can't load another instance of mirc and then load the script again because(assuming you're loading mirc from the same installation) it will load remote.ini.

Does anyone know a better approach to this?

Last edited by silimon; 13/06/08 06:32 AM.
Re: preventing a script from being called redundantly [Re: silimon] #200837 13/06/08 08:57 AM
Joined: Mar 2007
Posts: 40
S
silimon Offline OP
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2007
Posts: 40
I figured out one solution to this. Skip the variable altogether. Check to see if a window exists then open a hidden window (-h) of the same name immediatly afterward. It closes on program exit and won't get stored in a file for recall later on.

Re: preventing a script from being called redundantly [Re: silimon] #200843 13/06/08 01:56 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
You can use $script(filename) to determine if a script is loaded or not.

if ($script(myscript.mrc) != $null) echo myscript.mrc is loaded
else echo myscript.mrc is NOT loaded


You could also test than an alias within the script file exists.

if ($isalias(myalias).fname) echo myalias exists in $v1
else echo myalias doesn't exist

-genius_at_work

Re: preventing a script from being called redundantly [Re: genius_at_work] #200845 13/06/08 02:22 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
He's not trying to test if a script is loaded, he's trying to test if an asynchronous command is still "running" (like a socket operation).. his variable name %alreadyloaded might have been a little misleading.

To the OP:

You could have solved the loading problem (%alreadyloaded exists on start) by simply:

Code:
ON *:START:unset %alreadyloaded


As far as sharing instances goes, global vars would indeed not be able to get around that.

Another solution might be to create a hash table and check its existence much like a window

Code:
alias start {
  if ($hget(mytable,running)) { 
    echo -a RUNNING! | halt
  }

  hadd -m mytable running $true

  ; do stuff
}

alias end {
  hdel mytable running
}


This is a little cleaner in that it doesn't open a window. You can also use the hash table to store data that might be needed by the asynchronous command anyway, rather than global vars.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"