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

examine function not printing its return value #127

Open
FloridaChristopher opened this issue Jan 17, 2025 · 2 comments
Open

examine function not printing its return value #127

FloridaChristopher opened this issue Jan 17, 2025 · 2 comments

Comments

@FloridaChristopher
Copy link
Contributor

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.

@KVonGit
Copy link
Contributor

KVonGit commented Jan 17, 2025

"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.)

@ThePix
Copy link
Owner

ThePix commented Jan 30, 2025

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.

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

No branches or pull requests

3 participants