mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2005
Posts: 9
K
Kaepez Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
K
Joined: Feb 2005
Posts: 9
A script I'm currently trying to create requires the use of variable names in the format of:

%var.$nick

This is because I want a unique variable for each nick.

When I use $+(%var.,$nick), I can use /inc properly. However, when I try to use this text in a message, it evaluates the value of "%var." first, which is null, then appends "$nick". Thus, it returns only "$nick," which is hardly the intended effect.

I suppose saying that the script requires the use of variable names like that is an exaggeration, and I'm open to other suggestions as well, but is there any way to accomplish this?

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
did you try $eval($+(%var.,$nick),2)
short version of this command $($+(%var.,$nick),2)

look at /help $eval

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I think Mike might have missed a comma, then again i think u might have missed one as well. (unless the contents of %var holds another var name ie: %var. is "%somevarname"

Anyway heres some examples, assuming your wanting vars like %var.DaveC %var.Mikechat etc

set $+(%,var.,$nick) 1234
inc $+(%,var.,$nick)
echo $($+(%,var.,$nick),2)

* $( ,2) aka $eval( ,2) means evaluate the stuff in here twice, once makes the varaible name up, the second one looks at the contenmts of the variable.

Simpling rules are (1) break the % of the front, becuase otherwise it well try and get the contents of a var called "%var.", which is normally nothing
and (2) When you have something that refences the var like SET or INC or DEC dont add the $( ,2)
and (3) Whne you have something that wants the value of the variable add the $( ,2)

Joined: May 2006
Posts: 122
J
Vogon poet
Offline
Vogon poet
J
Joined: May 2006
Posts: 122
Use ][ brackets to evaluate the identifer within the scipt
Code:
var %something. [ $+ [ $nick ] ] = variable here

or "set" if you want keep the variable or you can use a hash table
Code:
hadd -m something $nick varible here
echo -a $hget(something,$nick)


If only women came with popup menus and online help.
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
1. The fact that you only know how to do it with brackets doesn't mean that any other way is wrong (if that's not what you thought, you ought to have mentioned "alternative way" or something of the sort - basic etiquette and common sense).

2. Your way of creating dynamic local variables is wrong because of a mirc bug: the = sign will be included in the var's value. Apart from that, you don't even need brackets there (as you don't need them in /set either).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Pray tell me a reason why you would want to create a local variable that uses a dynamicly created name like that? There maybe one but i cant think of it right now.

And regardless using [ ] and [ $+ ] around it is just ghastly, its not what there ment for just for a start, and they take up more room, it takes up more room, 95% of the time, and infact creates far more over head becuase they can cause unneeded evaluations to occur.


Link Copied to Clipboard