mIRC Home    About    Download    Register    News    Help

Print Thread
Optional parameters in the middle #179554 24/06/07 07:14 PM
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

Re: Optional parameters in the middle [Re: endlos] #179555 24/06/07 07:16 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
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
Re: Optional parameters in the middle [Re: Riamus2] #179559 24/06/07 07:49 PM
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

Re: Optional parameters in the middle [Re: endlos] #179567 24/06/07 08:41 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
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?

Re: Optional parameters in the middle [Re: endlos] #179569 24/06/07 10:00 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
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
Re: Optional parameters in the middle [Re: RusselB] #179595 25/06/07 10:51 AM
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

Re: Optional parameters in the middle [Re: endlos] #179606 25/06/07 01:30 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
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
Re: Optional parameters in the middle [Re: qwerty] #179609 25/06/07 02:08 PM
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

Re: Optional parameters in the middle [Re: endlos] #179611 25/06/07 02:17 PM
Joined: Jun 2007
Posts: 933
5
5618 Offline
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)

Re: Optional parameters in the middle [Re: endlos] #179612 25/06/07 02:19 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
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
[SOLVED] Re: Optional parameters in the middle [Re: qwerty] #179613 25/06/07 02:28 PM
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!