mIRC Homepage
Posted By: EviL_SmUrF wtf, cant pass numbers through $input ? - 30/01/04 07:23 AM
Code:
menu nicklist {
  .Timed Ban: {
    set %reason $input(Enter Reason, e)
    set %timeb $input(Enter Time, e)
    echo %reason
    echo %timeb
    if (%reason == $null) { halt }
    if (%timeb == $null) { halt }
    if (%timeb isnum) {
      ban -kr $snick(#,1) $calc(%timeb * 60) 2 %reason (Banned for %timeb minute(s))
      halt
    }
    echo [ERROR] Time must be a number!
    halt
  }
}


what is the deal?

everytime i do that, and try to enter "1" for %reason or %timeb it returns this:

* /echo: insufficient parameters


it works just fine if i enter letters tho instead of numbers. Why?

Thanks for your help!
Posted By: Nobodi Re: wtf, cant pass numbers through $input ? - 30/01/04 07:51 AM
It's not a problem with the $input identifier it's with how you are trying to use the echo command,

/echo [color] [-deghiNtsaqlbfnmr] [#channel|[=]nick] <text>
Prints text in the specified window using the specified color (0 to 15).

echo -a %variable
should echo the number.
Posted By: Raccoon Re: wtf, cant pass numbers through $input ? - 30/01/04 10:58 PM
In addition, here are some tips for proper coding to make things easier.

  Use var %myvar = data instead of set %myvar data in situations where you don't intend to keep the data after the alias has completed. This creates a local and temporary variable that is faster to access and wont conflict with variables from other scripts. Note that = must be used for /var and must not be used for /set

  Instead of echoing each variable on its own for debugging, use the -s switch in /var or /set.

  You are using /ban incorrectly. Your statement would UNban the user while kicking them. You want to use ban -kuN instead.

  Avoid using /halt so much, instead, try scripting in a way where you always reach the end of the event. Exceptions to this may include user input error, but I would recommend getting used to /return, as /halt will completely end your script. (I know that doesn't apply to this particular script, but I'm refering to the unnecessary /halts used after /ban)

  In a situation where input must be supplied, use $$input() instead. The extra $ makes it work like $$1 where the event returns if no input is supplied.

Code:
menu nicklist {
  .Timed Ban: {
    var -s %reason = $$input(Enter Reason, e)
    var -s %timeb = $$input(Enter Time, e)
    if (%timeb !isnum) { echo $colour(info) -a * Timed Ban: Time must be a number! | return }
    ban -ku $+ $calc(%timeb * 60) $* 2 %reason (Banned for %timeb minute(s))
  }
}


Remember to remove the var -s flags when done.

- Raccoon
Posted By: Iori Re: wtf, cant pass numbers through $input ? - 31/01/04 12:41 AM
Just a slight change smile
Code:
    if (%timeb !isnum [color:red]1-[/color]) { echo $colour(info) -a * Timed Ban: Time must be a number! | return }
ah sweet, thanks smile
Posted By: Raccoon Re: wtf, cant pass numbers through $input ? - 31/01/04 07:54 AM
A couple more changes you might enjoy,

Code:
menu nicklist {
  .Timed Ban: {
    var %reason = $input(Enter Reason, e, Timed Ban)
    var %timeb = $$input(Enter Time, e, Timed Ban, 5)
    if (%timeb !isnum 1-) { echo $colour(info) -a * Timed Ban: Time must be a number! | return }
    ban -ku $+ $calc(%timeb * 60) $* 2 %reason (Banned for %timeb minute(s))
  }
}


Here we made %reason optional by giving it only one $ for $input, and gave a default value of '5' minutes for
%timeb. This can be handy when trying to ban someone quickly.

You're welcome, grin

* Raccoon licks Iori.
© mIRC Discussion Forums