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

Event Name Tracking in Script Workers

When capturing an event in the script worker, is it possible to tell what the name of the event is? For example on("change:cultranks_animalhandling1", function() { update_attr ("animalhandling1") } I would like to parse out the skill name "animalhandling1" from the event name " change:cultranks_animalhandling1 " and pass that to my function rather than hard coding it like I do in the example. While I am wishing for the moon, I suppose it is too much to ask for wild card names in evens.  ie on("change:cultranks_*", function() { would capture any change event that begins "cultranks_".  It would make my code sooooooo much saner.
1544636119

Edited 1544636353
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Your first question is handled in the event attributes, which include (but may not be limited to): event:{ sourceAttribute:"attribute_name",//Note this will change for repeating attributes depending on how you listen for the change sourceType:"player",//Whether the change was initiated by player, worker, or (if I remember correctly) API triggerName:"attribute_name",//What triggered the change; for a repeating attribute this will be the repeating section and the item id, e.g. repeating_attack_-Kt4590Uty previousValue:"7", newValue:"8" } Unfortunately, question 2 isn't quite possible. You could do something like: _.each(['animalhandling1','animalhandling2'],(specific)=>{ on(`change:cultranks_${specific}`,doSomething); });
1544639081

Edited 1544639614
Pantsworth
Sheet Author
OK, thanks.  Sorry for being so stupid, but could you tell me how to reference the event attributes.  Is is something as simple as event.sourceAttribute Example: on("change:cultranks_animalhandling1 change:devranks_animalhandling1", function() {     var eventname = event.sourceAttribute     var skillname = eventname.substr(eventname.lastindexof("_"), eventname.length) update_skill (skillname)   } I mean I probably will pass the event name and parse that string in the function, but you get the idea,
As to the second question - I wonder if I should be using repeating rows for the skills.  The only thing that changes is their name and category.   If I did that would I also be able to abstract the skills out to an enum rather than hard coding every skill?
1544639967
GiGs
Pro
Sheet Author
API Scripter
What exactly is it you are trying to do? The complete script from start to finish, in plain english, not just the capturing the name part.
1544640091
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You just need to pass it in your on() listener: on("change:cultranks_animalhandling1 change:devranks_animalhandling1", function(event) {//It doesn't matter what you call it, the on function will pass the eventInfo as the first variable in whatever function is called as the second argument. See my example code in the next code section for another example of how to do this     var eventname = event.sourceAttribute     var skillname = eventname.substr(eventname.lastindexof("_"), eventname.length) update_skill (skillname)   } Other way to do this: on("change:cultranks_animalhandling1 change:devranks_animalhandling1",rankHandler); var rankHandler = function(event){     var eventname = event.sourceAttribute; var skillname = eventname.substr(eventname.lastindexof("_"), eventname.length); update_skill (skillname); } Also, I would highly recommend always ending your lines with semicolons (where appropriate of course).
1544640308

Edited 1544640339
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Pantsworth said: As to the second question - I wonder if I should be using repeating rows for the skills.  The only thing that changes is their name and category.   If I did that would I also be able to abstract the skills out to an enum rather than hard coding every skill? You could get the entered name pretty easily by just doing a getAttrs, but as GiGs said, more information on what you are trying to accomplish would help make sure that we're giving you the right advice. There's about 1001 ways to do just about anything in javascript; the trick is finding which one works best for your use case.
OK - I'll write up a use case and paste it here.
The main objective here is to build the skills page of a RMU (RoleMaster Unified) character sheet. caveats:  I started by using the existing character sheet for RMSS (RoleMaster Standard System).  While I am not wedded to it, it certainly has driven some design choices I have made. RMU has a skill system that uses skill categories - stat bonuses apply to all skills in a skill category. A given skill category can have any number of skills, and this is dictated by the user.   For example the Category Animal has the skill Riding, which is typed to specific animals, (Riding: Horse, Riding: Camel)  Ideally the user would be presented with a list of skills commonly used, but also be able to add skills to a category as needed. It would be nice to be able to provide the skill and category lists elsewhere (in a constant?) and have them read into the sheet, rather than hardcoded.into the sheet itself.   Nice to have: Calculations for most skills are the same for every skill.  I'd prefer to write one event capture routing.  If not there will be literally 100s of routines to capture, and heaven forbid the skill list changes.  That said - I can forgoe all but inline calcs if I have to.
1544726911
GiGs
Pro
Sheet Author
API Scripter
Regarding #5: this is definitely possible, but you'll need to construct the attribute names in a particular way. Pick a single skill or skill category, and the list of attributes that would be needed for a single skill calculation. We'll be able to generalise from that to figure out how make a single sheet worker that works for all of them. Regarding #4, if you are supplying a dropdown to select lists from, unfortunately there's no way to avoid having to write out the contents of that dropdown everywhere in the sheet its needed. Regarding #3: there are several approaches I can see using here, but I think that would be better handled in another thread. Lets stick to the skill calculation for this one.
1544728558
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
GiGs has some good advice, I'd just add the following to it: For #3, I'd recommend making your skills a repeating section. Either one section/category or a single repeating section that you filter what is displayed where based on it's category. This also dovetails into #5 as you can easily handle any changes to a repeating section with a single change listener. For #4, GiGs is correct that you can't dynamically set the options of a select in a character sheet, however there is a method that I call pseudo-selects that you can use to fake it. I've posted on it before, and I believe Jakob refined it; not sure where that thread is now though.
1544729053

Edited 1544729109
GiGs
Pro
Sheet Author
API Scripter
Scott C. said: For #3, I'd recommend making your skills a repeating section. Either one section/category or a single repeating section that you filter what is displayed where based on it's category. This also dovetails into #5 as you can easily handle any changes to a repeating section with a single change listener. I was hesitant about suggesting repeating sections, because of the way that some skills also have subskills, and you might want to use repeating sections for those, and you cant nest repeating sections. That's why I suggested opening up another thread for hashing out the details of that one. That said, it might be better to hash out the details here, because it'll inform the way the sheet worker skill calculation is built.
1544729579
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
GiGs said: I was hesitant about suggesting repeating sections, because of the way that some skills also have subskills, and you might want to use repeating sections for those, and you cant nest repeating sections. That's why I suggested opening up another thread for hashing out the details of that one. It is a potential problem, but (and I say this with no knowledge of the system beyond this thread) it sounds like there isn't a limit to the number of skills in a given category, which is pretty much the definition of when to use a repeating section.
1544730349

Edited 1544730405
GiGs
Pro
Sheet Author
API Scripter
On reflection, I think you're right. (That also simplifies the dropdown duplication too, you probably only need to write it once per section.) I do have some familiarity (from eons past) with RM, but am not familiar with the most recent editions. 
Well RMU has been in beta for 5 years? or so.  Anyway.  I think repeating sections is what I will try.  Just got done playing, so I will write that up later or tomorrow.
1544914003
GiGs
Pro
Sheet Author
API Scripter
The versions of RM I've played are the very first edition, and 1e Space Master, before RMSS, so i know the system has changed a bit since i played and I'm not sure of the details. Otherwise I'd have been to get started earlier without waiting to know exactly what you need.
1544979907

Edited 1545066268
Pantsworth
Sheet Author
Oh - I was just grousing about the fact that it is still in beta, not throwing shade to your knowledge of the game.  I wouldn't expect anyone to be able to get ahold of the beta rules, let alone make a character sheet for online play unless they really sought them out. OK - on to rules.   Skills are divided into Categories.  Each category contains similar skills; and uses the same stat modifiers.  Stat mods typically are in a set of three.  It can be 3 different stats, or all the same stat.  The stat bonus gets summed and added to every skill in that category. Most skills are calculated like so: Get your ranks from your culture, then you can buy ranks.  Add these ranks together, and that total gets you a bonus to your skill; starting at +5 for ranks 1-10 down to +1 for ranks 30+.  This is your base bonus.  You then add in your stat bonus, any profession (ie class) bonuses, any talent/knack modifiers, item bonuses, and misc modifiers.  This gets you a total bonus. Now the current sheet does a neat trick where it builds a macro in the sheet and the roll button just calls that macro.  Anyway - the roll asks for situational modifiers then rolls using an excellent template they built, that I would want to keep. For example let's look at Riding - Horse: For Larry of Rohan Category: Animal (Other skills in this category are Rifind other types of animals and Animal Handling of various animals.) Stat Modifiers for category: (Ag/Em/Pr): +8 Culture Ranks: 2  Bought Ranks: 9 Rank Modifier: (10 * 5) + (1 * 3)  = +53 Professional Bonus:  (+1 per rank if this is a profession skill): +11 Talent/Flaw:  Born in the saddle: +10  Item Bonus:  Pants of the Saddle : +10 Misc Bonus: 0  Total Bonus:  +92 So that is the basics for most skills.  We can talk about other skills later.  Ideally it would add the ranks together and calc the rank bonus.  If it is a professional skill, you would click a checkbox and get the bonus.  You would enter the Item, Misc, & Talent/Flaw mods and then it would total them, post that to the sheet where the macro could capture it's value to do it thing.
1545006885
GiGs
Pro
Sheet Author
API Scripter
That's a good decsription, though i still need a couple of clarifications. In RMSS, you chose a skill and subskill, and added those two ranks together. You might have, for instance, 1h Swords and Longsword , and your rank would be the total of those two. Does the new RM dispense with those, or are such subskills still in the game? I see the culture ranks, are their any other sources of ranks that might be added to a skill? For calculating bonus, it's 1-10 = 5/rank, 11-20 = 3/rank, what's the scaling after that? For stat modifiers, is that an average of all 3 stats modifiers, or a total of the 3 stats bonuses? How do you plan on implementing them on the character sheet? 
1545008428
GiGs
Pro
Sheet Author
API Scripter
Also, can you post a screenshot of how you expect the stat section to look on the character sheet? Either from your own sheet, the one youre are working off, or an official sheet meant for tabletop printout.
1545067293

Edited 1545069064
Pantsworth
Sheet Author
GiGs said: That's a good description, though i still need a couple of clarifications. In RMSS, you chose a skill and subskill, and added those two ranks together. You might have, for instance, 1h Swords and Longsword , and your rank would be the total of those two. Does the new RM dispense with those, or are such subskills still in the game? I see the culture ranks, are their any other sources of ranks that might be added to a skill? For calculating bonus, it's 1-10 = 5/rank, 11-20 = 3/rank, what's the scaling after that? For stat modifiers, is that an average of all 3 stats modifiers, or a total of the 3 stats bonuses? How do you plan on implementing them on the character sheet?  The whole 2 levels of buying skill ranks is gone.  You only ever buy development ranks for the skill.  The only thing categories are for is determining the stats that apply to the skills in a category.  Now culture ranks and development ranks are the only ways to get skill ranks.  And you only get culture ranks at creation. Ranks scale thusly:  1-10: +5; 11-20: +3; 21-30: +2; 31+: +1.  No ranks is a flat -25.  I have the formula worked out for that but it is not abstracted - ie it applies only to each skill.   [[-25+({@{animalhandling1ranks}, 1 }kl1*25)+({@{animalhandling1ranks}, 10 }kl1*5)+({{@{animalhandling1ranks}-10}, 0 }kh1}, {10} }kl1*3)+({{@{animalhandling1ranks}-20} , 0 }kh1}, {10} }kl1*2)+({@{animalhandling1ranks}-30} , 0 }kh1) ]] They no longer average stat bonuses.  Instead they lowered that bonus given by each stat (by about 1/5) and now you sum the three stats.  Also - stats are limited to 100.  They still divide each stat up into Temporary (should be named current, but whatev) and Potential (Max you can get). I tried to add a screenshot from my desktop, but it timed out.  Gonna try to use imgur in a different post so I don't have to retype.
1545068077

Edited 1545068530
Pantsworth
Sheet Author
Here is the screenshot:  BTW, column names are not justified yet. So from left to right we have Total Bonus, culture ranks, development ranks, total ranks (should not be needed in final product), Rank Bonus, Professional Skill (was once a checkbox - should be that way in the final product), Professional Bonus (For Clarity I think this should stay), talent modifier (could be +/-), Special Modifier (Long term effects - maybe call it misc mod?), item mod, macro (may not be needed in the final either - but I do like having it there), roll button. Originally stat modifier was calculated in a field next to the category name, but I didn't like it there.  It made checking the numbers take longer then needed.  So I plan on moving it back down and put it right after rank bonus. I also plan on moving total bonus to right infront of the macro field. All hail to the developers of the RMSS sheet, BTW.  They did a great deal of the heavy lifting here.
1545077719
Diana P
Pro
Sheet Author
Pantsworth said: All hail to the developers of the RMSS sheet, BTW.  They did a great deal of the heavy lifting here. Awe, thanks.   (You might want to look at the other HTML file in the RMSS Github directory, the one titled charsheet_RMSS_fullcalcs_RollTemplates.html   it is the most recent version and does have a lot of the calculations for RMSS in it; might be helpful.  Note:  I'm not a very good programmer so I know a lot of it is significantly less efficient than it should be.  I do plan on replacing the no-calculation sheet with it once I get it better optimized. :)   All the main fields are compatible between the sheets; iirc the newer one has some that the other one does not but I've spent most of my time on its reorganization and automating it. )
1545130208
GiGs
Pro
Sheet Author
API Scripter
Does every skill category have three stats for the modifier? 
1545138732

Edited 1545138766
Pantsworth
Sheet Author
No.  Magical Expertise and Combat Expertise have no stat modifiers.  But skills under these categories operate differently as well.  Combat Training has 3, but it varies depending on the weapon type.  All the rest have 3 and do not vary within the category.
1545192742
GiGs
Pro
Sheet Author
API Scripter
Can you paste the html you have now for one line of those skill bonuses (all those inputs). Thanks!
Hey - got caught up in the Holidays.  I have not abandoned this.  I will prolly get to spend more time on it this wknd.