Skip to content
selfsame edited this page Jan 18, 2015 · 1 revision

dispatch module

core.dispatch

Dispatchable functions are called and caught by rule declarations in the game/ module. They provide the core functionality of the game scenario.

A dispatch rule has the following parts:

#lifecycle-decorator( predicate argument guards)
@check("entity", non("container"))
#def name-symbol(arguments of same count as predicate guards)
def close(a, b):
  say("You can't close that.")
  return False

Multiple rules can be declared for a function-name. game/ module load order dictates the rule order. Core modules should cover general use, followed by more specific refinement.

dispatching is routed by: *function name *argument arity *lifecycle version *successful predicate application

calling dispatching functions

call("fname", 1, [])
# call first applicable @check rule, if one exists and it returns True, continue
# call first applicable @before rule
# call first applicable @given rule
# call first applicable @after rule
# return @given call value if any

stack("fname", 1, [])
# call first applicable @check rule, if one exists and it returns True, continue
# call first applicable @before rule
# call ALL applicable @given rules and make list of return values
# call first applicable @after rule
# return list of @given values

act_stack("fname", 1, []) #name subject to change!
# call first applicable @check rule, if one exists and it returns True, continue
# call first applicable @before rule
# call first applicable @given rule
# call first applicable @after rule
# return list of [@before, @given, @after] values

Function dispatching is modeled after the functions/actions/rulebooks of the inform7 language. We use a unified system, as opposed to having separate dispatching schemes for general functions and game-world specific event calls.

a module with rule declarations or call/stack use needs: from mud.core import *

Rational

  1. Dispatching functions by argument types/arity is a feature of many languages, and allows some useful design patterns.
  2. Entities are combinations of components. Predicate dispatch facilitates this.
  3. Decentralization. You can release 'libraries' of behavior without having to override generic functions, this means libraries can compose easily.
  4. Decoupled. If components change structure, predicates can be updated to preserve the semantic references.
Clone this wiki locally