When you release a script addon, you have to be very careful that it doesn't 'just work' if you want to gain respect from the IRC community. It is not enough to correct human errors - the way to go is to prevent them from happening. That is why beta testers are so important. The worst beta tester is the author himself because he knows beforehand how it should work.
One place most scripts fail in, in terms of prevention of errors, is in dialog editboxes. It is important to apply validation and verification procedures.
Data validation checks to see if the range of data is sensible for its intended purpose. For example, if you are inputting an age of a person, validation procedures should term 310 as invalid.
Data verification checks to see if the data is likely to be correct by using an alternative source of reference. Continuing on the same example, the # character should not appear in the editbox if verification procedures are applied.
The following example assumes a dialog called 'test' with the editbox having id number 1.
ON *:DIALOG:test:INIT:*:{
unset %Editbox
}
ON *:DIALOG:test:EDIT:1:{
If ($did(1) !isnum 1-120) && ($did(1)) { Backspace }
%Editbox = $did(1)
}
alias -l Backspace {
did -r test 1
If (%Editbox) { did -a test 1 %Editbox }
}
The above example will only accept numbers between 1 and 120 and will prevent you from entering any other characters or invalid numbers (e.g. 123). This has been made through very simple use of verification and validation procedures.
An improvement that could be done is making an error message coming up on the dialog itself. Suppose id 2 is a text message displaying an error message.
ON *:DIALOG:test:INIT:*:{
did -h test 2
unset %Editbox
}
ON *:DIALOG:test:EDIT:1:{
If ($did(1) !isnum 1-120) && ($did(1)) { Backspace }
%Editbox = $did(1)
}
alias -l Backspace {
did -r test 1
If (%Editbox) { did -a test 1 %Editbox }
did -v test 2
.timer 1 4 if ($dialog(test)) did -h test 2
}
Verification is not always that easy unfortunately and can get a bit more complex in some cases. If you need to input a channel name, you must make sure that it starts with a #, & or +. Also, some characters cannot form part of the rest of the channel name (example the comma and the space).
Keeping these basic ideas in mind, you can implement verification and validation procedures quite easily. One short note if you use multiple error messages - you should ideally have only one error message on screen at a time, so when you show one remember to hide the rest.