For Quest: Can A Template Return A Function?

0 votes
90 views
asked Apr 22 in Authoring by nimrod (1 point)
edited Apr 23 by Alex

I want to change the default responses of the engine, for example the "NotCarrying"-dynamic template. What do I have to enter in "Text:" so that it accesses the function "es"?

2 Answers

0 votes
answered Apr 22 by The Pixie (121 points)

DynamicTemplates are kind of like functions that take a single parameter, object, and return a string. The returned string depends on what you put in the "Text" field.

This is the default for NotCarrying:

"You are not carrying " + object.article + "."

Quest will evaluate that and return it. Specifically it will join together the first string, the value of the article attribute of object (which will be "it", "them", etc.) and the last string (so the player might see "You are not carrying it."). You can call other functions, for example:

"You are not carrying " + GetDisplayName(object) + "."

The GetDisplayName function will get the name or alias of the object as well as its prefix, so now the player might see "You are not carrying a ball."

You could do both. You can access other attributes on other objects too:

player.name + " is not carrying " + object.article + ". And by " + object.article + " I mean " + GetDisplayName(object) + "."

The player might see "Mary is not carrying them. And by them I mean some rocks." You can use functions and attributes you have added yourself too. It is very flexible.

commented Apr 22 by nimrod (1 point)
But that doesn't seem to work with a function I created.
the function is called: es
it is a switch script that randomly selects texts
does that change anything? what exactly would I have to type in?
0 votes
answered Apr 22 by jaynabonne (141 points)

This works for me:

  <function name="es" type="string">
    return("This is the result of es")
  </function>

with dynamic template having text:

es()

Be sure your function is of type "string" and actually returns a string.

commented Apr 23 by nimrod (1 point)
Oh, I meant, if I enter "es()" in a template like "UnrecognisedCommand" it just prints "es()". Why won't it use the function like a dynamic template does?
commented Apr 23 by jaynabonne (141 points)
That is the difference between a normal (textual) template and a dynamic (function-based) one. :) The former is just text.
commented Apr 23 by nimrod (1 point)
Oh, so there is no way to have randomized text with a normal template?
commented Apr 23 by jaynabonne (141 points)
Nope. A normal template is just fixed text. That's why dynamic templates were created. Unfortunately, you can only implement a dynamic template where they're actually used by the core code, so you can't replace everything as you might wish.
commented Apr 23 by nimrod (1 point)
Ah, I see, okay, well, thanks for the help. Really good to know, I clearly had no idea of anything, thanks.
This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...