-
Couldn't load subscription status.
- Fork 9
scope
Inform7 has a defined scope behind every action. The subject(first arg) is implicit, and things like the room and it's contents are also available to modify action dispatch or action evaluation.
For now, we're not putting any 'shadow scope' behind the action calls. Scope should be determined as needed, using provided arguments (extra arguments are easily used to flavor things like the current action name, location, etc.).
Separate actions can also be invoked with a scope collection as an argument.
Scope itself is currently the result of recursive action cascades. Usually they are used to get lists to search when matching player input nouns, but handle other scoping (think determining what items to list when describing a collection)
@action
@given(player, equals("walk"))
def check_scope_while(e, a):
return the(location(e),"exits").keys()
@action
@given(player, equals("drop"))
def check_scope_while(e, a):
return act("check_inventory_scope", e)
@action
@given(player)
def check_scope(a):
inv = act("check_inventory_scope", a)
loc = location(a)
res = act("check_scope", a, loc)
return inv + resThis module does some decent parsing using regex to find the verb, noun(s), strip articles, and find 'within' and 'adverb' connections between the predicates (the subject is basically always the player for input commands)
Further refinements could make adding new patterns and parsed output formats more programatic.
tests = ["look", "look at coin in the box",
"take the lamp inside of the box",
"look at the first locker inside the boat",
"put the second coin inside of the third cup"]
print map(determine, tests)
#[['look'],
#['look', ['container', 'box'], ['noun', 'coin']],
#['take', ['container', 'box'], ['noun', 'lamp']],
#['look', ['container', 'boat'], ['noun', 'first locker']],
#['drop', ['noun', 'second coin'], ['noun', 'third cup']]]Knowing a relational containment noun, we can narrow the scope with some pleasant results:
~ ~ a small treehouse. ~ ~
It's tiny and crudely built.
You see an open chest(containing a closed coin purse, a book and three coins).
exits: down
♥7/7►look purse
you look at a closed coin purse inside the chest.
<no desc>
Inside it you see a coin.
♥7/7►get coin in the purse
you pick up the coin from inside the coin purse in the chest.
♥7/7►inv
You have a coin.
♥7/7►a mouse walks in.
put coin in chest
you put the coin into an open chest the floor.
♥7/7►look
~ ~ a small treehouse. ~ ~
It's tiny and crudely built.
You see an open chest(containing a closed coin purse, a book and four coins).