QuestJS icon indicating copy to clipboard operation
QuestJS copied to clipboard

examine function not printing its return value

Open Woodhouse3D opened this issue 1 year ago • 3 comments

I started working on a dynamic todo list item, and I noticed some weird behavior with the examine function. Here's my code:

createItem("todo_list",TAKEABLE(), {
  alias: "To-Do List",
  loc: "Cave",
  examine: function() {
    let x = "To Do:|"
    x += "kidnapp princess|collect tribute|deal with rival drake|perch magestically|read the kobolds a bedtime story"

    return x
  }
})

Examining the object doesn't print the value, and I get an error: "Warning for todo_list: The 'examine' function attribute returns a value; it probably should not" However in the "attributes for items" docs its says that its valid to have this function return a value.

Woodhouse3D avatar Jan 17 '25 04:01 Woodhouse3D

"Warning for todo_list: The 'examine' function attribute returns a value; it probably should not"

The dumb GitHub search can't find anything when I search for bits and pieces of that error message. This is as close as I got in the terminal:

kv@DESKTOP-HALFFAST:/mnt/c/Users/kv/Documents/GitHub/QuestJS$ grep -InHr "warningFor" *
lib/_util.js:440:function warningFor(o, msg) { log('Warning for ' + o.name + ': ' + msg) }
lib/_world.js:333:        warningFor(item, "In an unknown location (" + item.loc + ")");
lib/_world.js:337:        if (!item.tellOptions || item.tellOptions.length === 0) warningFor(item, "No tellOptions for consultable/NPC")
lib/_world.js:338:        if (!item.askOptions || item.askOptions.length === 0) warningFor(item, "No askOptions for consultable/NPC")
lib/_world.js:345:          if (!item[key] instanceof Exit) warningFor(item, "Exit " + key + " is not an Exit instance.")
lib/_world.js:346:          if (item[key].name !== '_' && !w[item[key].name]) warningFor(item, "Exit " + key + " goes to an unknown location (" + item[key].name + ").")
lib/_world.js:349:          if (item[key] instanceof Exit) warningFor(item, "Attribute " + key + " is an Exit instance and probably should not.")
lib/_world.js:363:            if (test.testOutput.length > 0) warningFor(item, "The 'desc' attribute for this location is a function that prints directy to screen; should return a string only: " + item.name)
lib/_world.js:365:              warningFor(item, "The 'desc' function attribute does not return a string")
lib/_world.js:369:            warningFor(item, "The 'desc' function caused an error")
lib/_world.js:374:          warningFor(item, "The 'desc' attribute for this location is neither a string nor a function")
lib/_world.js:378:        if (!item.msg && !item.script) warningFor(item, "Topic has neither 'script' or 'msg' attribute")
lib/_world.js:379:        if (item.msg && typeof item.msg !== 'string') warningFor(item, "The 'msg' attribute for this topic is not a string")
lib/_world.js:380:        if (item.script && typeof item.script !== 'function') warningFor(item, "The 'script' attribute for this topic is not a function")
lib/_world.js:391:            warningFor(item, "The 'examine' function caused an error")
lib/_world.js:397:          warningFor(item, "The 'examine' attribute for this item is neither a string nor a function")
kv@DESKTOP-HALFFAST:/mnt/c/Users/kv/Documents/GitHub/QuestJS$

NOTE: My terminal didn't like it when I searched "errormsg". The terminal app crashed every time I tried. (Probably something to do with my laptop's WSL setup.)

KVonGit avatar Jan 17 '25 21:01 KVonGit

I also cannot find that error message anywhere. If you look in lib/_world.js, around lines 380 to 390, the examine function is tested for objected, and that is where I would expect the error message to be.

But as you say, it is valid to return a string. Are you using an older version? Are you using a release or downloading the code straight from GitrHub? You get pretty much the same thing either way, but the latter is a bit more recent. That said, looking at the file history, the part where I expect the code to be has not changed for three years or more.

ThePix avatar Jan 30 '25 21:01 ThePix

Six months later...

I finally got around to porting a game and testing different things...

This works for me (I only changed the loc value, to put it in my starting location):

createItem("todo_list",TAKEABLE(), {
  alias: "To-Do List",
  loc: "kowwsChasm",
  examine: function() {
    let x = "To Do:|"
    x += "kidnapp princess|collect tribute|deal with rival drake|perch magestically|read the kobolds a bedtime story"

    return x
  }
})

> x to-do list

To Do:

kidnapp princess

collect tribute

deal with rival drake

perch magestically

read the kobolds a bedtime story
>

KVonGit avatar Jul 12 '25 19:07 KVonGit