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

[Help] The ol' Firebase createObj() issue.

1420088663

Edited 1420103977
I've got a fun new script in the works that creates a giant GUI to replace the pen and paper inventories I'm not fond of. However, I can't seem to get rid of this issue, despite trying all of the many workarounds you clever coders have posted in the past year or so. As a reminder, anytime you try to modify an object after using the createObj() function, you get an error in the console that fixes itself after you hit "Save Script." Here's my code. I'm currently using a workaround that TheAaron posted in September. (it's the first function in the script). It's not called until the very last function in the script. Any help would be appreciated. <a href="https://www.youtube.com/watch?v=sp1KACYziFg&feature=youtu.be" rel="nofollow">https://www.youtube.com/watch?v=sp1KACYziFg&feature=youtu.be</a> <a href="https://gist.github.com/SplenectomY/1a8858b8a713a06db669" rel="nofollow">https://gist.github.com/SplenectomY/1a8858b8a713a06db669</a>
1420090784
The Aaron
Pro
API Scripter
Can you post the error when you have only this script running? There is a modified version in this thread that handled the issue when it's an attribute being created: <a href="https://app.roll20.net/forum/post/1462045/help-wit" rel="nofollow">https://app.roll20.net/forum/post/1462045/help-wit</a>...
1420092450

Edited 1420092539
Here's the error: /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 () 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 ( And when I used your code to fix it: TypeError: Cannot call method 'replace' of undefined at fixedCreateObj (evalmachine.:9:50) at create_inv (evalmachine.:581:3) at evalmachine.:606:7 at eval ( I'm going to be editing the OP shortly with the video I made for context. I'm creating a graphic rather than an attribute, so I think there are some changes I need on Steve's code if I wanted to use it.
1420093177

Edited 1420093767
Video has been uploaded. This is the only script I am running on a fresh campaign. It's also on the Dev server.
1420095045
The Aaron
Pro
API Scripter
Man, it seems like I've had that exact problem before. I spent a long time rewriting code without solving it. :/
Yuk. It might be time to really push for an official fix from the devs. In the mean time, I'll do as much research as I can, as usual.
1420096808
The Aaron
Pro
API Scripter
Minimal repeatable case is always nice.
Use one command to create the object and then a second command to do whatever it is you're wanting to do with it.
1420097939
The Aaron
Pro
API Scripter
This case is slightly more subtle, but that's possibly a good starting point. With the case he has, it behaves like createObj is returning undefined, and isn't fixable with the standard hack.
1420098688

Edited 1420099325
HoneyBadger said: Use one command to create the object and then a second command to do whatever it is you're wanting to do with it. There's some merit to this. On a hunch, I ran the function only on on("ready",function() instead of on on("change:graphic",function() and no error was thrown. Of course, that means I'd still have to press a button for the script to be functional. I'll see if I can adjust my script so that newly created objects aren't touched by the script until it fully finishes a cycle, because having this function being called by the "change:graphic" event is very convenient. However, this method works without needing the hack, so its definitely related to a new object getting some properties set before the script "cools down", I guess. So this doesn't fix the problem, it just works around it.
on:ready only fires when you enter the campaign.
HoneyBadger said: on:ready only fires when you enter the campaign. Right, or when I reload the scripts. What I'm getting at is that something about change:graphic causes the function to fire too many times at once, it seems, which is causing the error. If I have the function fire on ready only, it creates the new object just fine and doesnt throw any errors.
1420100805

Edited 1420105044
Actually, I'm pretty sure that's exactly what's happening. I've called the function to fire on something simpler - change:graphic:gmnotes - and it works perfectly. Too many changes are being detected at once during change:graphic, which somehow causes the error. I'm doing a little more research and I'll report back. EDIT: Spoke too hastily. The script crashes as soon as any attempt is made to run the script's functionality again, which is to check every graphic against the others on the page and adjust some values on the graphics. Without a reload, I'm stuck back at square one.
1420125616
The Aaron
Pro
API Scripter
John C. said: HoneyBadger said: on:ready only fires when you enter the campaign. Right, or when I reload the scripts. What I'm getting at is that something about change:graphic causes the function to fire too many times at once, it seems, which is causing the error. If I have the function fire on ready only, it creates the new object just fine and doesnt throw any errors. Oh! I think what HB might be implying is you should put all your on(...) event handler registration calls inside on('ready'). Currently, you will get called as each item is added to the canvas during campaign load, not just as things are created by the user.
The Aaron said: John C. said: HoneyBadger said: on:ready only fires when you enter the campaign. Right, or when I reload the scripts. What I'm getting at is that something about change:graphic causes the function to fire too many times at once, it seems, which is causing the error. If I have the function fire on ready only, it creates the new object just fine and doesnt throw any errors. Oh! I think what HB might be implying is you should put all your on(...) event handler registration calls inside on('ready'). Currently, you will get called as each item is added to the canvas during campaign load, not just as things are created by the user. OOH. I had no idea. That should save on clunkiness during load. Back to the matter at hand, is there any function that forces the Sandbox to restart? That would at least provide an ample work around while I bring this up to the devs.
1420151182
The Aaron
Pro
API Scripter
Nope.
1420153495

Edited 1420153620
DXWarlock
Sheet Author
API Scripter
Can you not do what Aaron helped me with, and add a delay? I was plagued by the "TypeError: Cannot call method 'replace' of undefined at fixedCreateObj" bug forever on trying to make a token, move it, size it, and apply a tint the instant I made it. adding a 5ms delay to what I was trying to do to it seemed to fix it. Not sure if its applicable here
You mean with setTimeout()? I'll give it a shot and see what happens.
1420160036

Edited 1420160146
... Okay. Adding a 5ms delay with setTimeout() fixed the issue with using fixedCreateObj, and the object was successfully created. I'd call that progress. However, immediately after that, I get this strange error: timers.js:112 first._onTimeout(); ^ TypeError: Property '_onTimeout' of object [object Object] is not a function at Timer.listOnTimeout [as ontimeout] (timers.js:112:15) William, can you link the script where you successfully created a token?
1420163639
The Aaron
Pro
API Scripter
That's probably an error in parameters, what is your code for that?
Much has been trimmed to show just the barebones, but the fixedCreateObj is fired from a change:graphic:lastmove event. The object is succesfully created, and then the script throws that error. <a href="https://gist.github.com/SplenectomY/65f2115b3c06a1" rel="nofollow">https://gist.github.com/SplenectomY/65f2115b3c06a1</a>...
1420175817
The Aaron
Pro
API Scripter
Change your create_inv to this: function create_inv(g_page_id, g_name, g_left, g_top, g_controlledby, g_id, g_wgt, g_vol) { setTimeout(function(){ fixedCreateObj("graphic",{ name: g_name, imgsrc: inv_img, pageid: g_page_id, controlledby: g_controlledby, left: g_left + 350, top: g_top, width: 70, height: 70, bar1_value: 0, bar1_max: g_wgt, bar2_value: 0, bar2_max: g_vol, layer: "objects", gmnotes: "inv inv_" + g_id, ); },5); } setTimeout() expects a function as the first argument. You were passing the result of calling fixedCreateObj(), not a function calling fixedCreateObj(). The above code is passing an anonymous function that will call the fixedCreateObj() after 5ms.
The Aaron said: Change your create_inv to this: *snip* That did the trick. Thank you to all. This was a most enjoyable collaboration. I will be wrapping up the script and introducing it proper now that this bug is behind me.
1420177585
The Aaron
Pro
API Scripter
Cheers!
1420206056

Edited 1420206095
DXWarlock
Sheet Author
API Scripter
John C. said: William, can you link the script where you successfully created a token? Well crap, sorry Im late to the party I just saw this. But seems you got it worked out. I keep forgetting to 'follow' topics I reply to..and never realize someone posted to it as I get no mail. they really should make it so you auto follow topics you reply to, not just the ones you start.
1420214046
The Aaron
Pro
API Scripter
oh.. auto follow would suck for me. I post on too many topics. I'd never get any notices. Maybe add a checkbox next to submit to let you follow. I just load the boards every 5 minutes or so to keep up.. =D
1420217054
Lithl
Pro
Sheet Author
API Scripter
I follow the topics that I truly care about. =) Another forum I frequent gives you a notification whenever someone quotes you. That's actually a pretty nice feature.
1420218467
The Aaron
Pro
API Scripter
That does sound nice!
Promising mod! Great work John./follow topic
1422911848
The Aaron
Pro
API Scripter
BTW, the createObj() bug appears to be squashed in Dev, so HAPPY DAYS!!! =D Also, finally got around to watching this video. =D Thanks for the mention. =D