Hi Marnix,
Thanks for your replies and explanation. Here, I’m going to pick up on your reply to my original XVAN problems, later I’ll write about the JSON ideas;
Firstly, thanks for explaining how it works. Following your ideas (working with the COD example), i factored t_drop and t_take_off into common triggers as suggested, thus:
t_take_off
if testflag(%this.f_worn) then
printcr("You take off [the] [%this]")
clearflag(%this.f_worn)
else
printcr("You're not wearing [the] [%this]")
disagree()
endif
t_drop
if testflag(%this.f_worn) then
# trigger(t_take_off)
printcr(" [[Taking off [the] [%this]]")
clearflag(%this.f_worn)
endif
if (owns(o_player, %this)) then
clearflag(%this.f_bypass)
move(%this, owner(o_player))
printcr("[%this]: dropped.")
else
printcr("One must hold something before it can be dropped.")
disagree()
endif
Now, as you mentioned, i can just call these from the objects;
$OBJECT o_cloak
...
d_drop "This isn't the best place to leave a smart cloak lying around."
TRIGGERS
"take off [o_cloak]" -> t_take_off
"drop the [o_cloak]" -> t_drop_cloak
...
t_drop_cloak
if equal(l_location, l_cloakroom) then
if trigger(t_drop) then
setflag(l_bar.f_lit)
endif
else
printcr(d_drop)
endif
This works neatly, where the bulk of the logic is factored out of the verb into the common triggers, yet i can still affect the bar.f_lit
as required.
Quick question; looking at my definition of t_drop
above, why can’t i call trigger(t_take_off)
here (commented out), would be nice to do this and factor more code.
I understand your explanation of how you might implement global triggers. When moving logic (such as drop above) into common triggers, the global trigger would be nice and would avoid having to have “drop the X” -> t_drop on every object that can be dropped. same for “get” if that were factored.
handler ordering
Thanks for this. I see how it goes; object->common->verb. I can also see how i might call trigger(t_something)
and make use of the result. But what would be nice is, if a handler could call the next in the chain (the one that it goes to for nomatch
) but it be a call and not a nomatch
because nomatch
does not come back!
What’s happening is; without being able to manually call (and return from) the super chain, logic must be factored into common handlers like i have done above for “drop”. Since pretty much everything will sooner or later need to be called from an object handler, all verb logic will eventually be in common handlers and none in verbs - which would be a rather perverse state of affairs.
If the version in the verb could be invoked from the object (or common), then it would not have to be factored out.
That’s just my view of it. Of course, it still works by factoring to common triggers.
Will address the JSON ideas next…