I have an API script that is working perfectly fine on another table (an LC); however, it encountered an issue that needed to be fixed on a home game table. The issue that needed to be fixed (I'm doubtful it's important) was that when a GM placed a token on the map and enacted the script, the token would report back that the controlledby field was empty. After fixing this, the token that was created (on another page) is nowhere to be found. I can see that the token was created, and I've checked to ensure that the page, location, and layer are appropriate. The console log shows that the token was created and lists the fields for that object. The API I've created is a portal API that, when the player enters a portal based on its dimensions and location, the token the player moved there is deleted, the player is moved to another page, and an identical token (with the exception of modifying the imgsrc to align with imgsrc restrictions) is placed on the destination portal. Here's the code block that I'm working through: on('change:graphic',function(obj){
if(obj.get('layer') === "objects"&&obj.get('bar3_value')!=='portal'&&findObjs({id:obj.get('represents')})[0].get('controlledby')!==''){
log('Obj: '+obj.get('name') + ': ' + obj.get('imgsrc'))
var portals = findObjs({type: 'graphic',bar3_value: 'portal', pageid: obj.get('pageid')})
for (var i = 0; i < portals.length; i++){
if(distance(obj,portals[i])<portals[i].get('bar1_value')/2){
var dest = findObjs({id: portals[i].get('bar2_value')})[0]
roster = Campaign().get('playerspecificpages')
if(!roster){
roster = {}
}
log(roster)
var obj2 = findObjs({id: obj.get('represents'), type: 'character'})[0]
log(obj2)
log("Obj ID: "+obj2.get('controlledby'))
log(Campaign().get('playerspecificpages'))
log("Control: "+obj2.get('controlledby'))
if(dest.get('pageid')===Campaign().get('playerpageid')){
delete roster[obj2.get('controlledby')]
if (Object.keys(roster).length==0){
roster = false
}
Campaign().set('playerspecificpages',false)
Campaign().set('playerspecificpages',roster)
}
if(dest.get('pageid')!==obj.get('pageid')){
delete roster[obj2.get('controlledby')]
if(dest.get('pageid')!==Campaign().get('playerpageid')){
roster[obj2.get('controlledby')] = dest.get('pageid')
}
if (Object.keys(roster).length==0){
roster = false
}
log("New Roster:")
log(roster)
Campaign().set('playerspecificpages',false)
Campaign().set('playerspecificpages',roster)
var imgsrc = obj.get('imgsrc').split('med')
if(imgsrc.length>1){
imgsrc = imgsrc[0]+'thumb'+imgsrc[1]
}else{
imgsrc = imgsrc[0]
}
imgsrc = imgsrc.split('max')
if(imgsrc.length>1){
imgsrc = imgsrc[0]+'thumb'+imgsrc[1]
}else{
imgsrc = imgsrc[0]
}
log(imgsrc)
newobj = createObj('graphic', {
pageid: dest.get('pageid'),
left: dest.get('left'),
top: dest.get('top'),
width: obj.get('width'),
height: obj.get('height'),
rotation: obj.get('rotation'),
layer: obj.get('layer'),
isdrawing: obj.get('isdrawing'),
flipv: obj.get('flipv'),
fliph: obj.get('fliph'),
imgsrc: imgsrc,
name: obj.get('name'),
gmnotes: obj.get('gmnotes'),
controlledby: obj2.get('controlledby'),
bar1_value: obj.get('bar1_value'),
bar1_max: obj.get('bar1_max'),
bar1_link: obj.get('bar1_link'),
bar2_value: obj.get('bar2_value'),
bar2_max: obj.get('bar2_max'),
bar2_link: obj.get('bar2_link'),
bar3_value: obj.get('bar3_value'),
bar3_max: obj.get('bar3_max'),
bar3_link: obj.get('bar3_link'),
represents: obj.get('represents'),
aura1_radius: obj.get('aura1_radius'),
aura1_color: obj.get('aura1_color'),
aura1_square: obj.get('aura1_square'),
aura2_radius: obj.get('aura2_radius'),
aura2_color: obj.get('aura2_color'),
aura2_square: obj.get('aura2_square'),
tint_color: obj.get('tint_color'),
statusmarkers: obj.get('statusmarkers'),
showname: obj.get('showname'),
showplayers_name: obj.get('showplayers_name'),
showplayers_bar1: obj.get('showplayers_bar1'),
showplayers_bar2: obj.get('showplayers_bar2'),
showplayers_bar3: obj.get('showplayers_bar3'),
showplayers_aura1: obj.get('showplayers_aura1'),
showplayers_aura2: obj.get('showplayers_aura2'),
playersedit_name: obj.get('playersedit_name'),
playersedit_bar1: obj.get('playersedit_bar1'),
playersedit_bar2: obj.get('playersedit_bar2'),
playersedit_bar3: obj.get('playersedit_bar3'),
playersedit_aura1: obj.get('playersedit_aura1'),
playersedit_aura2: obj.get('playersedit_aura2'),
light_radius: obj.get('light_radius'),
light_dimradius: obj.get('light_dimradius'),
light_otherplayers: obj.get('light_otherplayers'),
light_hassight: obj.get('light_hassight'),
light_angle: obj.get('light_angle'),
light_losangle: obj.get('light_losangle'),
light_multiplier: obj.get('light_multiplier'),
adv_fow_view_distance: obj.get('adv_fow_view_distance'),
side: obj.get('sides'),
currentSide: obj.get('currentSide'),
subtype: obj.get('subtype'),
has_bright_light_vision: obj.get('has_bright_light_vision'),
has_night_vision: obj.get('has_night_vision'),
night_vision_tint: obj.get('night_vision_tint'),
emits_bright_light: obj.get('emits_bright_light'),
bright_light_distance: obj.get('bright_light_distance'),
emits_low_light: obj.get('emits_low_light'),
low_light_distance: obj.get('low_light_distance'),
has_limit_field_of_vision: obj.get('has_limit_field_of_vision'),
limit_field_of_vision_center: obj.get('limit_field_of_vision_center'),
limit_field_of_vision_total: obj.get('limit_field_of_vision_total'),
has_limit_field_of_night_vision: obj.get('has_limit_field_of_night_vision'),
limit_field_of_night_vision_center: obj.get('limit_field_of_night_vision_center'),
limit_field_of_night_vision_total: obj.get('limit_field_of_night_vision_total'),
has_directional_bright_light: obj.get('has_directional_bright_light'),
directional_bright_light_total: obj.get('directional_bright_light_total'),
directional_bright_light_center: obj.get('directional_bright_light_center'),
has_directional_dim_light: obj.get('has_directional_dim_light'),
directional_dim_light_total: obj.get('directional_dim_light_total'),
directional_dim_light_center: obj.get('directional_dim_light_center'),
light_sensitivity_multiplier: obj.get('light_sensitivity_multiplier'),
tooltip: obj.get('tooltip'),
show_tooltip: obj.get('show_tooltip'),
night_vision_effect: obj.get('night_vision_effect'),
dim_light_opacity: obj.get('dim_light_opacity'),
bar_location: obj.get('bar_location'),
compact_bar: obj.get('compact_bar'),
lightColor: obj.get('lightColor'),
lockMovement: obj.get('lockMovement')
})
log(newobj)
sendPing(obj.get('left'),obj.get('top'), Campaign().get('playerpageid'), null, true)
newobj.set('top',dest.get('top'))
newobj.set('left',dest.get('left'))
obj.remove()
toFront(newobj)
break
}else{
obj.set('top',dest.get('top'))
obj.set('left',dest.get('left'))
break
}
}
}
}
}) Seems simple enough, but the results are unexpectedly not aligned with the expected behavior.