ThePix / QuestJS

A major re-write of Quest that is written in JavaScript and will run in the browser.
MIT License
66 stars 13 forks source link

TAKE ALL - Nothing prints when there's nothing to take. (TEMPORARY fix) #29

Closed KVonGit closed 3 years ago

KVonGit commented 3 years ago

When there is nothing at all to take and the player enters TAKE ALL, there is no response at all.

EXAMPLE 1

image)


This seems to temporarily patch that:

findCmd('Take').script2 = findCmd('Take').script

findCmd('Take').script = function(objects,matches){
    if (objects[0].length < 1 && parser.currentCommand.all) {
        //Tried to TAKE ALL when there is nothing to take!
        var verbUsed = parser.currentCommand.cmdString.replace(/ .*/,'').toLowerCase()
        metamsg("There is no ALL to "+verbUsed+"!")
    }else{
        findCmd('Take').script2(objects,matches)
    }
}

EXAMPLE 2

image

KVonGit commented 3 years ago

PS

Also see this: Quest 6: HACK - Adding the OOPS command to v0.3

It seems to involve the same parser functions, but I didn't know that while hacking TAKE ALL.

ThePix commented 3 years ago

Only had time to take a quick look. It is a bug. The bit that should deal with it is lines 281 to 285 in _parse.js. That works for DROP ALL, and it is not obvious why it does not for GET ALL.

KVonGit commented 3 years ago

I'll take a shot.

How do I see the parser.msg output?

I have settings.playMode on "dev", but none of the commands work (PARSER, INSPECT \, CMDS, etc).

https://github.com/ThePix/QuestJS/wiki/Debugging#debugging-commands

The only thing that works for me is the walkthrough, and it works perfectly.


EDIT

I found the parser.debug setting.

KVonGit commented 3 years ago

OK...

I removed my "fix" and moved one block of code down a few lines.

image


I moved this:

        if (list.length === 0) {
          res.error = cmd.nothingForAll ? cmd.nothingForAll : lang.nothing_msg;
          res.score = -1;
          return res;
        }

It was lines 281 - 285.

I moved it to what is currently line 300.

        list = list.filter(function(el) { return !exclude.includes(el); });  //This was line 299 before KV moved the next block.
        if (list.length === 0) { //KV moved this here to fix TAKE ALL
          res.error = cmd.nothingForAll ? cmd.nothingForAll : lang.nothing_msg; //KV moved this here to fix TAKE ALL
          res.score = -1; //KV moved this here to fix TAKE ALL
          return res; //KV moved this here to fix TAKE ALL
        } //KV moved this here to fix TAKE ALL
        if (list.length > 1 && !cmd.objects[i].multiple) {
          res.error = no_multiples_msg;
          res.score = -1;
          return res;
        }
ThePix commented 3 years ago

Thanks, that looks to fix it. The message is not ideal, but is obviously trying to catch all situations.