Dialogue Component

The dialogue component class stores all the data to do with the dialogue that can be attached to a game object. This includes the starting dialogue this component will open with, and all the currently available dialogue options, and which dialogues this component has unlocked. game objects do not have a dialogue component by default so one must be created and attached.
Return to Index
new ( am.game_object attach_to = nil )
__gc ( )
__eq ( am.dialogue_component rhs ) -> ( boolean )
talk_to ( am.game_object talkee , am.dialogue with_dialogue = nil ) -> ( am.dialogue_component )
talking_to ( ) -> ( am.game_object )
start_dialogue ( ) -> ( am.dialogue )
start_dialogue ( string dialogue_id ) -> ( am.dialogue_component )
start_dialogue ( am.dialogue dialogue ) -> ( am.dialogue_component )
locked ( string subject ) -> ( boolean )
locked ( string subject , boolean locked ) -> ( am.dialogue_component )
available ( string dialogue_id ) -> ( boolean )
available ( string dialogue_id , boolean available ) -> ( am.dialogue_component )
attached_to ( ) -> ( am.game_object )
attached_to ( am.game_object game_object ) -> ( am.dialogue_component )
on ( string event_type , function listener , table content = nil ) -> ( boolean )
off ( string event_type , function listener , table context = nil ) -> ( boolean )
has_event_listener ( string event_type ) -> ( boolean )
new ( am.game_object attach_to = nil )
Creates a new dialogue component.
Parameters:
am.game_object attach_to = nil : Attaches this dialogue component to the given game object if it is not null.
__gc ( )
Releases the reference counter on this dialogue component.
__eq ( am.dialogue_component rhs ) -> ( boolean )
Compares this dialogue component with another dialogue component.
Parameters:
am.dialogue_component rhs : The other dialogue component to compare with.
Returns:
boolean : True if they are the same dialogue component object.
talk_to ( am.game_object talkee , am.dialogue with_dialogue = nil ) -> ( am.dialogue_component )
Attempts to start a dialogue with another game object. The other game object must have a dialogue component attached to talk to.
Parameters:
am.game_object talkee : The game object to talk to.
am.dialogue with_dialogue = nil : By default the talk to function will start a conversation using the start_dialogue value, this allows for that to be overridden for this talk.
Returns:
am.dialogue_component : This
talking_to ( ) -> ( am.game_object )
Returns the game object that this dialogue component is currently talking to. Will return nil if there is no dialogue.
Returns:
am.game_object : The game object being talked to or nil.
start_dialogue ( ) -> ( am.dialogue )
Returns the openning dialogue this component will use when talked to, or nil.
Returns:
am.dialogue : The starting dialogue, or nil.
start_dialogue ( string dialogue_id ) -> ( am.dialogue_component )
Sets the starting dialogue this component will use when talked to, can be nil.
Parameters:
string dialogue_id : The dialogue id of the dialogue to open with.
Returns:
am.dialogue_component : This
start_dialogue ( am.dialogue dialogue ) -> ( am.dialogue_component )
Sets the starting dialogue this component will use when talked to, can be nil.
Parameters:
am.dialogue dialogue : The dialogue to open with.
Returns:
am.dialogue_component : This
locked ( string subject ) -> ( boolean )
Returns if the given subject title is locked or unlocked.
Parameters:
string subject : The subject to look up.
Returns:
boolean : True if the subject is locked, false if the subject is unlocked.
locked ( string subject , boolean locked ) -> ( am.dialogue_component )
Sets if a dialogue subject is locked or unlocked for this dialogue component. Unlocked subjects will be available to use in dialogue.
Parameters:
string subject : The subject to lock or unlock.
boolean locked : Sets is the subject is locked or unlocked.
Returns:
am.dialogue_component : This
available ( string dialogue_id ) -> ( boolean )
Returns if the given dialogue is available from this component.
Parameters:
string dialogue_id : The dialogue id to look up.
Returns:
boolean : True if the dialogue is available.
available ( string dialogue_id , boolean available ) -> ( am.dialogue_component )
Sets if the given dialogue will be available from this component.
Parameters:
string dialogue_id : The dialogue id to set.
boolean available : The availability of the given dialogue.
Returns:
am.dialogue_component : This
attached_to ( ) -> ( am.game_object )
Returns the game object this dialogue component is attached to, can be nil.
Returns:
am.game_object : The game object this is attached to.
attached_to ( am.game_object game_object ) -> ( am.dialogue_component )
Attaches this dialogue component to a game object, can be nil.
Parameters:
am.game_object game_object : The game object to attach to.
Returns:
am.dialogue_component : This
on ( string event_type , function listener , table content = nil ) -> ( boolean )
Adds an event listener for an event fired on this dialogue component. eg:
 character:on("talkTo", function(event)
     am_log("Character talked to")
 end)
Parameters:
string event_type : The event type or name to trigger on
function listener : The function to call when the event is fired.
table content = nil : An option context for the listener to be called with.
Returns:
boolean : True if the event was added successfully.
off ( string event_type , function listener , table context = nil ) -> ( boolean )
Removes an event listener from this character. eg:
 function talkToOnce(event)
     am_log("Character talked to once")
     character:off("talkTo", talkToOnce)
 end
 character:on("talkTo", talkToOnce)
Parameters:
string event_type : The event type the listener was listening for.
function listener : The listener function to remove.
table context = nil : The context which the listener was going to be called with, this is only optional if the listener was added with no context.
Returns:
boolean : True if the event listener was successfully removed.
has_event_listener ( string event_type ) -> ( boolean )
Returns true when there is an event listener for the given event_type.
Parameters:
string event_type : The event type to look up.
Returns:
boolean : True if there is any event listener that will be trigged by this event type.