unique aliases

I'm still playing around with some of the parser stuff, but that's a big project. In the mean time, I'm coming up against a problem with the 'toy' game I'm building. I realise that if I can get my modified GetScope() working, I'll be able to do this in a much simpler way.

(Here's an explanation of the problem, and my thought process as I look for solutions; feel free to skim it, because the question's all the way down at the end)

> Put potato in chest
Please choose which 'potato' you mean:
1: potato
2: potato
3: potatoes
4: potatoes
5: potatoes
6: pile of potatoes

(this is in the middle of a puzzle where your character is inexplicably restricted to transferring potatoes between containers all at once. The classic puzzle where you've got a 3 pint jug and a 5 pint jug, and you have to measure 4 pints of water. So obviously, not being able to distinguish the potatoes is a pain)

Okay then… I can solve this. I can have a script give each pile of potatoes a unique name.

switch (this.parent) {
  case (pov.parent) {
    suffix = "on the floor"
  case (pov) {
    suffix = "in your pocket"
  default {
    if (GetBoolean (this.parent, "is_character")) {
      suffix = GetDisplayName(this.parent)+"’s"
    else if (HasAttribute (this.parent, "open")) {
      suffix = "in the "+GetDisplayName(this.parent)
    else {
      suffix = "on the "+GetDisplayName(this.parent)
this.alias = this.basename + " ("+suffix+")"

Or something like that; just thinking about this so far. No sense implementing it yet, if it's going to turn out I can't use it.

Okay… I want to have a different alias for disambiguation, than what is displayed when looking at the room or at a container. Fine, I can do that.
What I do is, I make that script to make the names unambiguous. I set it as a turn script, which every turn looks at the current visible scope (room and inventory), identifies any items which have the same alias, and adds a suffix to them. Actually, it probably makes sense to add the alias-with-suffix to an object's alt first; and then for each item with a duplicate alias, change the displayed alias to any unique entries in the alt list.

I'm implementing a function GetUniqueAlias(object, objectlist scope); which should return one of the object's aliases, not shared by any other item in the scope. As it stands, I can have a turn script loop over the currently visible objects changing their aliases (and presumably switching back to the default name if there's no colliding names). When I've solved the much more complex problem (a bodged set of workarounds to let me override GetScope()), I'll be able to have GetScope() call GetUniqueAlias(), removing the need to actually change the object's alias (and meaning that it will only add a suffix if there's duplicate items within the current command's scope).

But for now, I still have one problem:

You are in a test room.
You can see a potato (on the floor), a banana and a sturdy table (on which there is a potato (on the sturdy table), a silver plate (on which there is six potatoes (on the silver plate)) and a treasure chest (in which there is a potato (in the treasure chest)))

Q1: Is there a way to change the alias of an item for the purposes of commands, but show a different one in object lists?
I know there's a separate alias and listalias (I'm currently using listalias to indent items that are in nested containers, to make the inventory easier to parse at a glance). But I don't think there's any alternates that are looked at either by the scripts in CoreParser, or by FormatObjectList. If there is, it makes this a whole lot easier.

If not… I override the 'look' and 'lookat' commands, so that they set the alias of everything in scope back to its basename, then include the standard 'look' behaviour, then add the suffixes back on. But that doesn't help when you're walking into a new room. Unless I untick "Show room description when entering a room", and add it back into the "Script when entering a room" box.
Q2: Will this work? Is it worth sinking a couple of hours into, or will I find out that it doesn't work?
Q3: Will changing the room descriptions like that cause any problems I haven't thought about?
Q4: Is it likely to be easier just to leave this until I can include it in my modified version of the parser?

Oh, and it's good that I wrote this. Because while I was writing this out, I spotted something hadn't thought about before. I have an object alias "potatoes (in box)". So if the player types put potatoes (in box) in chest, will it parse correctly? Or will it ask which potatoes you mean and then complain that you can't see a "box) in chest"? Does the parser attempt to cope with this at all? I don't think I've seen backtracking in the code I've looked over so far. It's unlikely to come up, because a player is only likely to see those names in the disambiguation menu, but I'm still interested to know.

And if you read this far, thanks :)

I would try overriding FormatObjectList to use a different attribute. Not sure if it would work, but I think tha would be easier than changing the parser side.

That's what I was thinking. The simplest way I could think of to do that is overriding both 'look' commands, changing the aliases back to their basenames, calling the standard command, and then re-adding the suffixes where necessary.
(Really hate not being able to override functions directly)

Log in to post a reply.