mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2012
Posts: 14
D
d0wn Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Jan 2012
Posts: 14
i'm trying to read a %variable that countain a $identifier in it.
but isn't working

i've used: set %ono $+ $chan opened
now i want read the variable, ex: %ono#hello that return to "opened"

i didn't have such knowledge in MS
i tryed to use: return %ono $+ $chan and return %ono [ $+ $chan ] but dont works

someone know a way to do that? can be with other way diefferent of %variables, but that works like i want. thx

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Setting a dynamic variable is pretty straightforward and you have that correct. e.g. /set %var $+ $chan

Accessing the dynamic variable isn't quite as straightforward, but it's easy once you know the syntax. There are two options for this.

Code:
//echo -a $($+(%,var,$chan),2)
//echo -a %var [ $+ [ $chan ] ]


As to how they work...

The first one uses $eval() -- $() is short for $eval() -- to evaluate the dynamic variable. $+() is used to combine the items, so that leaves you with evaluating the % + var + $chan variable. You need to do this 2 times, which is where the 2 comes in. Personally, I recommend this method because []'s are really meant for order of operations and I prefer to use things for what they are really meant to do instead of using them everywhere that they work.

The second one uses []'s to evaluate the pieces. It will start in the middle and evaluate $chan, then it will expand outward and combine the evaluated $chan with %var.

As a note, both methods are equally fast. Running benchmarks on them show they both take the same amount of time even at 100,000 iterations. They both vary within the same 40ms range at 100,000 iterations after repeated tests. So it doesn't really matter which method you use.

Last edited by Riamus2; 26/01/12 11:14 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2012
Posts: 14
D
d0wn Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Jan 2012
Posts: 14
thank you, worked perfectly

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: Riamus2

As a note, both methods are equally fast. Running benchmarks on them show they both take the same amount of time even at 100,000 iterations. They both vary within the same 40ms range at 100,000 iterations after repeated tests. So it doesn't really matter which method you use.


when you're performing benchmarks to compare pieces of code with running times that are on the same order of magnitude as the overhead involved in conducting the benchmark, you may find that your results will not be very informative. in this case, it seems they happen to be rather inaccurate :P

a more precise test reveals that $($+(%,var,$chan),2) is actually 3.5 times slower than %var [ $+ [ $chan ] ]. this difference comes from the fact that $eval() is translated into $evalnext() by mIRC, which calls itself recursively once for $( , 2). %var [ $+ [ $chan ] ], on the other hand, evaluates without the extra interpretation of mIRC script. you can eliminate one of those $evalnext() calls with $evalnext($+(%,var,$chan)) - however, it is still, predictably, slower than the eval brackets version (2.5 times).

you can verify all this using my benchmark snippet - i used /benchmark -s100 100000 <code> for the above results.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
This is actually the code I used for my benchmark, though I didn't use -s100 on it. I just tested with that and my benchmarks are still running basically equal in speed. I have a very simple test...

Code:
alias test1 {
  var %v $+ $me = 1
  var %2 %v [ $+ [ $me ] ]
}
alias test2 {
  var %v $+ $me = 1
  var %2 $($+(%,v,$me),2)
}


Both give times between 140ms and 156ms. Perhaps this test isn't valid for some reason? It does nothing other than set and read a variable. I've also tested with /noop instead of setting the second variable and results are also basically equal. I definitely am not seeing 2-3x difference.


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
oof, that's more than i originally thought crazy

first off, if you were using my snippet to perform the benchmark on those aliases, did you include the -c switch to have the code interpreted as a command? if not, it will have performed /noop test1 rather than /test1 100,000 times.

now, the problem with those tests is that there is a lot more happening in both cases than what we are examining.

first of all, /test1 is called by the benchmark snippet requiring mIRC to browse through your loaded aliases until it finds 'test1'. the two /var commands are translated to /set -l and mIRC is twice asked to browse through loaded aliases again (this time looking for a custom 'set' alias). then there's the creation and assigning of two local variables.

to give you some idea of how much extra work is being performed: 100,000 iterations of /test1 take my machine 5 seconds whereas 100,000 evaluations of '%v [ $+ [ $me ] ]' takes it 900ms. it's this unnecessary 4.1 seconds that you should aim to minimize, and you can do that quite effectively with the following tests:

Code:
/benchmark -s100 100000 %v [ $+ [ $me ] ]
/benchmark -s100 100000 $($+(%,v,$me),2)


why? because rather than this:

Code:
var %m = 100000 | while (%m) { test1 | dec %m }


the alias creates and executes code such as this:

Code:
var %m = 1000 | while (%m) { noop %v [ $+ [ $me ] ] %v [ $+ [ $me ] ] %v [ $+ [ $me ] ] ... 100 times total ... %v [ $+ [ $me ] ] | dec %m }


%v [ $+ [ $me ] ] is still being evaluated 100,000 times, but in a much more direct and simplistic manner.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ok, that's it. I missed -c. smile


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard