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

Trouble editing an attribute

September 10 (10 years ago)
esampson
Pro
Sheet Author
So I've been working on this for the past several hours and I'm a bit stymied. I'm having difficulty changing a value after I create it with the API. If I manually create the attribute (going to the Attribute & Abilities tab and selecting +Add) I'm able to change the value just fine using the API, but if I create the attribute with the API then when I try and alter the value I get an error.

Below is a sample piece of code.

on("ready", function(){
    on("add:character", function(obj) {
        var attribute = findObjs({
            _type: "attribute",
            _characterid: obj.id,
            _name: "test"
        })[0];
        if (attribute == undefined) {
            createObj("attribute", {
                name: "test",
                current: "1   2   3",
                characterid: obj.id
            });
        };
        //It all works fine up to this point.
        var attribute = findObjs({
            _type: "attribute",
            _characterid: obj.id,
            _name: "test"
        })[0];
        log(attribute);
        //We are still good at this point.
        //Log is showing a single attribute.
        attribute.set("current","A   B   C");
        //And here is where we fail.
        //We can use this same set of commands
        //on a manually create attribute and
        //it will work fine, but it fails when
        //the attribute is created through the API
    });
});
So does anyone have any insight into what I am doing wrong? When the attribute.set command is enabled I get the cryptic message:
/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1orts, require, module, __filename, __dirname) { function f(a){throw a;}var j=v
However if I have manually created the "test" attribute that same code will have no problem.

Any insight would be much appreciated.
September 10 (10 years ago)
esampson
Pro
Sheet Author
Never mind. I seem to have figured it out.
September 10 (10 years ago)
I just encountered this problem a couple days ago and sent an email in to the mentor contact email about this yesterday.

The error occurs every time the API is used to edit an attribute that was created with the createObj() function. More specifically, it's when the API edits an attribute that was created with createObj() within the same instance of the sandbox. When the sandbox is restarted after a code change, any previously created attributes can be edited without an error. I haven't tested if this occurs with object types other than attributes.

Here's my code for quickly recreating the bug.

on("ready", function() {
var object, type, values;
type = 'attribute';
values = {
name: "Test",
characterid: "-JWKLNK_sW82FYkXIZu3",
current: "1",
max: "2"
};
log("Creating " + type + " '" + values.name + "'");
object = createObj(type, values);
log(object);
log("Setting current to new value");
object.set('current', '2');
log("Finished setting new value");
log(object);
});

Here's the output from the API Console:


Restarting sandbox due to script changes...
Spinning up new sandbox...
"Creating attribute 'Test'"
{"name":"Test","current":"1","max":"2","_id":"-JWW2ih6sPSxsIPxdQPv","_type":"attribute","_characterid":"-JWKLNK_sW82FYkXIZu3"}
"Setting current to new value"
"Finished setting new value"
{"name":"Test","current":"2","max":"2","_id":"-JWW2ih6sPSxsIPxdQPv","_type":"attribute","_characterid":"-JWKLNK_sW82FYkXIZu3"}


/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:1
orts, require, module, __filename, __dirname) { function f(a){throw a;}var j=v
                                                                    ^
Error: Firebase.child failed: First argument must be a non-empty string and can't contain ".", "#", "$", "[", or "]".
    at Error (<anonymous>)
    at Ha (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:12:204)
    at G.W.H (/home/symbly/www/d20-api-server/node_modules/firebase/lib/firebase-node.js:126:213)
    at TrackedObj._doSave (
September 10 (10 years ago)
esampson
Pro
Sheet Author
No. My mistake. I haven't figured it out. I did find a problem with the code I had pasted which I have corrected but the base problem remains.
September 10 (10 years ago)
esampson
Pro
Sheet Author

Jaron K. said:

I just encountered this problem a couple days ago and sent an email in to the mentor contact email about this yesterday.

The error occurs every time the API is used to edit an attribute that was created with the createObj() function. More specifically, it's when the API edits an attribute that was created with createObj() within the same instance of the sandbox. When the sandbox is restarted after a code change, any previously created attributes can be edited without an error. I haven't tested if this occurs with object types other than attributes.
Ah. Thank you. Nice to know that it's a bug and I'm not being mental.

September 10 (10 years ago)
I just found the answer in this conveniently recent thread: https://app.roll20.net/forum/post/1164497/bug-anyone-know-the-work-around-for-this#post-1164588