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

On("change:campaign:playerpageid"...

1465962970

Edited 1465963170
I would like to have the game test the pageid when I change playerpageid. I want it to see if the current page is the random encounter page, and if it is, roll up the map layer to be a random map. I'm sure I can get the current pageid. I don't know how static pageids are. If I have it chat me the resource locator id, can I test? on("change:campaign:playerpageid",function(obj){ if(obj=="-ABC123"){ do stuff }}); Or do I have to reference a parameter: if(obj.get("name")=="RandomEncounterMap"){...
Crap! forgot the semicolon on the do stuff instruction!
1465964753
Lithl
Pro
Sheet Author
API Scripter
In the case of a change:campaign event, the obj parameter is the Campaign object.
So, then I'm going to need: on("change:campaign:playerpageid",function(obj){ var currMap = obj.get(playerpageid); if(curMap=="-ABC123"){ do stuff }}); Are ID numbers static? Can I hard-code this, and get results? or does the ID dynamically generate when the session is created, so if my playerpageid=-ABC123 today, tomorrow it might be -XYZ987?
1466088241

Edited 1466088789
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The ID is static for any given game (and is read-only and unique), but if you want to be able to use it in other games you may run, you'll want to use a way to mark the random encounter page. The way I did it for my  Page Navigator script is to have a text tag that the user appends to the page name and then use .indexOf to filter the pages for page names with the proper tag and then get the id from those pages. I believe that WhiteWolves did something similar for his  MapChange script. For your case you could probably just have it look for a page named Random Encounters or what not; this would of course potentially have conflicts with other scripts that use or do things to page names. EDIT: if you used something like this: on("change:campaign:playerpageid",function(id){ var currMap = getObj('page',id); if(currMap.get('name').indexOf('Random Encounters')>-1){ do stuff }; }); You wouldn't have to worry about the conflicts mentioned above, and it would be dynamic to work with any campaign as long as you followed the naming convention that random encounter pages had "Random Encounters" somewhere in the name, allowing you to then have several different random encounter pages (like say City Random Encounters, Wilderness Random Encounters, etc.) in case you found that you needed say different sized maps or something like that.
1466171532
Lithl
Pro
Sheet Author
API Scripter
Scott C. said: on("change:campaign:playerpageid",function(id){ var currMap = getObj('page',id); if(currMap.get('name').indexOf('Random Encounters')>-1){ do stuff }; }); Even when you limit a change event to a single parameter like this, the first parameter of the callback is still going to be the entire object. You would need something like: on('change:campaign:playerpageid', function(campaign) { var currMap = getObj('page', campaign.get('playerpageid')); ... });
1466171956
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
ah, didn't know that Brian, thanks for the correciton.