Yes it is possible to create your own user-defined functions but they are clumsy to call compared to a HN defined function.
In most programming languages the user-defined and language defined function usages are very similar.
Here is how to do it in HN:-
(1) Create a procedure for instance
MyAddFN with any required parameters
You can create your procedure in a the MainCode section where it will be global.
Procedures can also be created in cards, buttons etc, where they will be local.
@ MyAddFN(n1,n2) - simply adds 2 numbers together
Global myResultAddFN
Put n1 into myResultAddFN
Add n2 to myResultAddFN
(2) In your button place the call to your procedure
MyAddFNGlobal myResultAddFN
Call MyAddFN(2,3)
Put myResultAddFN into field 1
@ 5 should appear in field 1
I try to keep the global variable names similar to the user-defined functions(procedure) because its easier to keep track of them in large programs. However, you can name your global variables anything, as long as they don't conflict with a HN keyword or other variable.
Creating a ProcedureProcedures are created in the Script Editor using the
New, Edit, Del buttons in the lower left of the editor window.
Procedures are listed in the listbox directly above these 3 buttons.
Just make sure that you have selected the correct control, card or MainCode before creating your procedure.
This post might help in creating procedures, also know as handlers:-
http://www.tigabyte.com/smf/index.php?topic=118.msg399#msg399