mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
I was wondering if there was an identifier or a strategy to find out the line or name of a script that called the current script.

I can't really think of any better way of wording that, so here's an example:

caller {
say This script calls another script.
called
}

called {
say The script that called this script was: "caller"
say The line number of the script that called this script was "1"
}

The only way that I can think of that does that, is to actually send the line number to the called script. That's kind of bothersome, though.

Thanks a bunch in advance.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You can use $script and $scriptline, but you would need to send that to the alias.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
You mean to say that there's nothing I can do so that the script knows what called it? I'm working on a few scripts here that would really be nice if I didn't have to have $scriptline as a parameter each and every time.

Maybe a 3rd party script would work? Something along the lines of this, maybe?

Code:
on *script* say Script $scriptname has been called from line $scriptline from the $scriptfile file


I know that's not a built in remote and that the logic fails (big time), but it would be kind of foolish to not have something like that in there.

Last edited by Chappy; 07/03/07 09:03 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
No matter how you do it, you'll need to send the information to the alias. There has been a feature request in the past for a way to get the information about what called the alias, but nothing has (yet) come of it.

Keep in mind that it is very easy to send the data to the alias anyhow. All you do is just call all aliases in your script using:

/aliasname $script $scriptline parameters

Then, always use $3- for the actual parameters rather than $1-. Yes, it's 2 more pieces of information sent to the alias, but it's not difficult to work with.

I know that isn't what you want to hear, but it's all there is until/if that gets added into a new mIRC version.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
Dang.. that feature would be really, really beneficial to what I'm trying to do.

On a side note, is there anyway to rewrite the /var command so that whenever I use the /var command, it does a little something extra? I'm writing a script that watches for variables being created, modified, etc.

I run into a few problems with the variable being evaluated when trying to initialize the variable itself. If I try to rewrite /var so that it echoes when executed, this is what will happen:

This is what I use to redo the /var script:
Code:
alias var {
  .var $1 = @3-
  echo -a $1 is now being set to $3-
}


When I try to do the script, though...

Code:
//var %i = 1


Obviously I run into some problems with %i being evaluated. It would be a hastle to have to force "%i" to not be evaluated each and every single time I want to set a variable.

Which is why I think that the only thing that would work is to rewrite the /var script entirely.

I'd like to rewrite the /while function for similar reasons, too... I'm sure rewriting both the /while and the /var would be very similar in terms of how-to.

Thanks again.

Edit: Right, I could have put this in a different topic, but the two ideas are somewhat similar for the end product I'm trying to get. With trying to write an mirc for loop, I ran into the problem of trying to figure out how to make new structures similar to the /while. The only way I could have done that would have been to search for the script within the text file itself and read it off from there. That lead to a few problems in the form of decreased speed and almost unnecessary scripting.

Last edited by Chappy; 07/03/07 10:06 PM.
Joined: Jan 2007
Posts: 259
K
Fjord artisan
Offline
Fjord artisan
K
Joined: Jan 2007
Posts: 259
You could do: /set -u0 %caller $script $scriptline

However it is still cumbersome.

Also, you can't rewrite mIRC functions. /var will always be /var. However, server commands like /msg can be rewritten, even though they are built into mIRC.


Those who can, cannot. Those who cannot, can.
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
Simple answer to a somewhat difficult question...

Would an on input script work by checking if $1 is /var, and then working from there to add extra functions?

Joined: Jan 2007
Posts: 259
K
Fjord artisan
Offline
Fjord artisan
K
Joined: Jan 2007
Posts: 259
Yes, that could work. However, commands in a script wont be changed.


Those who can, cannot. Those who cannot, can.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
If you were just interested in /set variables, you could check the last line in the variables file to see if it's changed every so often and use that to handle it. But for /var's, I'm not sure that there is a good method if you want it to always display no matter whose script it is that's creating the variable.

Of course, you could make a script that can automatically insert such echo lines into any script wherever a /var is located. It would need some good checking to make sure it does it correctly, but it could be done.

I think you may be better off just requesting that a switch for the /var command (and /set) to echo the information. I don't think that would be hard for Khaled to add and could possibly be useful to others as well.


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Quote:
I think you may be better off just requesting that a switch for the /var command (and /set) to echo the information. I don't think that would be hard for Khaled to add and could possibly be useful to others as well.

The -s switch already exists for this purpose.

To the OP: The /var command is actually an internal alias to the equivalent of /set -l $1 $3. You can alias /set and check for the -l switch (which means it's local) however I don't know of a way to then actually set the variable from within that alias. You can set global variables from within a custom /set alias but not local ones. Maybe someone else knows a way...


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Interesting. I've never needed to echo it, so didn't look up what kinds of switches /var might have. Good to know if I ever need that.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2005
Posts: 14
C
Chappy Offline OP
Pikka bird
OP Offline
Pikka bird
C
Joined: Sep 2005
Posts: 14
Would something like this work? I don't have mIRC in front of me so I can't check it directly.

Code:
alias var {
  say Variable $1 has been set to $3
  set -l $1 $3
}


It looks way, way too simple for solving my problem.

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
The issue comes about when you then try and set the local variable - you'll create a variable local to your custom alias instead of local to the scope that called it. AFAIK there's no way around that.

Last edited by starbucks_mafia; 08/03/07 10:19 PM.

Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
According to starbucks_mafia, there is a -s switch that deals with displaying the variable's information. You might want to look into it. I don't have mIRC available to read up on that.


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
yeah -s switch works on most things.

"The -s switch makes the command display the result."

Quote:
set -s %buddy DJ_Sol
* Set %buddy to DJ_Sol


var -s %buddy = DJ_Sol, %train = BO
* Set %buddy to DJ_Sol
* Set %train to BO

Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
You can sorta come around this with -u0 but this makes it available up untill the highest calling alias which might have unwanted results.
i.e
Code:
alias set { 
  if (-l == $1) set -su0 $2-
  else set $1-
}
alias testvar { 
  var %hello = hello, %test = test
  echo -a hello = %hello
}
alias testvar2 { 
  testvar
  echo -a hello = %hello
}

calling /testvar all seems well but when calling testvar2 you dont want %hello avaliable there.

Another issue with this is that %var = value syntax will always set it to global

Last edited by Mpdreamz; 09/03/07 10:51 AM.

$maybe

Link Copied to Clipboard