mIRC Home    About    Download    Register    News    Help

Print Thread
$calc problem #178330 08/06/07 09:37 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
I have a small problem with my code, i inc a %var. The %var is set to 10, how ever when it gets to 7 i want it to react 1 time, how ever if i use if ($calc(%test - 3) > $+(%, test., $nick))) , then it triggers all the way up to 10, it result in that it will be triggered 3 times, but i just want it to trigger 1 time, then no more, if i use == it wont react at all, any ideas?


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: $calc problem [Re: sparta] #178332 08/06/07 10:00 PM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
You need to evaluate the '$+(%, test., $nick)':

Code:
if ($calc($test - 3) > $($+(%, test., $nick), 2)) {

Re: $calc problem [Re: Bekar] #178333 08/06/07 10:06 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
Still same result, it triggers 3 times up to 10..
Code:
if ($calc($test - 3) > $($+(%, test., $nick), 2)) { }

the > result in that it triggers on everything abow 7 ..


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: $calc problem [Re: sparta] #178335 08/06/07 10:46 PM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
.. Well, duh.. Of course it does..

> = greater-than.


Use either ==, or >= and then reset %test.$nick afterwards.

Re: $calc problem [Re: sparta] #178336 08/06/07 10:49 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
$test should be %test. I'm still not sure exactly what you're trying to accomplish from your description, so this may be all that's needed, or more may be necessary. If you need more, please try to explain some more of what's going on. You said that once it hits 7, you want it to react once, but I'm not sure what you mean.


Invision Support
#Invision on irc.irchighway.net
Re: $calc problem [Re: Riamus2] #178397 09/06/07 11:11 PM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
I need to match a %var, if that %var is less then 10, to be exact 3 less then 10, then i want it to react and do one command one time, now it does a react 3 times due

if ($calc(%test - 3) > $($+(%, test., $nick), 2)) { }

the > tells if its more then 7, then it should react, and it reacts on 8 - 9 and 10 .. i only want it so send the command 1 time at 8.. like if i did
set %test 8
if (%test == 8) { echo -a the test var is 1 more then 7, so it's 8 and i reacted on that }


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: $calc problem [Re: sparta] #178407 10/06/07 01:30 AM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Why not just do?:
Code:
if ($($+(%, test., $nick), 2) == 8) { }


Or:

Code:
if ($calc(%test - 3) == $($+(%, test., $nick), 2)) { }


Depending on what you're trying to do.


Invision Support
#Invision on irc.irchighway.net
Re: $calc problem [Re: Riamus2] #178425 10/06/07 08:18 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
I trying to do this:
Code:
%msgpro Normal
%msga 10
%msgu 60

on *:text:*:?:{
  if (%msgpro != Disabled) {
    if ($nick == Q) || ($nick == NickServ) || ($nick == X) || ($nick == W) { goto end }
    if ($($+(%, msg., $nick), 2) > %msga) { goto flood }
    if ($calc(%msga - 3) == $($+(%, msg., $nick), 2)) { .notice $nick Slow down a bit. }
    inc -u $+ %msgu $+(%, msg., $nick)
    goto end
  }
  :flood
  .ignore -wnu120 $nick 3
  grcho $nick is ignored for 2 minutes, possible notice flood.
  .notice $nick You being ignored for 2 minutes, possible notice flood.
  :end
}

and i want to warn people befor they are ignored. And maybe someone know a bether cleaner way to do what i want, and by the way, if i change "if" to "else if" the code wont be triggered at all, how come? the part if ($nick == Q) bla bla .. then the line below that one.


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: $calc problem [Re: sparta] #178428 10/06/07 08:51 AM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
Wow.. Goto's.. Haven't seen them for a while..

Code:
ON *:TEXT:*:?: {
  if ((%msgpro != Disabled) && (%msga > 0)) {
    if ($istok(Q NickServ X W, $nick, 32)) { return }
    if ($($+(%, msg., $nick), 2) == %msga) { 
      .ignore -wnu120 $nick 3
      grcho $nick is ignored for 2 minutes, possible msg flood.
      .notice $nick You are being ignored for 2 minutes, possible msg flood.
    }
    elseif ((%msga > 5) && ($calc(%msga - 3) == $($+(%, msg., $nick), 2))) {
      .notice $nick Slow down a bit.
    }
    inc -u $+ $iif(%msgu > 0, $v1, 60) $+(%, msg., $nick)
  }
}

Ths should do what you're after, and also inhibit the code from multiple-flood-triggering.

It also gets over the issue of someone setting '%msga' low, and thus sending 'Slow down a bit.' way too early.

It also doesn't use ugly GOTO's.. wink

[Typo's edited]

Last edited by Bekar; 10/06/07 09:05 AM.
Re: $calc problem [Re: Bekar] #178429 10/06/07 08:56 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
thnx, i will try understand ur code, then i know how to NOT use goto's wink

Found a nice error in ur code m8 wink ON *:TEXT:*?: wouldent work, need to be ON *:TEXT:*:?: wink u forgot a : smile

Last edited by sparta; 10/06/07 09:01 AM.

if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
Re: $calc problem [Re: sparta] #178430 10/06/07 09:01 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Code:
on *:text:*:?:{
  if (%msgpro != Disabled) {
    if !$istok(Q Nickserv X W,$nick,32) {
      if ($($+(%,msg.,$nick), 2) > %msga) {
        .ignore -wnu120 $nick 3
        grcho $nick is ignored for 2 minutes, possible notice flood.
        .notice $nick You're being ignored for 2 minutes, possible notice flood.
      }
      elseif ($calc(%msga - 3) == $($+(%,msg.,$nick), 2)) { .notice $nick Slow down a bit. }
      inc -u $+ %msgu $+(%, msg., $nick)
    }
  }
}

Sometimes changing from multiple if's to if/elseif requires a re-write of the format of the code.

I noticed that you have the command grcho in your code. I didn't know if that's a custom alias that you have, or a typo, so I left it alone.

I also made the presumption that if %msgpro == Disabled, then the entire code would be ignored, rather than how you have it, where the :flood section would still be run irrelevant.

Re: $calc problem [Re: RusselB] #178431 10/06/07 09:04 AM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
Wow.. How'd I read 'grcho' as 'gecho'.. *sighs*

And yeah, sorry for the typo :P

RusselB, nice thought on the !$istok() smile Didn't think to use it that way.

Re: $calc problem [Re: sparta] #178432 10/06/07 09:06 AM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
Originally Posted By: sparta
thnx, i will try understand ur code, then i know how to NOT use goto's wink

If you have any questions about it, ask! Happy to explain..

Re: $calc problem [Re: Bekar] #178433 10/06/07 09:31 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
While GOTO's are frowned upon, generally, there are times when they actually make for better code. There are a couple of Tutorial examples in this section of Hawkee which show fairly good examples as to when GOTO is actually a preferred method, as well as why.

Re: $calc problem [Re: RusselB] #178435 10/06/07 10:18 AM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
.. I don't agree with them ..

But that's ok, every one is allowed to have an opinion wink

Re: $calc problem [Re: RusselB] #178436 10/06/07 10:20 AM
Joined: Feb 2003
Posts: 3,432
S
sparta Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
Why does this work:

inc %test

while this dosent?

inc -u $+ %ttime %test

%ttime is set to the 60 .. i get this error:

* /inc: insufficient parameters

how ever if i change the code to:

inc -u60 %test

then it working just fine.

but the only thing i added is a time when the %var should be removed as a %var. someone that can explain?

;------ edit

i solved it. inc $+(-u,%ttime) %test

Last edited by sparta; 10/06/07 10:33 AM.

if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }