mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2007
Posts: 19
E
endlos Offline OP
Pikka bird
OP Offline
Pikka bird
E
Joined: Apr 2007
Posts: 19
Hello

I can't figure this out.
"1 2 3" will always be numbers
"A" will get its value from %calc.A


!calc 1 2 3 A
Result: (1*x + 2*y + 3*z) * A

!calc 1 2 A
Result: (1*x + 2*y) * A

so typing all "1 2 3" should not be necessary, just "1 2" or "1"
(avoiding !calc 1 0 0 A).

How can I do that, as "A" wouldnt always be $$4 ?

Thanks

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
A == $0. $0 is the total number of tokens (seperated by spaces, or another character if you use /tokenize).


Invision Support
#Invision on irc.irchighway.net
Joined: Apr 2007
Posts: 19
E
endlos Offline OP
Pikka bird
OP Offline
Pikka bird
E
Joined: Apr 2007
Posts: 19
Thanks

Now I have a big problem. These are the new possibilities:

!calc 1 2 3 A Land Cruiser
Result: ((1*x + 2*y + 3*z) * A) * %calc.points.LandCruiser

!calc 1 B Monte Carlo
Result: ((1*x) * B) * %calc.points.MonteCarlo

The quantity of numbers will vary, after them only A,B,C,D are allowed and finally a name is needed (which can be 1-3 words)

How can I make the last numbers optional with this?

thanks for the help

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
What, if any limit is there regarding the number of numerics that can be supplied. I noticed that you're using x, y, & z as non-specific identifiers for a pending calculation. Are these to be returned as letters, or as calculated (ie: use them as variables). Also do you only use x, y & z, or are other letters possbile based upon the number of numerics supplied. If the latter, where do the letters start, and if there are too many numerics supplied to cover the letters allocated, do the letters repeat, or is an error expected?

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Assuming there's always going to be 1 to 3 numbers (no more, no less), you can use regular expressions to match the strings you want and capture the useful substrings to format your reply:
Code:
on *:text:!calc *:#yourchannel:{
  var %a = $regsubex(calc,$2-,/^(\d)( \d|)( \d|)( )([ABCD])((?: \w+){1,3})$/, $&
    (( $+ $remove(\1*x + \2*y + \3*z,\4+ *z,\4+ *y) $+ ) * \5) * $($+(%,calc.points.,$remove(\6,\4)),2))
  if $regml(calc,0) {
    ; result is stored in %a
    msg # %a
  }
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Apr 2007
Posts: 19
E
endlos Offline OP
Pikka bird
OP Offline
Pikka bird
E
Joined: Apr 2007
Posts: 19
RusselB

Yes the letters (x,y,x) are %variables. All are numeric values and will show One numeric result.

For example, the value expected for a pilot who won 100 Level1, 200 Level2, 300 Level3 races and so on; with an Skill Level of A (or B,C,D), all of it multiplied by a phrase (1-3 words) which will have its own variable value %calc.ThatPhrase like this:

!calc 100 200 300 0 0 0 0 A Land Cruiser
Result: ((100* %calc.r1 + 200* %calc.r2 + 300* %calc.r3 + 0* %calc.r4 + 0* %calc.r5 + 0* %calc.r6 + 0* %calc.r7 ) * %calc.A) * %calc.multiplier.LandCruiser

so ...
!calc 100 200 300 A Land Cruiser
should show the same result

I will try now the regex suggestion from qwerty, but I'm not familiar with that yet so it will take me a while.

Thanks for the help so far

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Your last post gave a clearer, different picture of what you want to do (it would have helped if you gave all that information in your first post). It does make sense now, although you still give contradictory information with respect to the last variable. Is it %calc.points.<text> or %calc.multiplier.<text> ? The following piece of code assumes the latter; you'll have to modify it yourself if you want otherwise:
Code:
on *:text:!calc *:#yourchannel:{
  if $regex(c1,$2-,/^(\d++(?: \d++)*) ([ABCD])((?: \w++){1,3})$/) {
    var %a = ( $regsubex(c2,$regml(c1,1),/(\d+)/g,\1*%calc.r\n +) ) $&
      $+(*%calc.,$regml(c1,2) *%calc.multiplier.,$remove($regml(c1,3),$chr(32)))
    ; %a contains the final expression
    msg # $calc(%a)
  }
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Apr 2007
Posts: 19
E
endlos Offline OP
Pikka bird
OP Offline
Pikka bird
E
Joined: Apr 2007
Posts: 19
WOW!

It works! Thanks smile

Just one more thing, how can I make it to work no matter people type ABCD or abcd ?

!calc 100 200 300 A Land Cruiser
!calc 100 200 300 a Land Cruiser

Joined: Jun 2007
Posts: 933
5
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Originally Posted By: endlos

Just one more thing, how can I make it to work no matter people type ABCD or abcd ?

Make the end of the regex:

{1,3})$/)

read
{1,3})$/i)

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Just add an "i" (meaning case insensitive) after the second forward slash in $regex, ie:

if $regex(c1,$2-,/^(\d++(?: \d++)*) ([ABCD])((?: \w++){1,3})$/i) {


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Apr 2007
Posts: 19
E
endlos Offline OP
Pikka bird
OP Offline
Pikka bird
E
Joined: Apr 2007
Posts: 19
Excellent!

I really appreciate your help smile

Thanks!


Link Copied to Clipboard