mIRC Homepage
Posted By: Ninko Nickname as the variable name - 24/09/09 02:41 AM
Hi all,
How do you use $nick to make up a variable name?

Thanks


Ninko
Posted By: RoCk Re: Nickname as the variable name - 24/09/09 03:30 AM

Give an example of how you want to use it.
Posted By: Ninko Re: Nickname as the variable name - 24/09/09 03:37 AM
Hi RoCk,
So I can store info against a certain user, eg if say 'user123' started a command I would like to create a variable called say, %test_user123

Thanks


Ninko
Posted By: RusselB Re: Nickname as the variable name - 24/09/09 07:01 AM
Code:
on *:text:!*:#:{
  set $+(%,$nick) $1-
}

When a nick issues a command starting with the ! character, then the command and the parameters for the command are stored in a variable name for the person that issued the command.

To reference the value of the variable, you would use something like
Code:
on *:text:!view*:?:{
  if $nick == my_nick {
    .msg $nick $$2 $iif(!$($+(%,$$2),2),has not issued a command,has issued command $v1)
  }
}

Posted By: Ninko Re: Nickname as the variable name - 24/09/09 11:31 AM
Hi RusselB,
Thanks for your help, thats what I wanted. I was close to how I was trying to get it to work. The way I was doing it would have made...

Code:
on *:text:!*:#:{
  set $+(%,$nick) $1-
}

Become...

Code:
on *:text:!*:#:{
  $+(%,$nick) = $1-
}

Which returned an error for me, not actually sure why, I'm sure you lot know why though lol.

Thanks


Ninko
Posted By: RusselB Re: Nickname as the variable name - 24/09/09 03:58 PM
Error is probably due to the fact that there's no set command in the line, so mIRC doesn't know that you want to set the variable.

Please note that with this type of variable, you can not use the /var command to make them local variables.
Posted By: qwerty Re: Nickname as the variable name - 24/09/09 04:55 PM
Originally Posted By: RusselB
Please note that with this type of variable, you can not use the /var command to make them local variables.

You can, just not with $+(); plain old $+ works:

//var -s % $+ $me 42

That said, it makes little sense to create dynamic local variables.
Posted By: Wims Re: Nickname as the variable name - 24/09/09 04:58 PM
Can also with $+() form using set -l
Posted By: qwerty Re: Nickname as the variable name - 24/09/09 04:59 PM
Yeah, I just avoided using an undocumented feature as an example.
© mIRC Discussion Forums