Echo Hollow

Gender-Bending Interactive Stories! :D

User Tools

Site Tools


libtf:documentation:api:util

This is an old revision of the document!


<-- Back

LibTF.Util

Miscellaneous internal utility functions that don't seem to fit anywhere else.

You probably won't every need to use any of these, except maybe .capitalize().

Methods

LibTF.Util.commaList( list )

  • Arguments:
    • list: an array of strings.
  • Returns: (String) A comma-separated description of the list.
  • Throws: Nothing.

Returns a comma-separated description of the list, including “and”, or “nothing” if the list is empty.

alert( LibTF.commaList([ "a two-dollar pistol", "a Stetson hat", "a shotgun" ]) );
// prints "a two-dollar pistol, a Stetson hat, and a shotgun"
alert( LibTF.commaList([ "a two-dollar pistol", "a Stetson hat" ]) );
// prints "a two-dollar pistol and a Stetson hat"
alert( LibTF.commaList([ "a two-dollar pistol" ]) );
// prints "a two-dollar pistol"
alert( LibTF.commaList([ ]) );
// prints "nothing"

LibTF.Util.capitalize( s )

  • Arguments:
    • s: a string to capitalize
  • Returns: (String) A string matching s, but with the first character capitalized.
  • Throws: Nothing.

Returns a string matching s, but with the first character capitalized.

FIXME: This doesn't work if the first character is a quotation mark or other punctuation, or a number. Does it need to?

// given that some_widget.name == "widget"...
alert( LibTF.Util.capitalize(tf("some_widget").aName) + " sure is a good thing to have!" );
// prints "A widget sure is a good thing to have!"

LibTF.Util.yourHisHer( person, thirdPerson )

  • Arguments:
    • person: the person for which to return the adjective.
    • thirdPerson : True if output should be in third-person, or False if it should be in second-person.
  • Returns: (String) The appropriate adjective given the person's sex and thirdPerson.
  • Throws: Nothing.

If thirdPerson is True, returns “his”, “her”, or “their” depending on whether the given Person's femininity Transformable indicates that they are male, female, or androgynous respectively.

If thirdPerson is False, returns “your”. This is useful for when the same passage/code is intended to generate text for both the player character and NPCs.

// if Joe is male...
alert( "There is a fire on " + Util.yourHisHer(tf("joe"),true) + " head!" );
// prints "There is a fire on his head!"
// if Joe is female...
alert( "There is a fire on " + Util.yourHisHer(tf("joe"),true) + " head!" );
// prints "There is a fire on her head!"
// regardless of Joe's sex, if Joe is the player character and we pass thirdPerson=false...
alert( "There is a fire on " + Util.yourHisHer(tf("joe"),false) + " head!" );
// prints "There is a fire on your head!"

LibTF.Util.YourHisHer( person, thirdPerson )

This method is identical to .yourHisHer(), except that the first letter of the returned string is capitalized.

alert( Util.YourHisHer(tf("joe"),true) + " head is on fire!" );
// prints "His head is on fire!"

LibTF.Util.youHeShe( person, thirdPerson, youTheyVerb=null, heSheVerb=null )

  • Arguments:
    • person: the person for which to return the sentence fragment.
    • thirdPerson : True if output should be in third-person, or False if it should be in second-person.
    • youTheyVerb: optional verb to output on you/they choice.
    • heSheVerb: optional verb to output on he/she choice.
  • Returns: (String) A sentence fragment.
  • Throws: Nothing.

Chooses “he”, “she”, “they”, or “you” in the same way as .yourHisHer().

If a youTheyVerb has been included, it will be appended to the return value if “you” or “they” is chosen.

If no heSheVerb has been included, but “he” or “she” is chosen, then the youTheyVerb will have an “s” appended to it, and will be appended to the return value. Otherwise, if a heSheVerb is included, then it will be appended instead.

alert( LibTF.Util.youHeShe(tf("joe"),true,"jump") ); // "he jumps"
alert( LibTF.Util.youHeShe(tf("joe"),false,"jump") ); // "you jump"
alert( LibTF.Util.youHeShe(tf("joe"),true,"are","is")+" jumping" ); // "he is jumping"
alert( LibTF.Util.youHeShe(tf("joe"),false,"are","is")+" jumping" ); // "you are jumping"

LibTF.Util.YouHeShe( person, thirdPerson, youTheyVerb, heSheVerb )

This method is identical to .youHeShe(), except that the first letter of the returned string is capitalized.

alert( LibTF.Util.YouHeShe(tf("joe"),true,"jump") ); // "He jumps"
alert( LibTF.Util.YouHeShe(tf("joe"),false,"jump") ); // "You jump"
alert( LibTF.Util.YouHeShe(tf("joe"),true,"are","is")+" jumping" ); // "He is jumping"
alert( LibTF.Util.YouHeShe(tf("joe"),false,"are","is")+" jumping" ); // "You are jumping"

<-- Back

libtf/documentation/api/util.1519592927.txt.gz · Last modified: 2018/02/25 13:08 by lee