Difference between revisions of "Enable"

From Scriptwiki
Jump to: navigation, search
 
(Added example for menu usage for one channel and notes section)
 
Line 8: Line 8:
 
  /disable #help*
 
  /disable #help*
 
Disables all groups starting with the word ''help''.
 
Disables all groups starting with the word ''help''.
 +
 +
The example below shows how to enable or disable a block of code ''(menu item in this example)'' only when #my_channel is active.
 +
;Trigger when a windows focus is changed.
 +
on *:[[On active|active]]:*: {
 +
  ;If #my_channel is the channel that is now the active window, enable the group.
 +
  [[if]] ([[$active]] == #my_channel) .enable #MyChannelActive
 +
  ;Else if #my_channel is the last active channel disable the group.
 +
  elseif ([[$lactive]] == #my_channel) .disable #MyChannelActive
 +
}
 +
 +
#MyChannelActive off
 +
menu channel,nick {
 +
  My Menu Option: DoCommand
 +
}
 +
 +
;You can put your commands or other events in the group also.
 +
[[alias]] -l DoCommand { [[echo]] -ag We've done the command. }
 +
#MyChannelActive end
 +
 +
== Note ==
 +
You can not break up an event with a group, you can only put whole events in a group.
 +
Below is an example of broken code:
 +
on *:[[On text|text]]:hello:#: {
 +
  #Anti-Spam on
 +
  disable #Anti-Spam
 +
  [[msg]] # Hello [[$nick]]
 +
  #Anti-Spam end
 +
  .[[timer]]ANTISPAM 1 5 enable #Anti-Spam
 +
}
 +
The above code is incorrect, below is an example of how to correctly use groups in this fashion.
 +
#Anti-Spam on
 +
on *:text:hello:#: {
 +
  disable #Anti-Spam
 +
  msg # Hello $nick
 +
  .timerANTISPAM 1 5 enable #Anti-Spam
 +
}
 +
#Anti-Spam end
 +
 +
Note that although you're disable a group from inside the same group you're disabling the rest of the code block continues to execute.
 +
When you disable a group it stops the events from triggering, although the already triggered groups continue as if the groups enabled.
 
== See Also ==
 
== See Also ==
 
* [[Groups|/groups]]
 
* [[Groups|/groups]]
 
[[Category:Commands]]
 
[[Category:Commands]]

Latest revision as of 12:50, 21 June 2008

Enables or disables the specified groups in all scripts.

/enable <group1 group2 ... groupN>
/disable <group1 group2 ... groupN>

You can also specify a wildcard to enable/disable all matching groups.

Example

/enable #one #two #three

Enables groups #one, #two and #three within any loaded scripts.

/disable #help*

Disables all groups starting with the word help.

The example below shows how to enable or disable a block of code (menu item in this example) only when #my_channel is active.

;Trigger when a windows focus is changed.
on *:active:*: {
  ;If #my_channel is the channel that is now the active window, enable the group.
  if ($active == #my_channel) .enable #MyChannelActive 
  ;Else if #my_channel is the last active channel disable the group.
  elseif ($lactive == #my_channel) .disable #MyChannelActive
}

#MyChannelActive off
menu channel,nick {
  My Menu Option: DoCommand
}

;You can put your commands or other events in the group also.
alias -l DoCommand { echo -ag We've done the command. }
#MyChannelActive end 

Note

You can not break up an event with a group, you can only put whole events in a group. Below is an example of broken code:

on *:text:hello:#: {
  #Anti-Spam on
  disable #Anti-Spam
  msg # Hello $nick
  #Anti-Spam end
  .timerANTISPAM 1 5 enable #Anti-Spam
}

The above code is incorrect, below is an example of how to correctly use groups in this fashion.

#Anti-Spam on
on *:text:hello:#: {
  disable #Anti-Spam
  msg # Hello $nick
  .timerANTISPAM 1 5 enable #Anti-Spam
}
#Anti-Spam end

Note that although you're disable a group from inside the same group you're disabling the rest of the code block continues to execute. When you disable a group it stops the events from triggering, although the already triggered groups continue as if the groups enabled.

See Also