
I have a function that should return either a token object or a character object depending on which one has specific text in the GM Notes section. The problem is that nothing is happening inside the callback function to test for the text. I've tried everything from setting variables declared outside the callback to simply using a return inside the callback. Here's some pseudo code to illustrate:
myFunction (id) {
var obj;
var token = getObj('graphic', id);
if (token && token.get('represents') != '') {
token.get('gmnotes', function(notes) {
if (notes = 'my test') obj = token;
});
if (!obj) {
var char = getObj('character', token.get('represents'));
if (char) {
char.get('gmnotes', function(notes) {
if (notes = 'my test') obj = char;
});
}
}
}
return obj;
}
This function will never return anything but the undefined obj, regardless of whether the GM Notes contain the text I'm testing for. (I expect it to return undefined if neither passes the test.)
Then I tried to just return the already created object inside the callback. It met with the same results:
myFunction (id) {
var token = getObj('graphic', id);
if (token && token.get('represents') != '') {
token.get('gmnotes', function(notes) {
if (notes = 'my test') return token;
});
var char = getObj('character', token.get('represents'));
if (char) {
char.get('gmnotes', function(notes) {
if (notes = 'my test') return char;
});
}
} else {
return null;
}
}
Vigorous logging shows that I am definitely getting those objects, it's just that it all goes silent once inside that callback for the GM Notes. That is, logging happens inside the callbacks, but nothing else.
Is there something else I need to do here? Or what am I missing? Surely this is possible somehow.