I wrote this alias to simplify reading dynamic variables. It uses a format similar to token identifiers. I'll give a few examples.
In these examples, the following are true:
This is your variable file:
%testSavage hello
%call~Jaytea~#Savage_CL world
%this.SwiftIRC.#Savage_CL mychan
Note that the first doesn't have a seperator, the second uses ~ which is $chr(126), and the third uses a period, which is $chr(46).
Evaluations will be as follows:
$vget(test,$me,0) == hello
$vget(call,$nick,$chan,126) == world
$vget(this,$network,$chan,46) == mychan
You see that using 0 will cause the snippet to not use a seperator.
If you are writing a script that uses this identifier to call a variable multiple times without changing it, I suggest doing something like the following:
var %foo = $vget(foo,$bar,46)
This is because the alias uses functions that aren't particularly fast (like the while loop) and it would be faster to use it only when needed.
If you find this useful or find any bugs, visit me in #Savage_CL on SwiftIRC or comment here.
Thanks!
PS I know this is a lot longer than it has to be and I could likely have done it in 3 lines, but I wanted to do it this way. It makes it easier to read in my opinion.
alias vget {
if (!$2) { echo -ea invalid parameters! | HALT }
var %toks = $0,%items = %toks - 1,%tokenizer = $ [ $+ [ %toks ] ],%t = 1,%name = $chr(37) $+ $ [ $+ [ %t ] ],%t = 2
while (%t <= %items) {
var %name = %name $+ $iif(%tokenizer,$chr(%tokenizer)) $+ [ $ [ $+ [ %t ] ] ]
inc %t
}
if ($(%name,2) != $null) {
return $v1
}
else {
echo 7 -ae %name is not set!
}
}
WorldDMT: I've done it that way because I see little point in specifying an ascii number when you can just put the actual character in the parameters. For example, say I have a variable called %text.#hawkee.hixxy, it's easier to use $vget(text.,$chan,.,$me) than it is to have to specify the ASCII number!
Sorry for my accent because i don't speak English well
@Firstmate on "$vget(test,$me,0)" this will return %testSavage0 but the variable is without the "0" just %testSavage
and look at his code "if %name exist return %name else echo -ea %name is not set!" so when u use return to both the variable can be "Variable not set." and noting will be returned on active window
@Fuzionx wtf are you saying!! did you think twice before telling me this dumb story?
Well his is organized so that you can supply any number of parameters, i.e. $vget(blah, test, foo, fah, words,46).
However, I agree in that a loop isn't necessary. Here was my take on it:
alias vget {
tokenize 32 $($1-,2)
var %d $iif($($+($,$0),2) != 0,$v1)
var %e $($+(%,$replace($($iif(%d,$+($,1-,$calc($0 -1)),$+($,1-,$0)),2), $chr(32), $chr(%d))),2)
if (%e) return %e
else return Variable not set.
}
Though as you mentioned, you made yours for readability :V
hi
i think no need to loop u can do it like this also
alias vget {
if (!$2) { echo -ea invalid parameters! | HALT }
var %x $iif($0 = 4,$1-3,$1-2)
if $(% $+ $replace(%x,$chr(32),$chr($(,$+($,$0)))),2) { return $v1 }
else { echo 7 -ae % $+ $replace(%x,$chr(32),$chr($(,$+($,$0)))) is not set! }
}
P.S: this is just an E.G not tested yet only to give some idea
What if you wanted to use a comma? And wouldn't you think consistency is a good thing? for example, do we use $numtok(%string,.) ?