HyperNext Studio

HyperNext Studio => Getting Started => Topic started by: LinesOfCodes on October 02, 2020, 11:33:37 AM

Title: Function system
Post by: LinesOfCodes on October 02, 2020, 11:33:37 AM
Hello, I want to know How can I create a 'function' (user-defined procedure) and create a 'plug-in' (plug-in procedure)?
Title: Re: Function system
Post by: Malkom on October 03, 2020, 08:11:02 AM
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.

Code: [Select]
@ 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 MyAddFN

Code: [Select]
Global 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 Procedure

Procedures 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 (http://www.tigabyte.com/smf/index.php?topic=118.msg399#msg399)