{"id":5709,"date":"2023-12-01T16:30:19","date_gmt":"2023-12-01T15:30:19","guid":{"rendered":"https:\/\/msxitalia.org\/?p=5709"},"modified":"2023-12-01T16:32:20","modified_gmt":"2023-12-01T15:32:20","slug":"lezione-15-funzioni-create-dallutente","status":"publish","type":"post","link":"https:\/\/msxitalia.org\/en\/lezione-15-funzioni-create-dallutente\/","title":{"rendered":"LESSON 15 \u2013 User-created functions"},"content":{"rendered":"<p class=\"wp-block-paragraph\"><img decoding=\"async\" data-src=\"https:\/\/msxitalia.org\/wp-content\/uploads\/2023\/11\/400625230_10230377400034312_4163852793903628616_n-e1700830185545.jpg\" class=\"size-full wp-image-5213 aligncenter lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" alt=\"\" width=\"151\" height=\"113\" \/><noscript><img decoding=\"async\" class=\"size-full wp-image-5213 aligncenter\" src=\"https:\/\/msxitalia.org\/wp-content\/uploads\/2023\/11\/400625230_10230377400034312_4163852793903628616_n-e1700830185545.jpg\" alt=\"\" width=\"151\" height=\"113\"><\/noscript><\/p>\r\n<p>In this lesson I will briefly explain how to create a function that puts together groups of MSX Basic functions or multiple calculations that we will have to use several times in our programs. Create a single function that includes everything said above with a single command line, because perhaps in MSX BASIC we would have to do many steps and this would involve a waste of memory and perhaps a bit of confusion. These functions can be either numeric or alphanumeric.<br \/>The first thing to do is to give a name and we always do this at the beginning of the program by adding a variable to the DEF FN command, if it is alphanumeric we will add the $ symbol at the end: DEF FNA or DEF FNA$. The correct syntax is: DEF FN Function Name(Argument List)=Function definition. I&#039;ll explain step by step <br \/>its meaning. After giving the name to the function we must insert how many arguments we want to use, if there are more than one they must be divided by a comma: DEF FNA(X,Y).The variables that we insert as arguments are fictitious, they have nothing to do with the ones we will use inside the program, it just indicates that we will only have to use two of them. While in the last part of the command, we have to say what the arguments will do. For example, since we have specified 2 arguments, the first will find the square root and the second will multiply by Pigreco: DEF FNA(X,Y)= SQR(X)+Y*3.141. Below I insert the program that performs the above:<\/p>\r\n<pre>10 DEF FNA(X,Y)=SQR(X)+Y*3.141<br \/>20 I=4: J=3<br \/>30 R=FNA(I,J)<br \/>40 PRINT R<\/pre>\r\n<p>I&#039;ll give another example by creating an alphanumeric function<\/p>\r\n<pre>10 DEF FNA$(X,Y)=C$+MID$(X$,5)<br \/>20<br \/>30 FOR I=1 TO 3: READ C$<br \/>40 R$=FNA$(X,Y)<br \/>50 PRINT R$: NEXT I<br \/>60 DATA CAR, MONO, HOME<\/pre>\r\n<p>In this case, in the function definition we used the variables that we name later in the program, so the function we created will know that X and Y are equivalent<br \/>to them. What the function does; changes the first 4 characters of the word MONOVEDETTA (X$) 3 times, reading the name of the word to be changed (C$) with a READ instruction which<br \/>was saved in the DATA function. A simple function created with 2 arguments and the MID$ command.<br \/>These are just small examples but try to imagine what you can create if you are familiar with MSX BASIC; complex mathematical expressions, powerful algorithms, even with graphics it can be of great help and much more.<br \/><br \/>Thank you all. Until next time.<\/p>","protected":false},"excerpt":{"rendered":"<p>In questa lezione spiegher\u00f2 a brevi linee come creare una funzione che mette insieme gruppi di funzioni MSX Basic oppure pi\u00f9 calcoli che dovremo usare pi\u00f9 volte nei nostri programmi. Creare un&#8217;unica funzione che racchiude tutto quello detto sopra con una sola riga di comando, perch\u00e9 magari in BASIC MSX dovremmo fare tanti passaggi e [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[14],"tags":[],"dipi_cpt_category":[],"class_list":["post-5709","post","type-post","status-publish","format-standard","hentry","category-msx-basic"],"_links":{"self":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts\/5709","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/comments?post=5709"}],"version-history":[{"count":3,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts\/5709\/revisions"}],"predecessor-version":[{"id":5717,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/posts\/5709\/revisions\/5717"}],"wp:attachment":[{"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/media?parent=5709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/categories?post=5709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/tags?post=5709"},{"taxonomy":"dipi_cpt_category","embeddable":true,"href":"https:\/\/msxitalia.org\/en\/wp-json\/wp\/v2\/dipi_cpt_category?post=5709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}