I’m currently in the process of porting Graham nelson’s Curses to Dialog, based on various forms of release 16’s disassembly. I needed to implement Inform 6’s tasks, which in Curses are defined as constants to reference the task name and in turn refer to an array of scores. This can be represented as a map, hence my reply in this topic.
I’ve implemented this using Dialog’s ingenious unification. Instead of using constants, the names, and thus indices, are defined as rules.
When queried, these can be quite powerful as they not only provide an index based on the rule definition, but also the name based on the index for a reverse lookup.
As an example, here’s my award rule, as well as the top 3 achievements from Curses:
(score @hamburg 1)
(score @torch 2)
(score @joshua 3)
%% The task list
(global variable (taskScores [3 7 7]))
%% The award rule, which does the lookup
(award $taskName)
(score $taskName $index)
(taskScores $list)
(nth $list $index $points)
(increase score by $points)
If the index is known, we could look up the name as well:
(score $taskName 2)
%% $taskName is now @torch
Hope this is useful and showcases another way of implementing maps.
To modify this further, we could have sublists for $taskScores, and append to it when a task is done. Or, better yet, have a second list with the task indexes and if the list contains an index, the task is done. Of course this is outside the scope of this topic, I’m mentioning it for completeness’s sake only.
I really like how Dialog makes one think outside the box, even though when porting a reasonably huge game like Curses, it can be a bit frustrating at times