Conversation

Class for keeping track of a conversation between actors.

A conversation can consist of several threads, which can be activated or deactivated seperately. Using different threads can be useful when a conversation has a choice, or when you want certain threads to be active only when the player is close enough to the relevant NPS.

If no threads are added, all responses will be added to the default thread (threads[0]).

Constructor

Conversation() Class for keeping track of a conversation between actors.

Methods

addResponse([portrait, text, action, sticky]) Adds a response to the default Thread.
addThread(thread) Adds a new conversation Thread to the conversation.
block() Sets the conversation to blocked.
currentResponse() Retrieve the current response of the default thread.
getActiveThread() Returns the currently active thread.
hasNext() Checks if the default thread has a next response available.
nextResponse() Skips to the next response, if there is one.
setDebug([value]) Enables debug mode for this conversation, printing extra information.
setResponse([portrait, text, action, sticky]) Adds a response to this speech bubble and make it the current response.
unblock() Unblocks the conversation.

Details

class Conversation[source]

Bases: object

Creates a Conversation object.

Methods

addResponse(portrait=None, text='', action=None, sticky=False)[source]

Adds a response to the default Thread.

Parameters:
  • text – A string containing the text associated with this response.
  • action – A function executed when this response is ‘spoken’.
addThread(thread)[source]

Adds a new conversation Thread to the conversation.

Parameters:thread – The Thread to add.
block()[source]

Sets the conversation to blocked.

While the conversation is blocked, calling the current response will return an empty response.

currentResponse()[source]

Retrieve the current response of the default thread.

Returns:A Response object.
getActiveThread()[source]

Returns the currently active thread.

Returns the first active thread from the threads list. if no threads are active, the default (threads[0]) thread is returned.

Returns:The first active Thread object.
hasNext()[source]

Checks if the default thread has a next response available.

Returns:Boolean indicating whether the default thread has a response left.
nextResponse()[source]

Skips to the next response, if there is one.

setDebug(value=True)[source]

Enables debug mode for this conversation, printing extra information.

Parameters:value – Booleans indicating whether to enable (True) or disable (false) debug mode.
setResponse(portrait=None, text='', action=None, sticky=False)[source]

Adds a response to this speech bubble and make it the current response.

Parameters:
  • text – A string containing the text associated with this response.
  • action – A function executed when this response is ‘spoken’.
unblock()[source]

Unblocks the conversation.

Thread

Keeps a list of consecutive reponses of different NPCs in a conversation.

Can be associated with an area, such that the Thread only becomes active when the players is in that area.

Constructor

Thread([actor]) Keeps a list of consecutive reponses of different NPCs in a conversation.

Instance Attributes

area Area that indicates where this thread is active
currentResponseIndex Index pointing to the current response
responses A list of responses

Methods

active() Indicates whether this Thread is active.
addResponse([portrait, text, action, sticky]) Adds a response to this Thread.
blockSkip() Blocks the next skip command for this Thread.
clear([launchAction]) Clears all responses and launches any actions associated with them.
currentResponse() Retrieve the current response.
hasCurrent() Indicates whether this Thread has a current response.
hasNext() Indicates whether this Thread has a next response.
nextResponse() Skips to the next response, if there is one.
setActor(actor[, size]) Sets an actor for this Thread.
setArea(actor[, size]) Sets the area of this Thread around an actor.
setResponse([portrait, text, action, sticky]) Adds a response to this speech bubble and make it the current response.
skip([launchAction]) Skips all responses and launches all actions, except sticky ones.

Details

class Thread(actor=None)[source]

Bases: object

Constructs a Thread object.

By default the a Thread is always active if it contains responses, but if an actor is passed to the constructor, the thread will only be active if player is within a certain area of that actor.

Parameters:actor – A SpriteActor associated with this response.

Instance Attributes

area

Area that indicates where this thread is active

currentResponseIndex

Index pointing to the current response

responses

A list of responses

Methods

active()[source]

Indicates whether this Thread is active.

By default a Thread will be active is the player is within the provided area, or if no such area is defined for this Thread.

Returns:Boolean indicating whether this Thread is active.
addResponse(portrait=None, text=None, action=None, sticky=False)[source]

Adds a response to this Thread.

Parameters:
  • portait – The portrait that will be shown with this response.
  • text – A string containing the text associated with this response.
  • action – A function executed when this response is ‘spoken’.
  • sticky – If sticky is True, this response will not be removed from the Thread, meaning that this response will be repeated over and untill some other event ‘unsticks’ it.
blockSkip()[source]

Blocks the next skip command for this Thread.

Blocking the skip command may be necessary to prevent skipping animations that would otherwise block progress.

clear(launchAction=True)[source]

Clears all responses and launches any actions associated with them.

The difference between skip() and clear() is that clear() ignores sticky actions or blockSkip(), and guarentees that the response list is empty once called. Essentially resets the Thread.

Parameters:launchAction – If set to False, reponses are still skipped, but the associated actions are not executed.
currentResponse()[source]

Retrieve the current response.

Returns:A Response object.
hasCurrent()[source]

Indicates whether this Thread has a current response.

Returns:True if this Thread has a current response, False otherwise.
hasNext()[source]

Indicates whether this Thread has a next response.

Returns:True if this Thread has a response left, False otherwise.
nextResponse()[source]

Skips to the next response, if there is one.

setActor(actor, size=150)[source]

Sets an actor for this Thread.

When an actor is set, as square area around the actor will be set as the area for this Thread. In addition, the image returned by getAvatar() will be used as the portrait of this Thread.

Parameters:
  • actor – The SpriteActor to associate with this Thread.
  • size – The size of the area around the actor in which this Thread will be active.
setArea(actor, size=150)[source]

Sets the area of this Thread around an actor.

In contrast to setActor, this will not set the portrait of this Thread.

Parameters:
  • actor – The actor around whom to center the area.
  • size – The size of the area.
setResponse(portrait=None, text='', action=None, sticky=False)[source]

Adds a response to this speech bubble and make it the current response.

Parameters:
  • text – A string containing the text associated with this response.
  • action – A function executed when this response is ‘spoken’.
skip(launchAction=True)[source]

Skips all responses and launches all actions, except sticky ones.

This should allow skipping in conversations where the last response should never be removed.

Parameters:launchAction – If set to False, reponses are still skipped, but the associated actions are not executed.