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 .
×

Error when calling ToFront(): "Could not find page for object"

I am receiving a critical error when calling toFront() I am drawing a card this way: cardId = drawCard(fromDeckId, bottomCardId); The card is correctly placed in the Discard pile for the deck.  Then I am playing that card to the table this way: if(cardId){   playCardToTable(cardId, {left: left, top: top, isdrawing: true}); } The card is correctly paced on the table.  Then I look for that card in the deck this way: let cardAfterBeingPlayedToTable = findObjs({   type: 'card',   deckid: fromDeckId,   id: cardId })[0]; The card is correctly found.  Then I'm trying to bring that card to the front, this way: if(cardAfterBeingPlayedToTable){   toFront(cardAfterBeingPlayedToTable); } Or this way: if(cardAfterBeingPlayedToTable){   setTimeout(function() {toFront(cardAfterBeingPlayedToTable);}, 1000); } But then the scripts are disabled with this error: For reference, the error message generated was:  Error: Could not find page for object. undefined This code was working fine for me like 1 week ago, but it now has stopped working for some reason.  Has this toFront()  function changed or is this a bug that needs to be addressed? Or am I doing something wrong? For now I must disable the call to that function as it's disabling the entire set of Scripts... Thank you!
1623698721
The Aaron
Roll20 Production Team
API Scripter
toFront() only works on Graphic objects. The Card object represents the Card as a part of the Deck.  When you play it to the tabletop, a Graphic object with the subtype of "card" and a cardid matching the Card object's ID is created.  If you search for a Graphic object on the current page, you should be able to toFront() that.
Hello, Aaron.  After changing the type from ' card ' to ' graphic ' I was able to succesfully execute toFront (). Thank you for your prompt reply!
1623705161
The Aaron
Roll20 Production Team
API Scripter
Sweet!  No problem. =D
Nevertheless, it would be advisable for the toFront () and toBack () functions to return a friendly message to the console stating the object being passed as a parameter is not a 'graphic' one and then do nothing, instead of suspending the entire scripting for the game and produce that generic error.  It took me a while to realize the problem was right there. Aaron, is it possible for you to request this improvement to those functions?  Or do I submit a separate request for this? Thanks again!
1623764546

Edited 1623764694
The Aaron
Roll20 Production Team
API Scripter
toFront() and toBack() both have some big problems outside counterintuitiveness, but if you'd like a fix for that, it's actually pretty simple to do in your own code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 const __realToFront = toFront ; const toFront = ( obj ) => { if ([ 'graphic' , 'text' , 'path' ]. includes ( obj . get ( 'type' ))){ __realToFront ( obj ); } else { log ( ` toFront () : Object of type "${obj.get('type')}" does not have a physical representation on a map and can not be a target of toFront (). Please only call toFront () on objects of the following type : "graphic" , "text" , "path" ` ); } }; const __realToBack = toBack ; const toBack = ( obj ) => { if ([ 'graphic' , 'text' , 'path' ]. includes ( obj . get ( 'type' ))){ __realToBack ( obj ); } else { log ( ` toBack () : Object of type "${obj.get('type')}" does not have a physical representation on a map and can not be a target of toBack (). Please only call toBack () on objects of the following type : "graphic" , "text" , "path" ` ); } }; You'll need to put that in your own scope, so inside a functions closure or similar. You can report it as a bug, but there's things I'd rather the devs spent their time on (like API access to Journal Folders or the like).
Understood.  I will apply that suggested code to my scope.  I was thinking more in terms of other developers in the future that could experience the same situation.  I will report the suggestion anyway and the Dev team will define priorities, or course.  Thank you!
1623767921
The Aaron
Roll20 Production Team
API Scripter
Totally. And that's fair, it's kind of a gotcha that can bite you before you get used to it.  I sent a message about it to the devs, so maybe it can get captured on a list of bug/quality of life changes.