Problem with light switch in tutorial

Problem: The light switch won't do anything, I don't get to read darkDesc. I go into the basement, do switch off light, but it's still "dank" not "dark", so to speak :) Also the exit is still visible and usable.

I created the basement room like this:

createRoom('basement', {
    desc:
        "A dank room, with piles of crates everywhere.",
    darkDesc:
        "It is dark, but you can just see the outline of the trapdoor above you.",
    up: new Exit('kitchen'),
    lightSource: function () {
        return w.light_switch.switchedon ? world.LIGHT_FULL : world.LIGHT_NONE
    },
    // lightSource:
    //     () => w.light_switch.switchedon ? world.LIGHT_FULL : world.LIGHT_NONE,
})

and a switch like this:

createItem('light_switch', SWITCHABLE(true), {
    loc: 'basement',
    alias: 'light switch',
    examine:
        "A switch, presumably for the light.",
})

Pretty much like in the tutorial part 5 (unless I didn't spot a typo of mine).

Or is there something wrong with the example possibly? For example, I don't really know where w comes from (inside the return statement) - but changing it to world made the game refuse to load.

Also, is switchedon correct? The casing looks weird imo, but trying switchedOnor switched_on also didn't work.


Hello Riidom! Welcome to the wonderful world of QuestJS,

For more info on "w" look here: https://github.com/ThePix/QuestJS/wiki/General-notes

The wiki search will be your friend for the adventure you have embarked upon.. upper left hand corner of the screen.

As for your actual problem, I am thinking you are using V1.0 of Quest6 (QuestJS) If so, you are correct, the tutorial will not work as stated. I believe there were some bugs introduced with that version (Pixie please correct me if I am wrong). Pixie has since corrected the issue and has included the fixes in the repository, but it is not part of an official release yet.

In order to run through the tutorial as printed in the wiki, I would suggest either using QuestJS-0-9.zip.
or
The alternative would be to grab the lib folder from the repository and overwriting the lib folder you are currently using. I am using the updated lib files, and the example works correctly.

Steve


That worked, thanks a lot! Went for the "update lib folder" route as well. Now onto the next problem, how to get out of the dark basement... :)


I may have found some bug though; the exit will appear on the compass rose in side bar, but not in text. Of course, the description of the example strongly indicates there is an exit, but the default generated "You can go up." message is not appearing. The docs for isHidden state "[...] see and use this exit."

(are github issues preferred for bugs btw, or doesn't matter a lot whether it's this forum or github?)


Next Edit:

In the beginning of part 6 of the tutorial, where we implement the torch, is following line in the first code snippet:

return this.switchedon ? world.LIGHT_FULL : world.LIGHT_NONE

I found this not to work, but instead

return w.torch.switchedon ? world.LIGHT_FULL : world.LIGHT_NONE

will work. Which reliefed me a bit, because it was much more in line of what I read about w.


I will uploaded some updated files to GitHub (_defaults.js, _world.js and _text.js) to resolve some of this by the end of the day, and updated the tutorial, so it should all work. You can just flag an exit as "illuminated" now.

createRoom("basement", {
  desc:"A dank room, with piles of crates everywhere.",
  darkDesc:"It is dark, but you can just see the outline of the trapdoor above you.",
  up:new Exit('kitchen', {
    illuminated:true,
  }),
  lightSource:function() {
    return w.light_switch.switchedon ? world.LIGHT_FULL : world.LIGHT_NONE;
  },
})

I am not sure about this though:

In the beginning of part 6 of the tutorial, where we implement the torch, is following line in the first code snippet:

return this.switchedon ? world.LIGHT_FULL : world.LIGHT_NONE
I found this not to work, but instead

return w.torch.switchedon ? world.LIGHT_FULL : world.LIGHT_NONE
will work. Which reliefed me a bit, because it was much more in line of what I read about w.

this is a special word in JavaScript that means the object the script is attached to. If the return statement is inside a function that belongs to the torch, it means the torch, so in theory both of those should work fine. They do for me!

ETA: Now uploaded


Hello,
thanks for the updates. I revisited my problem with this and got remembered about some specialities wrt arrow functions. I tried to a) use arrow functions and avoid this, and b) revert to normal function keyword and use this. Both works well, but apparently this inside arrow functions will work not as expected. Most people probably know that, I just leave that here for those who don't.


Log in to post a reply.

Support

Forums