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

[Help} Parsing GM Notes or Bio fields

Is there an easy way to parse the bio or gm notes field? What I want to do paste some data in the tokens GM notes and then parse that data, create a character sheet and attach to that token, and then build the attributes and macros from that data. The GM Notes and Bio data looks like a rich text format or other marked up text. Is there an easy way to convert this to straight up text and remove all the tags? PeterW
1393300374
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Right now even writing to them is an issue but it's been used to hold data and information by scripts. But the state object is likely the way to go.
Actually the gmnotes in tokens work. The ones in the journal don't, though. You can manipulate everything you put inside token's gmnotes, just remember to convert some special characters (like : # ? and some others). I use strings delimited by "{name}" and "{/name}". For example, my weapons are like this: {icesword}2|efftype:e|damtype:k|end3|norange|pe|str13|wo1{/icesword} I use a function to parse the gmnotes and look for any special strings like that one: function UnwrapString(stringname, separator, obj){ var uArray = new Array(); var uString = ""; var gmnotes = decodeURI(obj.get('gmnotes')); gmnotes = UnescapeString(gmnotes); var startPos = gmnotes.indexOf("{" + stringname + "}"); if(startPos == -1) return { uString: "", uArray: uArray }; var endPos = gmnotes.indexOf("{/" + stringname + "}"); return { uString: gmnotes.substr(startPos+stringname.length+2, (endPos-startPos)-(stringname.length+2)), uArray: gmnotes.substr(startPos+stringname.length+2, (endPos-startPos)-(stringname.length+2)).split(separator) }; } function UnescapeString(dirtystring){ dirtystring = dirtystring.replace(/%3A/g, ':'); dirtystring = dirtystring.replace(/%23/g, '#'); dirtystring = dirtystring.replace(/%3F/g, '?'); return dirtystring; } Within my scripts, if I need to read the values for the "icesword" weapon, I use the function like this: var parsedWeapon = UnwrapString("icesword", "|", obj); Where obj is the token object, of course. Then parsedWeapon will contain the weapon string and an array containing the elements of the same string: wString = parsedWeapon.uString; wArray = parsedWeapon.uArray; wString being "2|efftype:e|damtype:k|end3|norange|pe|str13|wo1" and wArray[2] being "damtype:k" in the example above.