Hey, haven't been around the TI-BASIC scene in a while, but recently thought of something I figured some of you might like that gives legitimate functionality to something (last I ever heard) considered without practical use.
Functions (the u, v, and w lowercase letters) are essentially strings that when called will return their expr() result, essentially, but few can find a good legitimate use of them. Acting as strings they can be changed while running a program and, acting as a function, they return results based on their string, but if you have no intention of changing their string while running the program you might as well type out the characters in their place instead of relying that the function will be what you need it to be, leading to potential instability in your program.
While thinking over some aspects of how to make a game recently, I remembered about functions and found a good use for them that can be extended to many different programs. Their ability to be changed while executing a program leads them to be a fantastic variable type for configurable options holding configured conditions.
My example for this would be from the game that lead me to making this post (thanks KermM) that I call Presidents, but it goes by many names, with even more play variants. The exact rules of the game aren't important. Do know, however, that according to one variant, you must play a card of lower value than the previously played card, another variant allows you to play equal value cards, and a third variant allows you to skip the next players turn if you play equal value cards. Although I never had such a play variant, for sake of argument, I'll add in a fourth that adds a card specifically to skip the next player's turn. In the following examples, C is the current card's value, P the previous card's value, V the current variant selected and 8 would be the constant used for the skip card.
Code:
With only a few minor options in the game, some of the code can already start looking bloated and sloppy, but if in this code functions were used in place, it could look much cleaner:
Code:
The 000 in the first string are used because there is no method to skip a players turn in the first two variants, and the +000 in the second string are used simply as buffers to take up the whole 7 characters without returning a Syntax Error.
This style of configurable options can mean better optimized code for conditions that are repeated several times throughout a program, and may mean better speed of execution of your code, but that depends on how well it can decode the string into its tokens and execute fewer tokens than executing a longer condition.
Although my example was specifically for a game, it can be used in any style of program that has or needs options. Hope you guys enjoy.
Functions (the u, v, and w lowercase letters) are essentially strings that when called will return their expr() result, essentially, but few can find a good legitimate use of them. Acting as strings they can be changed while running a program and, acting as a function, they return results based on their string, but if you have no intention of changing their string while running the program you might as well type out the characters in their place instead of relying that the function will be what you need it to be, leading to potential instability in your program.
While thinking over some aspects of how to make a game recently, I remembered about functions and found a good use for them that can be extended to many different programs. Their ability to be changed while executing a program leads them to be a fantastic variable type for configurable options holding configured conditions.
My example for this would be from the game that lead me to making this post (thanks KermM) that I call Presidents, but it goes by many names, with even more play variants. The exact rules of the game aren't important. Do know, however, that according to one variant, you must play a card of lower value than the previously played card, another variant allows you to play equal value cards, and a third variant allows you to skip the next players turn if you play equal value cards. Although I never had such a play variant, for sake of argument, I'll add in a fourth that adds a card specifically to skip the next player's turn. In the following examples, C is the current card's value, P the previous card's value, V the current variant selected and 8 would be the constant used for the skip card.
Code:
-Options-
:Input V
-Code-
:If V=3 and P=C or V=4 and C=8
:Then
:[skip next player's turn]
:End
:If V=1 and P>C or (V=2 or V=3) and P≥C or V=4 and (C=8 or P>C)
:Then
:[continue with player's turn]
:Else
:[disallow attempted move]
:End
With only a few minor options in the game, some of the code can already start looking bloated and sloppy, but if in this code functions were used in place, it could look much cleaner:
Code:
-Options-
:Input V
:sub("000000P=CC=14",3V,3→u
:sub("P>C+000P≥C+000P≥C+000C=8 or P>C",7V,7→v
-Code-
:If u
:Then
:[skip next player's turn]
:End
:If v
:Then
:[continue with player's turn]
:Else
:[disallow attempted move]
:End
The 000 in the first string are used because there is no method to skip a players turn in the first two variants, and the +000 in the second string are used simply as buffers to take up the whole 7 characters without returning a Syntax Error.
This style of configurable options can mean better optimized code for conditions that are repeated several times throughout a program, and may mean better speed of execution of your code, but that depends on how well it can decode the string into its tokens and execute fewer tokens than executing a longer condition.
Although my example was specifically for a game, it can be used in any style of program that has or needs options. Hope you guys enjoy.