Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

TypeError: Object [object Object] has no method 'get' at Sandbox.

1383447755
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
var myvarone = findObjs({_type: "character", name: "somename"}); var myvartwo = myvarone.get("controlledby"); Results in: TypeError: Object [object Object] has no method 'get' at Sandbox. Any ideas?
1383455189

Edited 1383455298
findObjs is returning an array, even if there is only one matching object. Either use getObj(), call myvarone[0].get(), or enumerate through the returned list. For something like a Character, you probably want to use getObj() since there would presumably only be one with a given name.
1383463704
Lithl
Pro
Sheet Author
API Scripter
Alternatively, you can use: var myvarone = findObjs({ _type: 'character', name: 'somename' })[0]; This is generally the method I use when I'm certain findObjs will return a length-1 array.
If you are sure that there is only one object matching your query or you only want the first result, getObj() should be more performant. While I'm not positive on the underlying code, I assume that getObj() will stop searching after the first match while findObjs() will need to continue searching all the objects of the given type. This would have minimal impact in many cases, but could inflict a substantial performance penalty if it occurs in a loop.
1383487778

Edited 1383488213
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
I am actually having no success at this.... This is an effort to implement Brain's suggests to <a href="https://app.roll20.net/forum/post/435782/script-what-did-he-say-file-under-roleplay-api#post-438177" rel="nofollow">https://app.roll20.net/forum/post/435782/script-what-did-he-say-file-under-roleplay-api#post-438177</a> And I can't seem to get his suggests to fully to work.
1383488124
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
<a href="https://gist.github.com/baldar/f1b43630015d3059bd1e" rel="nofollow">https://gist.github.com/baldar/f1b43630015d3059bd1e</a>
1383488179
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Lines 63 to 68 I can't seem to simplify
1383520962
Lithl
Pro
Sheet Author
API Scripter
var allCharacters = findObjs({_type: "character"}); for(var c in allCharacters) { var currentCharacter = allCharacters[c]; if (currentCharacter.get("name") == msgApiCommand){ var spokenByid = currentCharacter.get("controlledby"); }; }; Try: var spokenByIds = findObjs({ _type: "character", name: msgApiCommand })[0].get("controlledby").split(","); spokenByIds is now an array of player IDs, or the string "all". You can take action on all of them by iterating over the array: _.each(spokenByIds, function(id) { if (id == "all") { // do something with all players } else { var player = getObj("player", id); // do something with player } });
1383521736
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
WOOT! That got it!
hello