mIRC Home    About    Download    Register    News    Help

Print Thread
#157859 29/08/06 02:58 PM
I
Ice_Aziraphale
Ice_Aziraphale
I
Hi, I'm having some problems using $calc to work out an average for me. The code I'm using is:
Code:
 
msg #You have got %TB.Correct. [ $+ [ $address($nick,4) ] ] $&
correct out of %TB.Goes. [ $+ [ $address($nick,4) ] ] tries.$&
This is from a total of %TB.Wires. [ $+ [ $address($nick,4) ] ] wires,$&
with an average of$&
$calc(%TB.Wires. [ $+ [ $address($nick,4) ] ] / %TB.Goes. [ $+ [ $address($nick,4) ] ]) wires per go.
 


This code correctly sends the numbers in the first half (or as I suspect, the text version of the numbers), but the $calc returns a 0 everytime. When doing some debugging by getting the code to msg just values such as
Code:
 %TB.Wires. [ $+ [ $address($nick,4) ] ] 
and
Code:
 $calc(%TB.Wires. [ $+ [ $address($nick,4) ] ])
, I've found that the variables return as numbers (or text) but if placed inside a $calc, they return as 0. Any thoughts?

#157860 29/08/06 05:31 PM
Joined: Mar 2005
Posts: 420
X
Fjord artisan
Offline
Fjord artisan
X
Joined: Mar 2005
Posts: 420
Quote:
I've found that the variables return as numbers (or text) but if placed inside a $calc, they return as 0. Any thoughts?


If you're trying to divide numbers & text, it will return 0.

#157861 29/08/06 06:57 PM
Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
The problem is your closing evaluation bracket is touching the closing parenthesis of the $calc() identifier.

Code:
$calc(%TB.Wires. [ $+ [ $address($nick,4) ] ] / %TB.Goes. [ $+ [ $address($nick,4) ] [color:red]])[/color]

should be:
Code:
$calc(%TB.Wires. [ $+ [ $address($nick,4) ] ] / %TB.Goes. [ $+ [ $address($nick,4) ] [color:red]] )[/color]


(highlighted in red around where the space is).

#157862 29/08/06 07:29 PM
S
SCNDRL
SCNDRL
S
if you use $eval or $() you may not mix

Click

#157863 29/08/06 08:11 PM
D
DaveC
DaveC
D
Its already been pointed out about $eval() or $() to u, but i thought id actually show u the code, and explain what you can do, in the long run its far better to use $eval() or $() as using [ [ ] ] has some dramatic side/unexpected effects in some events.

Code:
 
msg #You have got $($+(%,TB.Correct.,$address($nick,4)),2) $&
correct out of $($+(%,TB.Goes.,$address($nick,4)),2) tries.$&
This is from a total of $($+(%,TB.Wires.,$address($nick,4)),2) wires,$&
with an average of$&
$calc($($+(%,TB.Wires.,$address($nick,4)),2) / $($+(%,TB.Goes.,$address($nick,4)),2)) wires per go. 


What i have done is a 2 step thing
(1) create the variable name $+(%,TB.XXXX,$address($nick,4)) the concaternating of the parts, not the leading % is seprated to stop mirc attempting to use the contents of %TB.XXXX
(2) now i have the variable name i tell mirc to evaluate it 2 times (the first time would have been the concaternating of the $+ parts, so $() becomes %TB.XXXX.$address($nick,4) and then becomes the contents of it.
ex
var $+(%,TB.XXXX,$address($nick,4)) = 12345
//echo -a $( $+(%,TB.XXXX,$address($nick,4)) ,2)

* I have found the more complexe you start making your variables the harder it becomes to use [ [ ] ] while the simplier it becomes to use $()
Amagine if u had to become network and channel and nick specific
%TB.XXXX. [ $+ [ $network ] $+ ] . [ $+ [ $chan ] $+ ] . [ $+ [ $address($nick,4)) ] ]
vs
$+(%,TB.XXXX.,$network,.,$chan,.,$address($nick,4))

#157864 30/08/06 12:16 PM
Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
I wouldn't advise people to use $(). It's extremely bad form to use a non-descriptive identifier like $() when $eval() is available to do the same thing. Especially since it's not even documented that $() will work outside of event declarations. It makes for poor readability of code and it's difficult for new scripters to understand.

#157865 30/08/06 05:03 PM
Joined: Mar 2005
Posts: 420
X
Fjord artisan
Offline
Fjord artisan
X
Joined: Mar 2005
Posts: 420
I disagree on that. It would be better to let new scripters know that such identifier exists and that '$()' & '$eval()' works the same. Yes, $() works outside events, just like $eval does.

#157866 30/08/06 09:37 PM
D
DaveC
DaveC
D
Agreed it would have been better had i used $eval() and just mentioned that this could be shortened to $() but with the cavet of its undocumented.

#157867 30/08/06 10:03 PM
Joined: Dec 2002
Posts: 2,884
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,884
But as it's completely undocumented behaviour there's no guarantee that it will continue to work outside events in future versions of mIRC (although admittedly it's probably unlikely to be removed now for the sake of it). More importantly though, using $() creates non-descriptive code, which is bad practice in general. This becomes particularly apparent when used in conjunction with $+(), which it almost always is in dynamic variable situations such as the one described in this thread, because the two identifiers look so similar and is a common cause of typos going unnoticed.

Hardly worth saving 4 bytes over is it?

#157868 31/08/06 11:45 PM
D
DaveC
DaveC
D
but $( is so much easier to type than $eval( <snicker snicker>

#157869 01/09/06 12:10 PM
I
Ice_Aziraphale
Ice_Aziraphale
I
Thank you all. Adding the space between the "]" and the ")" worked and I'll look into changing all my code to use the $() or $eval.


Link Copied to Clipboard