Skip to content
Mathieu edited this page Jun 30, 2022 · 5 revisions

client/js/npc.js defines the Npc class, which uses the NpcTalk array that stores for each character the sequence of sentences it is supposed to produce to players.

The Npc class extends class Character

Properties

  • NpcTalk: Each talking npc is associated to a cell in the array, its content is an array with the sentences to produce in the order in which they are to utter them.

Methods

  • init: initialises the npc;
  • talk: displays the next sentence associated to the character in the NpcTalk table.

Conditional talk

(see scientist for an example)

Discourse can now be circonstancial. The default mechanism is providing an array of sentences. For more elaborate speech :

[
  {"text":[/*sentences*/]},
  {"condition": function(game),
   "text":[/*sentences*/]},
  {"condition": function(game),
   "text":[/*sentences*/]}
]
  • Each object (except the first, default discussion) has a "condition" property (function(game)boolean) which decides when to use this discussion and a "text" property, which contain the array of lines of the conversation ([/*sentences*/]).
  • name as the name of the user in npc dialogs

Potential improvements

  • It could also be modified to provide multilingual support.
Clone this wiki locally