Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An alias including "." doesn't play well with game.multiplecommands #1270

Open
KVonGit opened this issue Dec 5, 2024 · 2 comments
Open

An alias including "." doesn't play well with game.multiplecommands #1270

KVonGit opened this issue Dec 5, 2024 · 2 comments

Comments

@KVonGit
Copy link
Collaborator

KVonGit commented Dec 5, 2024

If game.multiplecommands is true and there is a . in an object's alias, there will be issues.

> x Mr. XanMag. Take beer. Give beer to Mr. Xanmag
Nothing out of the ordinary.
I don't understand your command.
You pick it up.
Mr. XanMag thanks you kindly and gives you the small brass key.
I don't understand your command.


I have a fix based on the code posted by angelwedge in this issue: #1256 (comment)

I'll submit the PR after a little more testing.

@angelwedge
Copy link

I'm not particularly happy with the solution I proposed there; as it only works with verb menus/buttons. Really it should work with typed commands as well.

Second solution would be checking object aliases for dots (during UpdateObjectLinks, maybe?) and making a list to check and escape dots in the same way; but that still only works if the name is exactly right.

My best idea for a solution (still not perfect) would be a later check. After generating a list of partial matches for an object name, you could check if multicommand mode is on, and there are commands remaining in the command queue, and the command string ends with the current string we're trying to match, and the alias contains the last word of the command string immediately followed by a dot. (could also have some additional checks; like the next command in the queue not matching any command regexes on its own; or the first word of the next command being in the possible alias). If so, stick the current and next command strings together with a dot, stick it on the beginning of the command queue, and fire HandleNextCommandQueueItem rather than proceding to the next name to resolve.

@KVonGit
Copy link
Collaborator Author

KVonGit commented Dec 5, 2024

Oh, I didn't even consider the links or the buttons. I only tested this one by typing the commands in a new test game -- with none of the stuff described in that other issue added to it.

You pointed out the flaw with . in an alias in that other issue, but that only seemed like one thing out of many happening in that user's code, haha. So I created this issue by itself to make sure this bug gets addressed in the upcoming release.

Do you think I can/should change this to work with that? Or would that be completely different code? EDIT: I should read these on my actual computer instead of my phone before responding. I apparently need new glasses, heheheh. I see what you're saying.

This is the only function I have modified concerning this, and it seems to work during testing (but I do work at the Overlook Hotel 😄):

  <function name="HandleCommand" parameters="command, metadata"><![CDATA[
    handled = false
    if (game.menucallback <> null) {
      if (HandleMenuTextResponse(command)) {
        handled = true
      }
      else {
        if (game.menuallowcancel) {
          ClearMenu
        }
        else {
          handled = true
        }
      }
    }
    if (not handled) {
      StartTurnOutputSection
      if (StartsWith (command, "*")) {
        SuppressTurnscripts
        msg ("")
        msg (SafeXML (command))
        msg ("Noted.")
        // Added for Quest 5.8
        FinishTurn
      }
      else {
        shownlink = false
        if (game.echocommand) {
          if (metadata <> null and game.enablehyperlinks and game.echohyperlinks) {
            foreach (key, metadata) {
              if (EndsWith(command, key)) {
                objectname = StringDictionaryItem(metadata, key)
                object = GetObject(objectname)
                if (object <> null) {
                  msg ("")
                  msg ("&gt; " + Left(command, LengthOf(command) - LengthOf(key)) + "{object:" + object.name + "}")
                  shownlink = true
                }
              }
            }
          }
          if (not shownlink) {
            msg ("")
            OutputTextRaw ("&gt; " + SafeXML(command))
          }
        }
        if (game.command_newline) {
          msg ("")
        }
        game.pov.commandmetadata = metadata
        if (game.multiplecommands) {
          foreach (alias, metadata) {
            command = Replace (command, alias, Replace (alias, ".", "@@@DOT@@@"))
          }
          commands = Split(command, ".")
          if (ListCount(commands) = 1) {
            game.pov.commandqueue = null
            HandleSingleCommand (Trim(Replace(command, "@@@DOT@@@", ".")))
          }
          else {
            game.pov.commandqueue = commands
            HandleNextCommandQueueItem
          }
        }
        else {
          game.pov.commandqueue = null
          HandleSingleCommand (Trim(command))
        }
      }
    }
  ]]></function>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants