mIRC Home    About    Download    Register    News    Help

Print Thread
#253647 25/06/15 06:56 AM
Joined: Oct 2014
Posts: 42
K
Kooky Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Oct 2014
Posts: 42
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.

Kooky #253649 25/06/15 08:30 AM
Joined: Sep 2014
Posts: 259
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Use this:

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

Sakana #253650 25/06/15 08:41 AM
Joined: May 2015
Posts: 249
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
$iif($2,$2,6)


Dont give a fish - teach to fish!
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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

Last edited by Wims; 25/06/15 12:23 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #253653 25/06/15 01:16 PM
Joined: May 2015
Posts: 249
Fjord artisan
Offline
Fjord artisan
Joined: May 2015
Posts: 249
Ok,
Code:
$iif($2 != $null,$2,6)


Dont give a fish - teach to fish!
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #253778 06/07/15 02:07 AM
Joined: Oct 2014
Posts: 42
K
Kooky Offline OP
Ameglian cow
OP Offline
Ameglian cow
K
Joined: Oct 2014
Posts: 42
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"

Kooky #253779 06/07/15 07:24 AM
Joined: Sep 2014
Posts: 259
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
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) }


Link Copied to Clipboard