Hello,
I have found out that very often I want particular trigger to work only in certain context (depending on previous lines). As a solution to this I track the state by a number of flags (as in_combat=1, bashed=0, skill_lag=1 ... etc.) but the whole script soon starts to be quite complex and hard to understand.
Maybe better approach would be finite state machine paradigm where the script would track current "state". Each state would have it's own triggers, aliases, timers and actions. Depending on mud input (trigger), user output (alias) or time elapsed (timer), the state might change to another state with different sets of triggers, aliases etc.
The state change should include:
This seems to be extremely powerful approach which would enable to easily create context sensitive triggers, e.g. empty line can be triggered only in combat to separate the combat rounds, mobs in room can be parsed only after the description of room arrived or after recent look or movement input from player.
I'm not experienced with Lua programming and any suggestion how to implement such a state machine in Lua would help. I guess it would involve using the tables but I can't figure out how to do it elegantly.
I have found out that very often I want particular trigger to work only in certain context (depending on previous lines). As a solution to this I track the state by a number of flags (as in_combat=1, bashed=0, skill_lag=1 ... etc.) but the whole script soon starts to be quite complex and hard to understand.
Maybe better approach would be finite state machine paradigm where the script would track current "state". Each state would have it's own triggers, aliases, timers and actions. Depending on mud input (trigger), user output (alias) or time elapsed (timer), the state might change to another state with different sets of triggers, aliases etc.
The state change should include:
- Removal (or disabling - I'm not sure which is better) of old triggers, timers, aliases
- Definition (or enabling) of new triggers, timers and aliases
- Execution of predefined actions
This seems to be extremely powerful approach which would enable to easily create context sensitive triggers, e.g. empty line can be triggered only in combat to separate the combat rounds, mobs in room can be parsed only after the description of room arrived or after recent look or movement input from player.
I'm not experienced with Lua programming and any suggestion how to implement such a state machine in Lua would help. I guess it would involve using the tables but I can't figure out how to do it elegantly.