mIRC Home    About    Download    Register    News    Help

Topic Options
#200832 - 13/06/08 07:24 AM preventing a script from being called redundantly
silimon Offline
Ameglian cow

Registered: 05/03/07
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?


Edited by silimon (13/06/08 07:32 AM)

Top
#200837 - 13/06/08 09:57 AM Re: preventing a script from being called redundantly [Re: silimon]
silimon Offline
Ameglian cow

Registered: 05/03/07
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.

Top
#200843 - 13/06/08 02:56 PM Re: preventing a script from being called redundantly [Re: silimon]
genius_at_work Offline
Hoopy frood

Registered: 08/10/05
Posts: 1741
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

Top
#200845 - 13/06/08 03:22 PM Re: preventing a script from being called redundantly [Re: genius_at_work]
argv0 Offline
Planetary brain

Registered: 13/10/03
Posts: 3918
Loc: Montreal, QC, Canada
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"

Top