[b87,89,90] BUG: FOREACH strips some leading zeros

Confirmed bugs should get a single post here. Check the READ ME FIRST sticky thread for the format.

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice, MapTool BugReport Manager

Forum rules
Posts that do not conform to the READ ME FIRST sticky thread are subject to deletion.
User avatar
lmarkus001
Great Wyrm
Posts: 1867
Joined: Sat Mar 29, 2008 12:30 am
Location: Layfayette Hill, PA

Re: [b87,89,90] BUG: FOREACH strips some leading zeros

Post by lmarkus001 »

Yep, I just got confirmation that mote has this fixed

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: [b87,89,90] BUG: FOREACH strips some leading zeros

Post by wolph42 »

lmarkus001 wrote:Yep, I just got confirmation that mote has this fixed
great! In the mean time: do you happen to have a campaign file with such a token (numeric id). Ive upgraded 'diagnose' in the bag of tricks, to check for this as well, but I can't test it.

alternatively, you could replace the ontokenmove.rptok, with the latest available and run diagnose and let me know if it detects it.

User avatar
lmarkus001
Great Wyrm
Posts: 1867
Joined: Sat Mar 29, 2008 12:30 am
Location: Layfayette Hill, PA

Re: [b87,89,90] BUG: FOREACH strips some leading zeros

Post by lmarkus001 »

Here are my Identify, and my Identify & Replace macros:

Identify Bad IDs

Code: Select all

[H: selectTokens()]
[H: ids = getSelected()]
[H: badids = "[]"]
[H,FOREACH(id,ids),CODE: {
  [ tlen = length(id) ]
  [IF( tlen != 32 ): badids = json.append(badids,id); ""]
}]
[R,FOREACH(id,badids,""): "<b>Bad ID:</b> " + getName(strformat("%032d",id)) + " ("+id+")<br>" ]
[R: json.length(badids) + " IDs are bad."] 
Identify, Copy, Remove Bad IDs

Code: Select all

[H: selectTokens()]
[H: ids = getSelected()]
[H: badids = "[]"]
[H,FOREACH(id,ids),CODE: {
  [H: tlngth = length(id) ]
  [IF( tlngth < 32 ): badids = json.append(badids,id); ""]
}]
[R,FOREACH(id,badids,""),CODE: {
  [H: switchToken(strformat("%032d",id)) ]
  [H: tname = getName() ]
  [H: tupdates = json.set("{}","name",tname,"delta",1,"x",0,"y",0)]
  [H: copyToken(strformat("%032d",id),1,"",tupdates) ]
  [H: removeToken(strformat("%032d",id)) ]
  [R: "<b>Bad ID:</b> " + tname + " ("+id+")<br>" ]
}]
[R: json.length(badids) + " IDs were bad and repaired."] 

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: [b87,89,90] BUG: FOREACH strips some leading zeros

Post by Full Bleed »

lmarkus001 wrote:Yep, I just got confirmation that mote has this fixed
Cool.

Nice catch, btw. ;)
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
lmarkus001
Great Wyrm
Posts: 1867
Joined: Sat Mar 29, 2008 12:30 am
Location: Layfayette Hill, PA

Re: [b87,89,90] BUG: FOREACH strips some leading zeros

Post by lmarkus001 »

wolph42 wrote:
lmarkus001 wrote:Yep, I just got confirmation that mote has this fixed
great! In the mean time: do you happen to have a campaign file with such a token (numeric id). Ive upgraded 'diagnose' in the bag of tricks, to check for this as well, but I can't test it.

alternatively, you could replace the ontokenmove.rptok, with the latest available and run diagnose and let me know if it detects it.
https://www.dropbox.com/s/p70gvtimlllrr ... cmpgn?dl=0
MapTool version: 1.3.b89 Nerps! P
The map: Battlemap_OpenSea
Bad ID tokens: Marine 3, Marine 22


User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: [b87,89,90] BUG: FOREACH strips some leading zeros

Post by wolph42 »

what maptool version are you using for that campaign file? I get a load error (lumens) on load in b90.

ah wait 'lumens' thats the special compilation of Jamz' right?

edit: *facepalm*, you named the file as such.... sigh...

edit2: also your length check works better then the isnumber method as this "00000000E87994005575000000000000" id *does* check as a number but does NOT give any issues.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: [b87,89,90] BUG: FOREACH strips some leading zeros

Post by wolph42 »

ok. BoT is updated. Diagnose now automatically fixes 'broken' ID's.
In case your interested:
This is the relevant part

Code: Select all

<!-- check whether the ID of the tokens are NOT numerical -->
<!-- code (for the most part) by lmarkus -->
[hasWrongIdName    = "[]"]
[idList    = getTokens("json", '{layer:["TOKEN","GM","OBJECT","BACKGROUND"]}')]
[splices    = bot_createSplices(idList)]
[foreach(splice, splices), CODE:{
    [foreach(id, splice), if(length(id) != 32): hasWrongIdName = json.append(hasWrongIdName, id)]
    
''
}]
<!-- add the mapname to the tokens and create a clickable output -->
[if(json.length(hasWrongIdName)):    txtOutput    = txtOutput + strformat("The following token <b>ID's</b> have been <b>fixed</b> (numerical token ids can lead to a lot of issues in maptool. By copy pasting the original they get a new ID. Run Diagnose again just to be sure that the new name is not a number):<b> ")]
[txtOutputL    = ""]
[foreach(id, hasWrongIdName), CODE:{
    [txtOutputL    = listAppend(txtOutputL, getName(strformat("%032d",id)))]
    [copyToken(strformat("%032d",id),1,"",json.set("{}","name",getName(strformat("%032d",id)),"delta",1,"x",0,"y",0)) ]
    [removeToken(strformat("%032d",id)) ]
}]
[txtOutput    = txtOutput + txtOutputL + if(txtOutputL != "", "</b><br><br>", "")] 
BoT version 37g.

Also, in case you're interested in the campaign file you provided but then usable in b90, its attached.
Attachments
MT1.3.90.BAD_IDs.cmpgn
(26.64 MiB) Downloaded 51 times

Post Reply

Return to “Bug Reports”