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

[Script issue] issue with UDL vision on copy token between maps

Hi, recently I have an issue with a script I made some times ago. The script copy tokens from a token page on the current page at a beacon named PlayerStart (and start some music when the ribbon is moved on the page). Like before the tokens are created but now players cannot see anything. It's probably due to a modification of the updated dynamic lighthing gestion but can't figure hox to fix it Some precisions : on the token page tokens see correctly current page dynamic options are correct (and edit them don't change anything) I have a light source near my player to test All dynamic options on created tokens are correct and that's the most incomprehensible things for me because if I edit token and save without changing anything it works perfectly (the player is able to see like I expected) In conclusion it's like if I need to refresh the token to recalculate the token's vision correctly. Anyone have an idea of what I need to add/change in my script to do it automatically ? I try to deactivate the token's vision and reactivate it but it does'nt modify anything My script : on('chat:message', function(msg) {     if ( msg.type == "api" && msg.content.indexOf("!prepareStart") !== -1 ) {                  /* get the arguements */ var parameters = msg.content.split(" ");         var pageName = "Token"         if ( parameters.length > 1 )             pageName = parameters[1];              var tokenName = "PlayerStart";         if ( parameters.length > 2 )             tokenName = parameters[2];         //sendChat("API PS Debug : ", "nb arg :" + parameters.length + ", pageName :" + pageName + ", tokenName :" + tokenName);         /* find the pagename (the token page) */         var page = findObjs({             _type: "page",              name: pageName         });         if ( page.length !== 1 ){             sendChat("API PS Erreur : ", page.length + " pages named " + pageName + " existing.");             return;         }else             page = page[0];         //sendChat("API PS Debug : ","pageId " +  page.get("id"));                           /* check you are the GM */         if ( ! playerIsGM( msg.playerid ) ){             sendChat("API SD, " + msg.who + " you need to be GM to use it");             return;         }         /* and find the page you are looking (the destination) */         var gm=getObj("player", msg.playerid);         var lastPage = gm.get("_lastpage");                  /* find the id of tokenName (location's target)*/         var beacon = findObjs({                                         _pageid: lastPage,           _type: "graphic",           name: tokenName         });         if ( beacon.length !== 1 ){             sendChat("API PS Erreur : ", beacon.length + " token named " + tokenName + " existing.");             return;         }else             beacon = beacon[0];         //sendChat("API PS Debug : ","targetId " +  beacon.get("id"));                           /* find tokens on the pageName */         var pageNameGraphics = findObjs({                                         _pageid: page.get("id"),                                         _type: "graphic"                                   });                           /* since I play with 2 groups I use a little trick :           rock group on the gm layer             online group on the objects */         let layer = "objects";         let adjust = 0;         if ( parameters.length === 4 && parameters[3] === "rock" ){             adjust = -4*70;             layer = "gmlayer";         }                           _.each(pageNameGraphics, function(obj) {                              /* only visible */             if ( obj.get("layer") === layer ){                 //sendChat("API PS Debug : ","token : " + obj.get("name"));                                  /* search existing token with the same name on the pageName */                 var alreadyExisting = findObjs({                                                 _pageid: lastPage,                   _type: "graphic",                   name: obj.get("name")                 });                 //sendChat("API PS Debug : ","alreadyExisting : " + alreadyExisting.length);                 if ( alreadyExisting.length === 0 ){                                      /* change the property in order to repect the formation on the new page */                     let props = JSON.parse(JSON.stringify(obj));                     props.left += beacon.get("left") - beacon.get("width") / 2;                     props.top += beacon.get("top") - beacon.get("height") / 2 + adjust;                     props._pageid = beacon.get("_pageid");                     props.imgsrc = props.imgsrc.replace(/med|max/,'thumb');                     props.layer = "objects";                                          /* create a copy */                     const copy = createObj("graphic", props);                      if (copy)                         toFront(copy);                 }             }         });                  /* -load */         if ( parameters.length === 4 && parameters[3] === "-load" ){             /* move the player to the page with Mapchange api */             sendChat("API Debug","!mc moveall --target " + lastpage);         }     }                     });
1615116440
David M.
Pro
API Scripter
If you move the tokens after summoning them, does their vision suddenly start to work? I ask because I have seen something weird occasionally with my !Spawn script with UDL when spawning the default token and adding light emission. Initially there is no light, then I move the token and suddenly the light works. I think even a wiggle might work, but I can't remember. I haven't tried to programmatically move the tokens yet to see if that works, though that's something I might try for my case. It would be interesting to try your script in your current game with tokens/pages using LDL and see if it starts to work to narrow down the issue.
Hi namesake :) Sadly if anyone move the token it still doesn't work. The only way I found to solve this issue is to manually edit and save each token (without any modification). I just save my game, and invite you on my save (I probably have to promote you as gm once you accepted)
1615149288
David M.
Pro
API Scripter
I installed your script and tested it out. Works fine with LDL, but I'm getting the exactly same behavior that you described when I try it with UDL. Interestingly, even if I copy the source token on the "Token" page and manually paste it on the destination page, it doesn't work right. In this latter case, moving the manually copied token seems to suddenly allow vision to work, the behavior I mentioned in my previous post. So, looks like something is broken with UDL's interaction with the api. You might want to check out the UDL bug forum and see if others have reported this problem already. If not, I'd suggest reporting it there or perhaps in the Bugs forum. Something like "When creating a copy of a UDL vision-enabled token via an api createObj command, the token can't see despite valid light sources on the destination page. If I open the token settings and save changes without actually making any changes, the vision is magically restored." Sorry, don't know what else to tell you. Looks like you will be dealing with this unless you go back to LDL or they fix the bug.
Thank you for your answer and the reformulation, I'm creating the bug report. Hope it will be fix soon
1615213842
The Aaron
Roll20 Production Team
API Scripter
Just to confirm, this is current bug in the UDL implementation that is beyond the capability of the API to fix currently, to the best of our knowledge.  They are working on it though, and with LDL sunsetting soon, there's a lot of pressure from the community to see this working. 
Ok, thanks for the information, guess I will back to copy/paste token for now :)