mIRC Home    About    Download    Register    News    Help

Print Thread
#247814 27/08/14 05:01 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
After attempting to debug a fellow users script I've stumbled upon a need that mIRC seems unable to reliably meet: A script-scoped variable; similar to how locale aliases work, I'd like to see an addition that allows for variables of the same sort of 'scoping'. Currently there's only locale variables that only exist for within the coding block they are declared and global variables which can be altered by by anyone or anything.

For example, I keep a few COM instances open(for efficiency) to handle various processing tasks. To do so I use something similar to the following:
Code:
on *:START:{

  ; loop until we find a name not in use
  var %x = 1
  while ($com(JSONCOM $+ %x)) {
    inc %x
  }

  ; store the name
  set -e %JSONCOM JSONCOM $+ %x

  ; code that creates a COM instance for use later
}

alias -l JSONCOM return %JSONCOM

; Events and such that make use of $JSONCOM and the COM instance the on start created


The above script is quite easy to accidentally break by either altering or deleting %JSONCOM. This can happen quite a few different ways from an accidental "/unset %J*" to the user manually deleting it from the variable list editor



I suggest having a variable declaration that only functions from the remote script's root code block(similar to declaring events or aliases) and an assignment command, to alter/update the value, used from within code blocks. Any value given to the variable must be done by code blocks within the same script and its value shouldn't be stored when mIRC is closed. Further more, its referencing should take precedence between local and global variables:
Code:
; Declare the variables; its value being optionally specified
scriptvar %name 
scriptvar %exmp svar

on *:START:{

  ; Assigns a value to a declared scriptvar
  scripvar %name example

  ; If the scriptvar was not declared an error should be thrown stating as such.
  scriptvar %NotDeclared value

  ; scriptvars take precedence over global varaibles
  set %exmp gvar
  echo -a %exmp /* svar */

  ; local variables take precedence over scriptvars
  var %exmp lvar
  echo -a %exmp /* lvar */
}

Last edited by FroggieDaFrog; 27/08/14 05:35 PM.

I am SReject
My Stuff
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
After discussing this suggestion with a few other scripters, I feel I've over thought the implementation of it, and even more so over complicated the explanation.

The end goal is a variable that is only accessible from within the script file its created in, by any part of the script file at any time. Essentially a script-file-global variable.

Instead of adding a new construct/command to create such a variable, an additional switch to either the /set or /var command would suffice, with the additional prop of ".scriptglobal" added to the $var identifer:
Code:
;Creates the variable "%varname" so its globally scoped to the script file:
set -S %varname value

; returns $true
echo -a $var(%varname, 1).scriptglobal


As explained in the original post, its precedence is between local and global variables, so the order in which variables are looked up is: local, script global, global.


Last edited by FroggieDaFrog; 30/08/14 04:40 PM.

I am SReject
My Stuff

Link Copied to Clipboard