mIRC Homepage

If/Then question

Posted By: Kooky

If/Then question - 25/06/15 06:56 AM

So I'm having an issue with a script snip.
This line

if ($2 = null) {$2 = 6}

I'm using a wrong variable. The idea is if no other number is set for $2 I want $2 to equal 6. Otherwise, it's the number set in the script command.
Posted By: Sakana

Re: If/Then question - 25/06/15 08:30 AM

Use this:

if ($2 == $null) { var %2 = 6 }
Posted By: splinny

Re: If/Then question - 25/06/15 08:41 AM

$iif($2,$2,6)
Posted By: Wims

Re: If/Then question - 25/06/15 12:21 PM

And you get 6 when $2 is 0

Never use $iif unless speed execution doesn't matter and it really avoids repetition

I like Sakana's idea
Code:
var %2 = $2
if (%2 == $null) %2 = 6
Posted By: splinny

Re: If/Then question - 25/06/15 01:16 PM

Ok,
Code:
$iif($2 != $null,$2,6)
Posted By: Wims

Re: If/Then question - 25/06/15 02:31 PM

Yeah but you are still using $iif, the suggestion was to never suggest to someone to use $iif unless speed execution doesn't matter AND it makes the code clearer/avoids repetition, because $iif is much much slower than /if
Posted By: Kooky

Re: If/Then question - 06/07/15 02:07 AM

On the same lines as this, if I want a different variable set if letters and not numbers are used, how would I do that?

I'm looking for the variable segment that states that, but I cannot find it.

As in..

if $2 is a word or series of words and not a number then.. the script does another thing...

Looking for the variable that means "no numbers included, only the alphabet"
Posted By: Sakana

Re: If/Then question - 06/07/15 07:24 AM

You need a regular expression. This one does what you want (only triggers if all characters in $2- are either letters or spaces)


Code:
if $regex($2-,/^([A-Za-z\s]*)$/g) { echo -a $regml(1) }
© 2022 mIRC Discussion Forums