Error when using HandleSingleCommand and ShowRoomDescription()
Brian5757
24 Feb 2020, 13:37When 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?
Pertex
24 Feb 2020, 15:09This 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
mrangel
24 Feb 2020, 15:23The 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:
- 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
- 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)
Brian5757
24 Feb 2020, 22:16Thanks Pertex and mrangel.
You are correct as I was testing the command {rndalt:object} in the room description.