Let them chose their name. Function to typewriting in Ink

HotCosmo

Just a guy
Joined
Oct 3, 2023
Posts
34
Well, I've been lately having a little writer's block, so I did the second-best thing after writing: create Ink's functionalities.

I present you text_generator(), a tunnel that would make it possible for your player to write some text, like, for example, a name. The code of the functionality is in the next post of this thread (apparently I was exceeding the maximum number of characters 😅) for you to copy-paste in your story game, but first let's go to look at how it works and how you must use it.


First, you have to declare a global variable called 'text', just like in the next example:
Code:
VAR text = ""
Nothing will work if you don't declare this variable. I recommend declaring it at the start of the game.


Second, call the functionality whenever it's needed in the story:
Code:
-> text_generator(0, 25)->
So this functionality has two parameters:

  • The first one (the zero in the example) is 'esp,' and depending on its value, the player could use spaces and special characters. The player has access to the 26 letters of the Latin alphabet in their uppercase and lowercase forms and with most of their accents (Ä, á, û...). Allowing special characters, the player has access to symbols like Æ, &, $...
    • 0: Space and Special Characters blocked
    • 1: Space allowed, Special Characters blocked
    • 2: Space blocked, Special Characters allowed
    • 3: Space and Special Characters allowed
  • The second parameter (the 25 in the example) is 'max_char' is the maximum number of characters that you allow the player to use. Be aware that spaces count as a character.


Third, call the variable with the text of the player whenever it's necessary. Once you have used text_generator(), the variable 'text' contains the text of the player. You can call it using the braces {}:
Code:
His name was {text}.
Although I don't recommend doing it in this way. The reason is simple: you can use text_generator() as many times as you wish, and each time 'text' would be replaced. Imagine that you want the player to not only name his character but also name a pet or a friend or even to make them write some kind of text that you want to reproduce at any moment of the story, like, for example, their favorite food. So my proposal is to create a variable to hold the concrete information and let 'text' be a temporary holder of your player texts, like for example:

Code:
VAR text = ""
VAR name = ""

-> text_generator(2, 25)->
~ name = text

His name was {name}.

I recommend doing some experiments before adding text_generator() to your story game and not using it very frequently or giving the player the option to use it or not (for example, existing a default name if the player doesn't want to typewrite their name. Picking your own name is cool, but maybe a little boring if it's your third time playing the game. Although I try to make the functionality easy to use and simple, it's far slower than, for example, typewriting on a phone or computer.

The functionality only allows you to erase the whole word and restart, not the last character.

The special symbols are the most improvable part of this functionality, so don't be afraid to add symbols that you need. I'm sure once you look at the code, you would have no problem figuring out how to add an extra symbol if you think that some of your players need it.


Well, I hope this functionality can be helpful for all of you. If you have any questions or ideas to improve it, I'm open to any comment.
 
Code:
VAR text = ""

=== text_generator(esp, max_char) ===
// Global variable 'text' is required for this function to work.
/*esp=
- 0: Space and Special Characters blocked
- 1: Space allowed, Special Characters blocked
- 2: Space blocked, Special Characters allowed
- 3: Space and Special Characters allowed
*/
// max_char: Maximum number of characters (spaces count as characters).
{esp !=3 and esp !=2 and esp !=1 and esp !=0: Error: It is necessary to include 0, 1, 2, or 3 as the parameter 'esp' to identify if special characters are accessible or inaccessible.->DONE}
{max_char <= 1: Error: The maximum number of characters must be at least 1.->DONE}
{max_char < 8: Warning: The maximum number of characters is very short. Be aware.}

~ text = ""
~ temp count = 0

-> keyboard(count, esp, max_char)


= restart( count, esp, max_char)
~ text = ""
~ count = 0

-> keyboard( count, esp, max_char)


= keyboard( count, esp, max_char)
{count >= max_char:
You have reached the character limit. Your text is: {text}
Are you okay with this text?
+ [YES]
->->
+ [RESTART]
Are you sure you want to elminete the text and restart?
    ++ [YES]
    -> restart( count, esp, max_char)
    ++ [NOT]
    ->->
}
~ temp letter = ""
[{count}/{max_char} characters]
Text: {text}_

+ {esp == 1 or esp == 3 and count >= 1}[Space]
    ~ text = text + " "
    ~ count += 1
+ [A/B/C/D/E/F/G]
->a_b_c_d_e_f_g(letter,  count, esp, max_char)
+ [H/I/J/K/L/M/N]
-> h_i_j_k_l_m_n(letter,  count, esp, max_char)
+ [O/P/Q/R/S/T/U]
-> o_p_q_r_s_t_u(letter,  count, esp, max_char)
+ [V/W/X/Y/Z]
-> v_w_x_y_z(letter,  count, esp, max_char)
+ {esp == 2 or esp == 3}[Special Characters]
-> special(letter,  count, esp, max_char)
+ [RESTART]
Do you want to erase the text that you have written?
    ++ [NOT]
    -> keyboard( count, esp, max_char)
    
    ++ [YES]
    -> restart( count, esp, max_char)
+ [END]
{count==0: The text is empty. You must use at least one character. ->keyboard( count, esp, max_char)}
Text: {text}
Are you okay with this text?
    ++ [YES]
    ->->
    ++ [NOT]
    -> keyboard( count, esp, max_char)
-

->keyboard( count, esp, max_char)

= special(letter,  count, esp, max_char)

+ [Ç]
    ++ [Ç]
        ~ letter = "Ç"
    ++ [ç]
        ~ letter = "ç"
    ++ [BACK]
    ->special(letter,  count, esp, max_char)
+ [Æ]
    ++ [Æ]
        ~ letter = "Æ"
    ++ [æ]
        ~ letter = "æ"
    ++ [Ǽ]
        ~ letter = "Ǽ"
    ++ [ǽ]
        ~ letter = "ǽ"
    ++ [Æ̀]
        ~ letter = "Æ̀"
    ++ [æ̀]
        ~ letter = "æ̀"
    ++ [Æ̂]
        ~ letter = "Æ̂"
    ++ [æ̂]
        ~ letter = "æ̂"
    ++ [Æ̃]
        ~ letter = "Æ̃"
    ++ [æ̃]
        ~ letter = "æ̃"
    ++ [BACK]
    ->special(letter,  count, esp, max_char)
    
+ [&]
    ~ letter = "&"
+ [@]
    ~ letter = "@"
+ [$]
    ~ letter = "$"
+ [€]
    ~ letter = "€"

+ [BACK]
->keyboard( count, esp, max_char)

-
~ text = text + letter
~ count += 1
->keyboard( count, esp, max_char)

= a_b_c_d_e_f_g(letter,  count, esp, max_char)

+ [A]
    ++ [A]
        ~ letter = "A"
    ++ [a]
        ~ letter = "a"
    ++ [Á]
        ~ letter = "Á"
    ++ [á]
        ~ letter = "á"
    ++ [Ä]
        ~ letter = "Ä"
    ++ [ä]
        ~ letter = "ä"
    ++ [À]
        ~ letter = "À"
    ++ [à]
        ~ letter = "à"
    ++ [Â]
        ~ letter = "Â"
    ++ [â]
        ~ letter = "â"
    ++ [BACK]
    -> a_b_c_d_e_f_g(letter,  count, esp, max_char)
    --

+ [B]
    ++ [B]
        ~ letter = "B"
    ++ [b]
        ~ letter = "b"
    ++ [BACK]
    -> a_b_c_d_e_f_g(letter,  count, esp, max_char)   
    --

+[C]
    ++ [C]
        ~ letter = "C"
    ++ [c]
        ~ letter = "c"
    ++ [BACK]
    -> a_b_c_d_e_f_g(letter,  count, esp, max_char)   
    --

+[D]
    ++ [D]
        ~ letter = "D"
    ++ [d]
        ~ letter = "d"
    ++ [BACK]
    -> a_b_c_d_e_f_g(letter,  count, esp, max_char)   
    --

+[E]
    ++ [E]
        ~ letter = "E"
    ++ [e]
        ~ letter = "e"
    ++ [É]
        ~ letter = "É"
    ++ [é]
        ~ letter = "é"
    ++ [Ë]
        ~ letter = "Ë"
    ++ [ë]
        ~ letter = "ë"
    ++ [È]
        ~ letter = "È"
    ++ [è]
        ~ letter = "è"
    ++ [Ê]
        ~ letter = "Ê"
    ++ [ê]
        ~ letter = "ê"
    ++ [BACK]
    -> a_b_c_d_e_f_g(letter,  count, esp, max_char)   
    --

+[F]
    ++ [F]
        ~ letter = "F"
    ++ [f]
        ~ letter = "f"
    ++ [BACK]
    -> a_b_c_d_e_f_g(letter,  count, esp, max_char)   
    --
    
+[G]
    ++ [G]
        ~ letter = "G"
    ++ [g]
        ~ letter = "g"
    ++ [BACK]
    -> a_b_c_d_e_f_g(letter,  count, esp, max_char)   
    --

+ [BACK]
->keyboard( count, esp, max_char)
-

~ text = text + letter
~ count += 1
->keyboard( count, esp, max_char)


= h_i_j_k_l_m_n(letter,  count, esp, max_char)

+[H]
    ++ [H]
        ~ letter = "H"
    ++ [h]
        ~ letter = "h"
    ++ [BACK]
        -> h_i_j_k_l_m_n(letter,  count, esp, max_char)   
    --

+[I]
    ++ [I]
        ~ letter = "I"
    ++ [i]
        ~ letter = "i"
    ++ [Í]
        ~ letter = "Í"
    ++ [í]
        ~ letter = "í"
    ++ [Ï]
        ~ letter = "Ï"
    ++ [ï]
        ~ letter = "ï"
    ++ [Ì]
        ~ letter = "Ì"
    ++ [ì]
        ~ letter = "ì"
    ++ [Î]
        ~ letter = "Î"
    ++ [î]
        ~ letter = "î"
    ++ [BACK]
        -> h_i_j_k_l_m_n(letter,  count, esp, max_char)
    --

+[J]
    ++ [J]
        ~ letter = "J"
    ++ [j]
        ~ letter = "j"
    ++ [BACK]
        -> h_i_j_k_l_m_n(letter,  count, esp, max_char)   
    --

+[K]
    ++ [K]
        ~ letter = "K"
    ++ [k]
        ~ letter = "k"
    ++ [BACK]
        -> h_i_j_k_l_m_n(letter,  count, esp, max_char)   
    --

+[L]
    ++ [L]
        ~ letter = "L"
    ++ [l]
        ~ letter = "l"
    ++ [BACK]
        -> h_i_j_k_l_m_n(letter,  count, esp, max_char)   
    --

+[M]
    ++ [M]
        ~ letter = "M"
    ++ [m]
        ~ letter = "m"
    ++ [BACK]
        -> h_i_j_k_l_m_n(letter,  count, esp, max_char)   
    --

+[N]
    ++ [N]
        ~ letter = "N"
    ++ [n]
        ~ letter = "n"
    ++ [Ñ]
        ~ letter = "Ñ"
    ++ [ñ]
        ~ letter = "ñ"
    ++ [BACK]
        -> h_i_j_k_l_m_n(letter,  count, esp, max_char)   
    --
    
+ [BACK]
->keyboard( count, esp, max_char)

-
~ text = text + letter
~ count += 1
->keyboard( count, esp, max_char)


= o_p_q_r_s_t_u(letter,  count, esp, max_char)
+[O]
    ++ [O]
        ~ letter = "O"
    ++ [o]
        ~ letter = "o"
    ++ [Ó]
        ~ letter = "Ó"
    ++ [ó]
        ~ letter = "ó"
    ++ [Ö]
        ~ letter = "Ö"
    ++ [ö]
        ~ letter = "ö"
    ++ [Ò]
        ~ letter = "Ò"
    ++ [ò]
        ~ letter = "ò"
    ++ [Ô]
        ~ letter = "Ô"
    ++ [ô]
        ~ letter = "ô"
    ++ [BACK]
        -> o_p_q_r_s_t_u(letter,  count, esp, max_char)
    --

+[P]
    ++ [P]
        ~ letter = "P"
    ++ [p]
        ~ letter = "p"
    ++ [BACK]
        -> o_p_q_r_s_t_u(letter,  count, esp, max_char)
    --

+[Q]
    ++ [Q]
        ~ letter = "Q"
    ++ [q]
        ~ letter = "q"
    ++ [BACK]
        -> o_p_q_r_s_t_u(letter,  count, esp, max_char)
    --

+[R]
    ++ [R]
        ~ letter = "R"
    ++ [r]
        ~ letter = "r"
    ++ [BACK]
        -> o_p_q_r_s_t_u(letter,  count, esp, max_char)
    --

+[S]
    ++ [S]
        ~ letter = "S"
    ++ [s]
        ~ letter = "s"
    ++ [BACK]
        -> o_p_q_r_s_t_u(letter,  count, esp, max_char)
    --

+[T]
    ++ [T]
        ~ letter = "T"
    ++ [t]
        ~ letter = "t"
    ++ [BACK]
        -> o_p_q_r_s_t_u(letter,  count, esp, max_char)
    --

+[U]
    ++ [U]
        ~ letter = "U"
    ++ [u]
        ~ letter = "u"
    ++ [Ú]
        ~ letter = "Ú"
    ++ [ú]
        ~ letter = "ú"
    ++ [Ü]
        ~ letter = "Ü"
    ++ [ü]
        ~ letter = "ü"
    ++ [Ù]
        ~ letter = "Ù"
    ++ [ù]
        ~ letter = "ù"
    ++ [Û]
        ~ letter = "Û"
    ++ [û]
        ~ letter = "û"
    ++ [BACK]
        -> o_p_q_r_s_t_u(letter,  count, esp, max_char)
    --
+ [BACK]
->keyboard( count, esp, max_char)

-
~ text = text + letter
~ count += 1
->keyboard( count, esp, max_char)


= v_w_x_y_z(letter,  count, esp, max_char)

+[V]
    ++ [V]
        ~ letter = "V"
    ++ [v]
        ~ letter = "v"
    ++ [BACK]
        -> v_w_x_y_z(letter,  count, esp, max_char)
    --

+[W]
    ++ [W]
        ~ letter = "W"
    ++ [w]
        ~ letter = "w"
    ++ [BACK]
        -> v_w_x_y_z(letter,  count, esp, max_char)
    --

+[X]
    ++ [X]
        ~ letter = "X"
    ++ [x]
        ~ letter = "x"
    ++ [BACK]
        -> v_w_x_y_z(letter,  count, esp, max_char)
    --

+[Y]
    ++ [Y]
        ~ letter = "Y"
    ++ [y]
        ~ letter = "y"
    ++ [BACK]
        -> v_w_x_y_z(letter,  count, esp, max_char)
    --

+[Z]
    ++ [Z]
        ~ letter = "Z"
    ++ [z]
        ~ letter = "z"
    ++ [BACK]
        -> v_w_x_y_z(letter,  count, esp, max_char)
    --
-
~ text = text + letter
~ count += 1
->keyboard( count, esp, max_char)
 
Back
Top