The first findObjs() here will find all the objects of type character, the {name: msg.who} ends up being passed as the second parameter to the function, not as a part of the criteria to find characters: // get the player object -- this will be just an object
let user = findObjs( {_type: 'character'},
{name: msg.who},
{caseInsensitive: true});
You'd need to write it like this if you want characters with the same name as the currently talking as selection: // get the player object -- this will be just an object
let user = findObjs( {
_type: 'character',
name: msg.who
},
{caseInsensitive: true});
Assuming that found a character then this code would be searching for all the attributes named max_hits where characterid is undefined . let max_hits = findObjs({
type: 'attribute', // object is an Attribute
name: 'max_hits', // attribute is named 'str'
characterid: user.id // attribute belongs to the character
}); The reason is that findObjs() returns an array, not an object. The array does not have a field .id , so user.id would be undefined . To get around this, you'd probably want to use the first index of the array instead: let max_hits = findObjs({
type: 'attribute', // object is an Attribute
name: 'max_hits', // attribute is named 'str'
characterid: user [0] .id // attribute belongs to the character
});
similarly, if findObjs() found the 'max_hits' attribute, then accessing the .get property will also not do what you expect. Usually, array doesn't have a .get property, but in this case it does (no idea what it is), but it isn't a function, so attempting to invoke it with 'current' causes an exception let max_hitsVal = max_hits.get('current')
What you'd need to do is access the first index of the array and call get on that: let max_hitsVal = max_hits [0] .get('current')
However, that makes the assumption that there was such an attribute. What you would really want to do is check the length of the array (or at least the index you'll be using) to be certain there actually is something there. Putting it all together you'll have something like this: // get the player object -- this will be just an object
let user = findObjs( {
_type: 'character',
name: msg.who
},
{caseInsensitive: true});
if(user[0]){
let max_hits = findObjs({
type: 'attribute', // object is an Attribute
name: 'max_hits', // attribute is named 'str'
characterid: user [0] .id // attribute belongs to the character
});
if(max_hits[0]) {
let max_hitsVal = max_hits [0] .get('current');
}
}
msg.who might not be the name of a character, so it's usually better to either start with a player and find the characters they can access, or pass in the id of a character as part of the command: !atk @{selected|character_id} If you did the above, you would be able to access the second argument just as you've surmised: // split the command into parts at contiguous whitespace
let cmd = msg.content.split(/\s+/);
// handle commands for this script
switch(cmd[0]) { // the first part will be the command
case '!atk': // if the command was !atk
let character = getObj('character',cmd[1]);
if(character){
log('Found the character: '+character.get('name'));
}
break;
} /\s+/ is a regular expression, a special series of characters that specifies how to match certain parts of a string. Regular expressions are specified with / at the beginning and end. \s matches any type of whitespace, so spaces or tabs. + modifies the prior match (\s in this case) to mean 1 or more of something. so /\s+/ will match any sequence of one or more spaces and tabs. Let me know if you have any more questions!