mIRC Homepage
Posted By: CraZyHanD $Calculating - 10/11/05 03:39 AM
The help file for $calc doesnt help at all.
The example shown:
$calc(3.14159 * (2 ^ %x % 3) - ($ticks / (10000 + 1)))

Is confusing. Can someone explain what "* ^ %" and how these and other functions work.

Like how can you add 1 to 1, then add 1 to 2 then add 1 to 3.

And can you add $files in the $calc?
Ex: $calc($read(Numbers.txt) + $read(Numbes.txt))
Posted By: benjy355 Re: $Calculating - 10/11/05 03:51 AM
mmkay... Computer codes for calculation: :P
* = Multiply
^ = to the power of (2^3=8)
/ = Divide
% = The beginning of a variable, has nothing to do with math (%cows / %moos.per.cow)

Question 2:
yes, but if anything it reads isn't a number (i believe this will happen), it will come out as 0 no matter what ^_^
Posted By: RusselB Re: $Calculating - 10/11/05 03:57 AM
+ addition
- subtraction
* multiplication
/ division
^ exponents
% <not a clue>

You might be able to do the example you gave, presuming that the information read from those files were numbers

Hope this helps, and if you have any other questions please ask and please be as specific as possible.
Posted By: CraZyHanD Re: $Calculating - 10/11/05 04:01 AM
If I used $calc($Read(Numbers.txt) + $Read(NUmbers.txt)
Is there a way I can strip out all the words so I it only shows numbers.
Can isnum commands be used in this situation?
Posted By: DaveC Re: $Calculating - 10/11/05 04:25 AM
Quote:
% = The beginning of a variable, has nothing to do with math (%cows / %moos.per.cow)


Not in his example it doesnt, and really u should have looked a bit harder than just saying it is the start of a variable, I mean the example he gave it the one from the help file /HELP $CALC

% is the modular of something (remainder after division)

//echo -a $calc(1234 % 10)
4
//echo -a $calc(1234 % 999)
235

Quote:
yes, but if anything it reads isn't a number (i believe this will happen), it will come out as 0 no matter what ^_^


close, calculations seem to work up tell a non numeric / non valid calculation is incountered
//echo -a $calc(2 * 123 * 10)
2460
//echo -a $calc(2 * 123 * 10x)
2460
//echo -a $calc(2 * 123x * 10)
246
//echo -a $calc(2x * 123 * 10)
2
Posted By: RusselB Re: $Calculating - 10/11/05 06:37 AM
Learn something new everyday. I've got a few codes that use the remainder, and I was getting it the hard way.
Posted By: DaveC Re: $Calculating - 10/11/05 12:39 PM
eeewwww not

var %result = $calc(%value - $int($calc(%value / %divisor)) * %divisior)

lol, damn i used to do that too.!
Posted By: Riamus2 Re: $Calculating - 10/11/05 02:27 PM
Heh! % is VERY useful. I use it in my $DateXpander script to handle the leap years. smile

----------------

Anyhow, as far as adding files...

Do you want to add the number of files? Or all the numbers in a file? If the latter, how is the file formatted? If you give an example of the format of the file and how you want things added from within it, we can help with that. It's hard without an example to work with.
Posted By: CraZyHanD Re: $Calculating - 10/11/05 10:13 PM
Can you add $calc or read in the middle of a message like
Code:
msg $chan Roll: $calc($+($read(Numbers.txt) - $Read(Numbers.txt)))

And Can you replace a number with another number like Replace 1 with 200 without using a variable.
Posted By: DaveC Re: $Calculating - 11/11/05 12:19 AM
Quote:
Can you add $calc or $read in the middle of a message like


yes

Quote:
msg $chan Roll: $calc($+($read(Numbers.txt) - $Read(Numbers.txt)))


You dont need that $+( ) and infact that may even cause problems, not this time but in other occasions.
You may also be encountering a far more subtle problem also that your unliekly to be aware of, I well deal with this first.

Im assuming the Numbers.txt file contains a list of numbers one per line, if this is the case you can not correctly choose a random line from this file using $read(Numbers.txt)
the reason for this is if the first line of a file using $read has a number in it, it is considered to be the total number of lines in the file. example
--- Numbers.txt --
3
A
B
C
D
E
--- Numbers.txt --
As far as $read(Numbers.txt) is concerned that file has 3 lines, being the lines A B & C

HOW TO FIX IT ---> $read(Numbers.txt , t ) the t switch tells mirc to ignore any first line with a number on it, its just "t"ext

YOU SHOULD ALSO DO ---> $read(Numbers.txt , nt ) the n switch tells mirc to not evaluate the line (this is unlikely to be a concernt to you here but putting it in is good practice)


Ok so now you have a more useable $read I can explain what it does (broardly) in a line such as...
msg $chan Roll: $calc($read(Numbers.txt,nt) - $Read(Numbers.txt,nt))

The first $read(Numbers.txt,nt) this reads that file pulls a line out at random and replaces the $read(Numbers.txt,nt) with the contents of the line, i assume the lines are numbers in your case, but they can be anything on the line of the file
The second $read(Numbers.txt,nt) does the same, and may choose the same line or any other line in the file, its random.
Lets assume it chose two lines the contents of each being a number and those two numbers were 17 and 9, so your line then looks like this
msg $chan Roll: $calc(17 - 9)

The $calc(17 - 9) well this is a calculation so it goes 17 - 9 = 8, and replaces the $calc(17 - 9) with the 8, leaving you with
msg $chan Roll: 8

and the $chan is replaced with the channel, lets assume here its #rollingnumbers so you end up with
msg #rollingnumbers Roll: 8

And thats what mIRC sends to the irc server.


Quote:
And Can you replace a number with another number like Replace 1 with 200 without using a variable.


I dont under stand in what context you are meaning this.
I well say, if you can set a variable to a value and then display that variable in a line of text, you can almost certianly just place the same code as what you did to set the variable into the line of text. (with one exception, variables can be calculated with out using $calc() while showing it in a line you must use this)
ex1:
var %name = " $+ $me $+ "
echo -a my name is %name
echo -a my name is " $+ $me $+ "
my name is "DaveC"
my name is "DaveC"


ex2: (the exception)
var %IQ = 101 - 50
echo -a my IQ is %IQ
echo -a my IQ is 101 - 50
echo -a my IQ is $calc(101 - 50)
my IQ is 51
my IQ is 101 - 50
my IQ is 51


The reason for the exception to the rule is becuase mIRC can in no way tell what you might want as part of the calculation and not.
the line might have looked like echo -a Test results # 1 - $calc(%score1 / 100 ) percentage written with out $calc( ) that would read echo -a Test results # 1 - %score1 / 100 percentage was mIRC to think you wanted to do $calc(1 - %score1 / 100) or not, it doesnt know so it doesnt do any calculation.
of course using the line var %IQ = $calc(101 - 50) is perfectly fine, I infact do that all the time just so should i want to cut the calcualtion out and display it on a line i can with out having to add thr $calc( )
Posted By: RusselB Re: $Calculating - 11/11/05 12:26 AM
Yep, but I'm in the process of changing all of those to using that "new" method.
Posted By: Riamus2 Re: $Calculating - 11/11/05 03:44 PM
Are you trying to do a dice rolling script or something?

And, do you know about $rand? If you're $reading random numbers from a text file and if those numbers include numbers that do not skip (e.g. 10,11,12,13,14 instead of 10,14,17,23,24), then you can just use $rand.

//echo -a $rand(10,19)
//echo -a $calc($rand(1,100) - $rand(1,19))
Posted By: gliX Re: $Calculating - 12/11/05 03:26 AM
Here's an easy script for calculating. It includes every function (add, subtract, multiply, divide, exponents, and probably more)

Quote:
on *:TEXT:.calc *:#: msg $chan $nick $+ : $calc($2-)


Example: .calc (3.14159 * (2 ^ %x % 3) - ($ticks / (10000 + 1)))

Edit: This is in response to crazyhand
Posted By: Riamus2 Re: $Calculating - 14/11/05 03:19 PM
I think I'd be careful of using that script... I believe that you can use brackets to make it run commands on whoever has that script... commands like QUIT or other worse things. I could be wrong, but it's something to be aware of.
Posted By: genius_at_work Re: $Calculating - 15/11/05 07:33 AM
% is modulus division

The / operator returns a number with a decimal. Example:

$calc(32 / 5) = 6.4

The % operator only returns the remainder. Example:

$calc(32 % 5) = 2 (30r2)

This can be useful if you want to figure out whether one number is a multiple of another. For example, if some event happened repeatedly, but you only wanted to display it once every 5 occurances (and also wanted to count total occurances), you could use a code like this:

on *:EVENT:{
if (%events % 5 == 0) echo -a something happened
inc %events
}

In this example, if %events was a multiple of 5 (5,10,15,etc) then the /echo would execute. Due to the location of the /inc line, the first occurance of the event would also be displayed because 0 % 5 = 0. To prevent this, the /inc line could be moved above the /if line.

-genius_at_work
Posted By: Mpdreamz Re: $Calculating - 15/11/05 11:11 AM
i'd use
// v2 is a multiple of v1
\\ v2 is not a multiple of v1
in those cases

% can also be useful in massmodes to find out how much people remain be to be mode'd at the end of the loop.
var %ops = $opnick($chan,0) , %remainder = $calc(%ops % $modespl)
© mIRC Discussion Forums