mIRC Home    About    Download    Register    News    Help

Print Thread
#8675 28/01/03 10:47 PM
Joined: Dec 2002
Posts: 68
P
Babel fish
OP Offline
Babel fish
P
Joined: Dec 2002
Posts: 68
Why will this not work?

Code:
on 1:CHAT:*:{
  if (%create. $+ [ $nick ] == on) && (%cuser. $+ [ $nick ] == on) {
    msg =$nick test
  }
}


I have the vars

Code:
%create.phrozenfire on
%cuser.phrozenfire on 

#8676 28/01/03 11:08 PM
Joined: Dec 2002
Posts: 3,138
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 3,138
Code:
on 1:CHAT:*:{
  if ($eval(% $+ create. $+ $nick,2) == on) && ($eval(% $+ cuser. $+ $nick,2) == on) {
    msg =$nick test
  }
}


#8677 28/01/03 11:57 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Although Collective's example will work, I'll just point out what you did wrong: You had the %create. $+ [ $nick ] - however you needed an extra pair of evaluation brackets in there so that the $+ was evaluated beforehand aswell like so: %create. [ $+ [ $nick ] ].


Spelling mistakes, grammatical errors, and stupid comments are intentional.
#8678 29/01/03 02:41 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Also, to get at the value stored in that built variablename, you also have to evaluate the whole thing with another pair of [ ] around the entire expression.
  • if ( [ %create. [ $+ [ $nick ] ] ] == on) { commands }
Much easier is the newer format using $eval() and $+():
  • if ($eval($+(%,create.,$nick),2) == on) { commands }
Once you get used to looking at that form of the expression, it is MUCH clearer. With only 2 or 3 evaluation brackets, it doesn't look like you're saving much; if you're going to have to keep using that value, then put it into a temp var %var = $eval($+(%,create.,$nick),2) .. work with the %var throughout the course of your script (so you don't have to keep evaluating it over and over) and then re-store the value at the end of your script back into the variable it's supposed to be in.
  • set $+(%,create.,$nick) %var
Once you get used to it, it's MUCH, MUCH easier to get consistent results this way. Years ago, when all we had was [ ] to do this sort of thing, sometimes you had to play with how you created your variables to get the variable name correct and get it to store the correct value in that variable.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#8679 29/01/03 02:54 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
No, the extra brackets wouldn't be needed because with evaluation brackets you're changing the order of the evaluation. So by the time the 'normal' parsing of the line goes through the variable reads as %create.nickname as if it had been hardcoded into the line, so the variable is evaluated as normal to return its value.

But yes, this is a case where re-ordering isn't required and $eval() and $+() make much cleaner, more 'mIRC-styled' code.


Spelling mistakes, grammatical errors, and stupid comments are intentional.

Link Copied to Clipboard