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

Campaign() returns 'undefined'? Help, please.

var MyModule = MyModule || (function(){ var icon = createObj("graphic", { _pageid: Campaign().get("playerpageid"), imgsrc: "", left: 35, top: 35, width: 35, height: 35, layer: "gmlayer", isdrawing: true }); }()); This is an extraction of some problem code. Just this by itself throws the error: Cannot call method 'get' of undefined I'm sure as soon as I hit Post Topic, I'll see the obvious. For now, I am stuck on this stupid problem. Any help would be appreciated. PS - nevermind imgsrc. It throws this error even if there is a valid imgsrc. Thanks.
Off the top of my head, I suspect that it's due to the sandbox not being fully set up yet. I'd suggest waiting until the "ready" event has fired before calling anything in the API other than on() (e.g. Campaign() or createObj()). This can be accomplished in a handler for the "ready" event: on("ready", function(){ var icon = ... });