I am trying to have a list of "special abilities" in my characters in a text adventure I am designing. I know how to fake functions using |tag> syntax, but is there a dedicated
def
or
defun
syntax in Harlowe I haven't heard about? If so, could I have an array of functions I could mess around with?
Based on the assumption that a function is just a named reusable block of code that may also accept parameters you can use passages to archive the same results.
note: The function passage (Character Description) in my example is generating visible output but the solution works just as well with passages that don't generate output.
a. Character Description passage
This passage acts as a function, it contains the function's block of code and accepts a single $character parameter.
Name: $character's Name
Age: $character's Age
HP: $character's HP
b. Some other passage which is going to call the Character Descriptionfunction
It first defines a list of NPCs, each one contains an "Info" element containing the name of a function passage to called. A (display:) macro is used to call the function passage.
(set: $npcs to (array:))
(set: $npcs to it + (array: (datamap: "Name", "John", "Age", 18, "HP", 100, "Info", "Character Description")))
(set: $npcs to it + (array: (datamap: "Name", "Jane", "Age", 18, "HP", 100, "Info", "Character Description")))
Show John's Info:
(set: $character to $npcs's 1st)(display: $character's Info)
Show Jane's Info:
(set: $character to $npcs's 2nd)(display: $character's Info)
Comments
note: The function passage (Character Description) in my example is generating visible output but the solution works just as well with passages that don't generate output.
a. Character Description passage
This passage acts as a function, it contains the function's block of code and accepts a single $character parameter.
b. Some other passage which is going to call the Character Description function
It first defines a list of NPCs, each one contains an "Info" element containing the name of a function passage to called. A (display:) macro is used to call the function passage.