Error when using HandleSingleCommand and ShowRoomDescription()

When using the command HandleSingleCommand("look") or the command ShowRoomDescription()
the look command works but I still get this error
Error running script: Error evaluating expression 'ListCount(object.alt)': ListCount function expected list parameter but was passed 'null'

Is there a way around this?


This script commands are working. Do you still have the textprocessor command {rndalt:object} in your room description? Try to remove it, then it should work


The only place in the core code that the expression ListCount(object.alt) appears is in the function ProcessTextCommand_RandomAlias.

If this is happening when you show a room description, the description must be using the {rndalt text processor command for an object which doesn't have any alternate names. Really, I think that in this case the function should explicitly check that the attribute exists.

I think it should be:

  <function name="ProcessTextCommand_RandomAlias" type="string" parameters="section, data">
    objectname = Mid(section, 8)
    object = ObjectForTextProcessor(objectname)
    if (object = null) {
      return ("@@@open@@@" + ProcessTextSection(section, data) + "@@@close@@@")
    }
    else if (HasAttribute (object, "alt")) {
      count = ListCount(object.alt)
      if (count > 0) {
        return (ListItem(object.alt, GetRandomInt(0, count - 1)))
      }
    }
    return ("")
  </function>

(If you're not comfortable modifying core functions, you could wait for someone else to fix it; or make sure that all objects have an alt attribute)

Solutions for the web editor:

  1. Make sure all objects have an alt attribute (in the start script):
foreach (obj, AllObjects()) {
  if (not HasAttribute (obj, "alt")) {
    obj.alt = Split(GetDisplayAlias (obj))
  }
}

or

  1. Change the script at runtime (again in the start script):
newscript => {
  objectname = Mid (section, 8)
  object = ObjectForTextProcessor (objectname)
  if (object = null) {
    game.textprocessorcommandresult = "@@@open@@@" + ProcessTextSection(section, data) + "@@@close@@@"
  }
  else if (HasAttribute (object, "alt")) {
    game.textprocessorcommandresult = PickOneString (object.alt)
  }
  else {
    game.textprocessorcommandresult = ""
  }
}
DictionaryAdd (game.textprocessorcommands, "rndalt:", newscript)

Thanks Pertex and mrangel.

You are correct as I was testing the command {rndalt:object} in the room description.


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

Support

Forums