Relay over-ride scripts end up having naming conflicts with other relay over-ride scripts that function on the same page. I've been considering this, and there is a simple solution which might save you (the script writer) time in the future. It is fairly simple, and would make importing the re-named script into a new "shell" script a lot less time consuming.
This will be a reference for myself and others to use. Contributions/suggestions are welcomed.
- [li]avoid global variable declarations where possible.[/li]
[li]Place all code which does something to the source in a function, and pass the source to the function as a parameter. Return the modified source.[/li]
[li]Try to use function names that will be unique to your script[/li]
[li]Place all calls to your created functions inside void main()[/li]
[li]Avoid top level commands[/li]
Here is an example. It uses my Link back to manage store at the top of the store log page script as an example. Strangely I wasn't thinking about this when I wrote the script, but it follows the ideas.
Now when another script is written to do something else on the same page, rename the file to storelogtoplink.ash, then write a new storelog.ash file as follows:
buffer addtoplink(string source)
"<td style=\"padding: 5px; border: 1px solid blue;\"><center><table>",
"<td style=\"padding: 5px; border: 1px solid blue;\"><center><table><tr><td><center><a href=\"managestore.php\">Back to Your Store</a></center></td></tr><tr><td></td></tr>"
Because void main() is not used in an imported script, we need to do nothing to the original script (unless it conflicts in some way with what the new script is doing). Not having top level commands means that we are less likely to have a command executed before it's time. Avoiding global variables means we won't end up with variable naming conflicts. The use of unique names ahead of time will reduce the chances of a naming conflict in function names. (naming all your functions which make changes to the source "modify_source" is not such a good idea.
//import new script here
//code to call new script function can be here
source = addtoplink(source);
//or it can be here
Comments, suggestions, Edits by other moderators/admins, and any improvements to this concept are not only welcomed, but will be enjoyed by me as it will make what I try to do in the future better.