Jump to content

! Tutorial


Guest X-Fusion

Recommended Posts

Guest X-Fusion

I've noticed with people's scripts/addons that the ! switch is either overused, or not used at all.

 

It may be people's scripting style, but believe me ! in if's and commands works faster and is a lot cleaner.

 

First off, lets give the ! function a definition..

The ! function tells if a variable or identifier returns $null or 0. This is the big thing people miss, they believe ! is just like == $null, I repeat it is not.

 

When dealing with numbers and 0 the ! function may mess up any processing...

Sometimes it is safer to use != $null or == $null, just in case the user specifies 0.

It is safe to use the ! function when you know the result is either 0 or 1, $null or value, but when $null and 0 may combine, you should not use the ! function.

 

Let me give you some examples..

 

; ! Example -- /inputbox
; Here we know %x can either be $true, Yes button, or $false, No button
alias inputbox {
 var %x = $?!="Choose one, yes or no"
 if (%x == $true) { echo -a You said Yes! }
 if (%x == $false) { echo -a You said No! }
}

 

Above is a bad piece of code for 2 reasons.. ! can establish $true and $false, and another if() isn't needed you can simply do an else.

So using the ! function and the else function we can establish a better script..

 

; ! Example -- /inputbox2
; The ! before %x says the same as: if (%x == $false)
alias inputbox2 {
 var %x = $?!="Choose one, yes or no"
 if (!%x) { echo -a You said No! }
 else { echo -a You said Yes! }
}

 

Now in if() and other comparison functions you can leave the variable alone.. Doing this is just like the ! function it will return $true if: The variable isn't null, the variable isn't $false, and if the variable isn't 0.

 

So if you were going to use the input box without the ! function it would look like this:

 

; ! Example -- /inputbox3
; Nothing before %x says the same as: if (%x == $true)
alias inputbox3 {
 var %x = $?!="Choose one, yes or no"
 if (%x) { echo -a You said Yes! }
 else { echo -a You said No! }
}

 

Here is a common mistake done by when radio buttons or check buttons in dialogs are being called... If the radio or check is regular and doesn’t have a 2, value then you can use the ! function...

Here would be "bad" code..

 

; Example of code, not to be used.
 if ($did($dname,1).state == 1) { echo -a Checked! }
 else { echo -a Unchecked! }

 

You could use this:

 

; Same as $did($dname,1).state == 1
 if ($did($dname,1)) { echo -a Checked! }
 else { echo -a Unchecked! }

 

or..

 

; Same as: $did($dname,1).state == 0
 if (!$did($dname,1)) { echo -a Unchecked! }
 else { echo -a Checked }

 

Note: To all, I used if()'s then else events, I do realize that you can simply do the $iif() event and save time and code.. If for some reason you do not know what i mean here is the /inputbox3 example with $iif

 

; $iif Example - /inputbox3
alias inputbox3 {
 var %x = $?!="Choose one, yes or no"
 echo -a You sad $iif(%x,Yes!,No!)
}

 

You can use ! for other things besides if() events, such as returning a character that would of been evaluated.. here is what i mean..

 

; ! Example -- /iam
; When using ! after $ it will return $, and not evalute it.
alias iam {
 echo -a Used with !: $!me
 echo -a Used without !: $me
}

 

Also, you can use ! before commands..

What the ! does before commands is makes mirc use its default internal command, just in case there is already a repeat of the command..

Lets say there was an alias like:

 

alias msg msg $chan ( $+ $chan $+ ): $1-

 

Now if that alias is present each time you message a channel it will return: (#Channel): Your Message

If you do not want that and you wish to use the default mirc command in another alias, you would use:

 

; ! Example -- /!msg
alias msgc {
 !msg $active $+($chr(2),$1-,$chr(2))
}

That would bold your text messaging the channel and wouldn't message with the (#Channel). This was just simple stuff for people that were releasing their scripts, or want to approach a new way of doing things. Getting advancement in scripting by doing it this way is a much more effective way to code. It also makes you appear like you know what your doing.

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...