mIRC Home    About    Download    Register    News    Help

Print Thread
Possible to store a command in a variable? #266682 12/01/20 07:10 PM
Joined: Jul 2007
Posts: 63
B
beer Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Jul 2007
Posts: 63
Hi,

Say you have several lines to send to a user, sometimes as /msg and sometimes as /notice. To avoid needing a bunch of duplicate lines where the only difference is "/msg" vs. "/notice", is it possible to just store the command in a variable? So, for example where:
Code
if ($something = msg) {
  /msg $nick line1
  /msg $nick line2
  /msg $nick line3
  /msg $nick line4
}
elseif ($something = notice) {
  /notice $nick line1
  /notice $nick line2
  /notice $nick line3
  /notice $nick line4
}


could be optimized with something like:
Code
var %cmd = $something
%cmd $nick line1
%cmd $nick line2
%cmd $nick line3
%cmd $nick line4


I did try the above as both "var %cmd = $something" and "var %cmd = / $+ $something" but get "Unknown command". If this isn't possible, what about sending a raw message instead of /msg|/notice?

Re: Possible to store a command in a variable? [Re: beer] #266684 12/01/20 07:38 PM
Joined: Jul 2006
Posts: 3,715
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,715
It should work.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Possible to store a command in a variable? [Re: beer] #267059 29/03/20 09:00 PM
Joined: Jan 2017
Posts: 57
KubosKube Offline
Babel fish
Offline
Babel fish
Joined: Jan 2017
Posts: 57
I do something similar, where I turn text into a command.
Here's the method I use.

Code
if (%condition == $true) {
  $eval(%cmd $nick line1)
}


The fact that the $eval identifier is not actually part of command has yet to cause me any issues.

I was warned before, however, to make sure that you are the sole person able to insert a command here.