DevJoy.Scene.Condition (DevJoy v2.0.0)

View Source

Conditions are used to choose one of the available choices based on their action which is invoked at runtime. The character would be fetched at runtime making its data customisable using a data module.

Usage

The condition always requires a character id, action and possible choices.

defmodule MyApp.SceneName do
  use DevJoy.Scene

  part :condition do
    condition :john_doe, &MyApp.some_func/1 do
      choice :choiceA, goto(:partA)
      choice :choiceB, goto(:partB)
    end
  end
end

Summary

Field types

The type representing the action of the condition. Action in a 1-airty function that takes a character struct and returns a choice content.

Main

The condition structure contains the following keys

t()

The type representing the condition structure.

Field types

action()

@type action() :: (DevJoy.Character.t() -> DevJoy.Scene.Choice.content())

The type representing the action of the condition. Action in a 1-airty function that takes a character struct and returns a choice content.

If the function returns a non-existent content the default action would be is called which logs a debug message about the wrong content.

Main

%DevJoy.Scene.Condition{}

(struct)

The condition structure contains the following keys:

  • action - a function to be called to choose one of the available choices
  • character - a character associated with the condition or nil

t()

@type t() :: %DevJoy.Scene.Condition{
  action: action(),
  character: DevJoy.Character.t() | nil
}

The type representing the condition structure.