Difference between revisions of "Why doesnt my text event work"
m (Added to new category: Debugging) |
m (added link to the bracket-error-button image) |
||
Line 29: | Line 29: | ||
==Bracket Errors== | ==Bracket Errors== | ||
− | The good news is that this problem is easy to find. Simply press the button labeled {} in the top right of the scripts editor. | + | The good news is that this problem is easy to find. Simply press the button labeled [[:Image:Bracket-button.png|{} in the top right]] of the scripts editor. |
If you get a bracket missmatch error, you have probably found your problem. Bracket missmatches are caused by an uneven number of { }. Most of the time, if you have more { than } your script will still work, but any scripts below it will throw invalid command errors. If you have more } than { your script may still work but will kill any scripts below it. For example | If you get a bracket missmatch error, you have probably found your problem. Bracket missmatches are caused by an uneven number of { }. Most of the time, if you have more { than } your script will still work, but any scripts below it will throw invalid command errors. If you have more } than { your script may still work but will kill any scripts below it. For example | ||
Revision as of 08:14, 7 August 2007
So you're fairly new to scripting and cannot figure out why your simple text script does not work. This page will take you through the most common errors new (and sometimes experienced) scripters make when dealing with these events.
For the purpose of this page we will use the following script as the example:
on *:TEXT:!voice:#:if ($me isop # && $nick !isvoice #) { mode # +v $nick }
Double Events
Perhaps one of the most common "pitfalls" in event driven mIRC scripting is the use of double events. This term refers to what happens when you attempt to place two on text events, both of which you intend to trigger, in the same file. More detailed information can be found here: Common Pitfalls
In essence, given the following code:
on *:TEXT:*:#:echo -atg $nick spoke in # on *:TEXT:!voice:#:if ($me isop # && $nick !isvoice #) { mode # +v $nick }
The first one will be triggered whereas the second one will be overlooked, thus not working.
To fix this, either rearrange the order so the first one is now second, place the second in its own file (file > new in the scripts editor menus), or combine the two like this:
on *:TEXT:*:#: { if ($1 == !voice && $me isop # && $nick !isvoice #) { mode # +v $nick } echo -atg $nick spoke in # }
Triggering User
Another common mistake is people who attempt to use their own on text script. For example, if the example script was in your mIRC client's script editor and you tried to use !voice, it would not work. Only another person would be able to use this. If you want your own client to react, either create an alias or use an on input event.
alias voice { if ($me isop # && $me !isvoice #) { mode # +v $me } }
on *:INPUT:#:if ($1 == !voice && $me isop # && $me !isvoice #) { mode # +v $me }
Bracket Errors
The good news is that this problem is easy to find. Simply press the button labeled {} in the top right of the scripts editor. If you get a bracket missmatch error, you have probably found your problem. Bracket missmatches are caused by an uneven number of { }. Most of the time, if you have more { than } your script will still work, but any scripts below it will throw invalid command errors. If you have more } than { your script may still work but will kill any scripts below it. For example
on *:TEXT:!hi:#: { say hello on *:TEXT:!voice:#:if ($me isop # && $nick !isvoice #) { mode # +v $nick }
This will cause !hi to work, but also show: ON invalid command
on *:TEXT:!hi:#: { say hello } } on *:TEXT:!voice:#:if ($me isop # && $nick !isvoice #) { mode # +v $nick }
In this event !hi will work, !voice will simply not.
Also note that if you do not put spaces around your brackets, you will have the same effect, for example:
on *:TEXT:!hi:#: { say hello} on *:TEXT:!voice:#:if ($me isop # && $nick !isvoice #) { mode # +v $nick }
At first this looks ok, but since } is not spaced, it will be seen as part of the text you wish to say. !hi will say "hello}" and give you an ON Invalid command error.