mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2007
Posts: 66
B
beer Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Jul 2007
Posts: 66
I'm having trouble evaluating a variable where part of the name is dynamic. Broken example:
Code
var %test.playcount = 1, %test.pausecount = 2, %test.reccount = 3
var %which = pause
var %output = %test. $+ [ %which ] $+ count

I expected %output to be set to the contents of %test.pausecount ("2") but if I echo %output, I just get "pausecount". I've tried "var %output = % $+ test. $+ %which $+ count" and other variations but have yet to stumble across the secret sauce that gives me the result I'm looking for.

Any help is greatly appreciated!

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2007
Posts: 66
B
beer Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Jul 2007
Posts: 66
I've already read that and it doesn't address my question, hence why I've asked here. Whether the answer is that dynamically named variables can't be formatted the way I'm doing it, or there's a problem with how I'm trying populating it, the link lacks clarity on that.

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Originally Posted by https://en.wikichip.org/wiki/mirc/variables#Dynamic_Variable_Names
You can also get the value of a dynamic variable by using $eval, $eval allows you to force an expression to evaluate more than once, a bit like the brackets [ ], but brackets are meant to alter the order of evaluation of a line, which itself can have its own drawbacks.

$eval($+(%,<static>,<dynamic>),2)
So you would use $eval($+(%,test.,%which,count),2)

Bracket evaluation are more complex to understand, people usually get away with one single dynamic part, but in your case you kind of have two with the hardcoded 'count'

If you start with %test., you have to follow with [ $+ [ dynamic ] $+ count ]
But if count were a variable such as %count, this wouldn't work and you have to add another pair of $+ [ ]:

Code
//var %test.pausecount 2,%which pause,%count count | echo -a %test. [ $+ [ %which $+ [ %count ] ] ]
I'll change wikichip to be clearer regarding that, but the bracket evaluation page, which is linked in the article for dynamic variable, explains this all.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Feb 2015
Posts: 138
kap Offline
Vogon poet
Offline
Vogon poet
Joined: Feb 2015
Posts: 138
Code
alias t30 {
  var -s %test.playcount = 1, %test.pausecount = 2, %test.reccount = 3
  var -s %which = pause
  var -s %output = %test. [ $+ [ %which ] $+ count ]
}


GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net
Joined: Jul 2007
Posts: 66
B
beer Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Jul 2007
Posts: 66
Thank you for clarifying this! The examples given here make it much easier to understand. smile


Link Copied to Clipboard