Text Processor If/If Not errors

I'm trying to understand how msg() works compared to how it used to in Quest 5.8 in regards the either{} equivalent code If/If Not{} and I'm struggling to understand why it doesn't work how I want it to, I tried to look at the Git Hub Wiki but there wasn't any clear answer there as far as I could see.

Here's my example:

data.js

"use strict"

createItem("me", PLAYER(), {
  loc:"lounge",
  synonyms:['me', 'myself'],
  examine: "Just a regular guy.",
})

createRoom("lounge", {
  desc:"The lounge is boring, the author really needs to put stuff in it.",
})

createItem("Lamp", {
    alias: "Toggle Lamp",
    examine: "",
    loc: "lounge",
    hereVerbs: ["Interact"],
    bLampIsOn: false,
    interact: function () {
        msg("<a href=\"javascript:void(0);\" onclick=\"ToggleLamp(w.Lamp)\">Toggle Lamp {if:w.Lamp.bLampOn:Off:On}</a>")
    },
})

function ToggleLamp(oLamp) {

    if (oLamp.bLampIsOn) {
        oLamp.bLampIsOn.false
    }
    else {
        oLamp.bLampIsOn.true
    }
    msg("The lamp is now turned {if:oLamp.bLampOn:On:Off}")
}

code.js

"use strict"

commands.unshift(new Cmd('interact', {
    regex: /^(?:interact) (.+)$/,
    objects: [{
        scope: parser.isHere
    },
    ],
    default:
        function (item) {
            msg("You can't do that...")
            return false
        },
}))

I get this error for the top line:

The text process cannot handle attributes of attributes, so failed to deal with: w.Lamp.bLampOn
_text.js:336 (3) ['w', 'Lamp', 'bLampOn']
0: "w"
1: "Lamp"
2: "bLampOn"
length: 3[[Prototype]]: Array(0)
ERROR: Failed to find object 'w.Lamp.bLampOn' in text processor 'if/ifNot' (<a href="javascript:void(0);" onclick="ToggleLamp(w.Lamp)">Toggle Lamp {if:w.Lamp.bLampOn:Off:On}</a>)

and this error for the bottom line in the ToggleLamp() function

ERROR: Failed to find object 'oLamp.bLampOn' in text processor 'if/ifNot' (The lamp is now turned {if:oLamp.bLampOn:Off:On})

Also one last thing is also using the direct implant method, I know the below is just going to print true or false but this doesn't work either.

msg("The lamp is now turned {oLamp:bLampOn}")
ERROR: Attempting to use unknown text processor directive 'oLamp' (The lamp is now turned {oLamp:bLampOn})

Can anyone help me to figure out what I'm doing wrong with these 3 methods please and how you fix/work around them?


I'm not familiar with this engine, but the first thing that jumps out at me is the line:

  • oLamp.bLampIsOn.false

If I understand JS handling of undefined values correctly, that would cause oLamp.bLampIsOn to become an object (if it doesn't already have a value), and then fetch the value of that object's false property. But then you never do anything with that value.

Is it possible you meant:

  • oLamp.bLampIsOn = false

Ah I meant to refer to bLampIsOn for all uses of the Lamp attribute. The engine is QuestJS v1.4 btw.


Okay I replaced everything and still get errors with the 2nd part:

function ToggleLamp(oLamp) {

    if (oLamp.bLampIsOn) {
        oLamp.bLampIsOn = false
    }
    else {
        oLamp.bLampIsOn = true
    }
    msg("The lamp is now turned {if:oLamp.bLampIsOn:On:Off}")
}

ERROR: Failed to find object 'oLamp.bLampIsOn' in text processor 'if/ifNot' (The lamp is now turned (if:oLamp.bLampIsOn:On:Off})

EDITED THE CODE. The first code I posted was overcomplicated.

data.js

"use strict"

createItem("me", PLAYER(), {
  loc:"lounge",
  synonyms:['me', 'myself'],
  examine: "Just a regular guy.",
})

createRoom("lounge", {
  desc:"The lounge is boring, the author really needs to put stuff in it.",
})

createItem("Lamp", {
    alias: "Toggle Lamp",
    examine: "",
    loc: "lounge",
    hereVerbs: ["Interact"],
    bLampIsOn: false,
    interact: function () {
      msg("<a href=\"javascript:void(0);\" onclick=\"ToggleLamp(w.Lamp)\" id=\"lamptoggler\">Toggle Lamp {if:Lamp:bLampIsOn:true:Off:On}</a>")
    },
})

function ToggleLamp(oLamp) {
  var onOff; // Added this
  if (oLamp.bLampIsOn) {
        //oLamp.bLampIsOn.false // <- this was causing an error
        oLamp.bLampIsOn = false;
        onOff = "On"; //Added this
    }
    else {
        //oLamp.bLampIsOn.true // <- this was causing an error
        oLamp.bLampIsOn = true;
        onOff = "Off";
    }
    msg("The lamp is now turned " + onOff + "."); // <- altered this

    /*
      Deactivate the link from the game text,because it will not change On to Off
       in that on-screen text when the lamp is toggled.
    */
    var s = document.getElementById('lamptoggler').textContent;
       document.getElementById('lamptoggler').parentElement.textContent = s;
}


Here's where I found half of that:

https://github.com/ThePix/QuestJS/wiki/Controlling-text-with-the-text-processor#if-and-ifnot

https://github.com/ThePix/QuestJS/wiki/Controlling-text-with-the-text-processor#ifis-and-ifnotis


If you like concise code, you could reduce that a little:

function ToggleLamp(oLamp) {
    msg("The lamp is now turned " + ((oLamp.bLampIsOn = !oLamp.bLampIsOn) ? "On" : "Off") + ".");

    /*
      Deactivate the link from the game text,because it will not change On to Off
       in that on-screen text when the lamp is toggled.
    */
    var s = document.getElementById('lamptoggler').textContent;
       document.getElementById('lamptoggler').parentElement.textContent = s;
}

Yippee! I love to learn more concise ways to code.

What about the bit when I disable the link?

I bet you know a more eloquent way to do that, mrangel. (In fact, I think you've shown me before, but I can't find the old post.)


Hey great stuff guys, thank you so much :)
I still have a lot to learn about JS in general and how QuestJS uses it too.


This topic is now closed. Topics are closed after 14 days of inactivity.

Support

Forums