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] Renaming an Attribute or set ot to Null

1534270789
Mike W.
Pro
Sheet Author
Here is the situation - BTW I am very new to HTML, JavaScript, and CSS so I have no idea how this can be done. I have a character sheet, I am not the original author, where within a Repeating Section named Techniques , the original authors have created an attribute using a reserved name (max): attr_max . If any data is entered into that attribute, you are no longer able to delete that Row. Question 1 . Can an attribute be renamed and retains its value? I would like to rename attr_max to attr_techniuque_mx and keep the values, if any, intact for each Row. Remember this is part of a Repeating Section. Question 2 . If you cannot rename the attribute or cannot rename without loosing data, how would I use setAttrs to set a Null value for each row of the Repeating Section? I think by entering a Null value I will then be able to delete unwanted rows. The code also needs to be able to detect that if the new attribute already exists, because the sheet had been opened before and data transferred, then not to recopy the old data again. If this can be done and testing proves it works, I would then like to add additional code to delete attr_max all together from the Repeating Section after this process. I hope I am making myself clear. I need to test this several times so I do not want it to delete attr_max until I am sure all is working perfectly. In my testing , I noticed that if I 'Add' a new Row and no value is entered into attr_max (you must skip it entirely, not even tabbing into that field), I can then delete the Row just added. However if you enter a value or even tab into the field, you are no longer able to delete that Row. I have opened a Bug report with the Devs but have not heard form them in a couple of weeks now. Any suggestions and code would be greatly welcomed. I assume the code would need to be part of my on('sheet:opened', function() { section of code in order to make this change happen - and it will probably have to remain there for some time.
1534295764

Edited 1534297256
GiGs
Pro
Sheet Author
API Scripter
What is the max value used for? If you rename an attribute in the character sheet, any already existing characters will still have the original attribute, it just wont be visible and they wont be able to edit it. It is possible to create a script to change the values of an attribute, but you cant delete them that way. (Outside of API scripts, there's no way to actually delete an attribute that is already created on an active character.) Several sheets have a version script, which runs each time a sheet is opened, checked the current sheet version. If it's an old version, it gets updated to the newest version. People use this process to migrate attributes from an old name to a new one, or zero out old attributes that aren't used any more. You have to be careful creating such a script, to make sure it only runs the update procedure once. So, a process that would do what you need to do is: Add a new attr_technique_mx (or maybe attr_techniqueMax, no underscore) Decide on a version number for your current sheet Create a sheet:opened  event which checks for the version of the sheet If version < below current version, run an upgrade script, and after the script is run, create a version attribute, and store the current version in it. That way the next time the sheet is opened, the script will stop here and skip the following steps. In this upgrade script, loops through the techniques section, and for each attribute named max: Copy its value to the technique_mx attribute, and set the old value to "" or null (not sure which is best) That should fix it with zero disruption to people who already have characters using the sheet. If the sheet already has a versioning script, you can use that. If not, you'll need to create one.
1534296582
Mike W.
Pro
Sheet Author
It is a numerical value. The attribute named attr_max, seems to be causing an issue because of that name. If any value or even a 0 is in the field, you are unable to delete the Row. Since I have not heard form the devs yet, I assume my only choice its to delete that attribute BUT I want to save what data is already there.
1534297499
GiGs
Pro
Sheet Author
API Scripter
The steps I have listed should solve the issue. I was really asking what the max value represented in the game. If it is purely a reference value, that players get from a book and doesnt vary (e.g. all techniques of the name x have the same max of y), you dont need to worry about migrating data. You can just run a version script which nullifies it, and they can look up the value again. But if it's something that varies unpredictably, migrating it properly does matter.
1534297602
GiGs
Pro
Sheet Author
API Scripter
Mike W. said: Any suggestions and code would be greatly welcomed. I assume the code would need to be part of my on('sheet:opened', function() { section of code in order to make this change happen - and it will probably have to remain there for some time. Once you add a version script to a sheet (which does trigger of sheet:opened), you never delete it. But since the script checks the sheet version number, it only runs when needed. 
1534299652
Mike W.
Pro
Sheet Author
There is a version script. My real issue is I do not know how to write all the code needed. I am also hopping to hear form a Dev in my Bug thread, who may see a better solution. So for now there is no rush.The better option may be to just delete that attribute and inform everyone when they open to sheet that they need to reenter its value. Thankfully it has no macros associated with it, it only indicates the maximum level that particular Technique cna reach. How is it to delete an attribute from a Repeating Section?
1534299925
GiGs
Pro
Sheet Author
API Scripter
You'll still need to use a versioning script to manage the deletion, because if you just delete the attr_max reference from the character sheet, those characters already created will still have the stat but it will be hidden from view and there'll be no way for them to manually delete it. Can you paste the versioning script that sheet uses?