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 .
×

Basic API functions like on("change:strength") not working?

1621442268

Edited 1621443221
Hey started experiment with custom sheets and i cant figure out why basic event triggers arent working. I am using the sheet sandbox btw.  I use a custom char sheet that is currently just a copy paste from WH40k e2 advanced sheet so i just wanted to get a basic understand of the api and did as sample: on( "change:strength" , function (eventInfo) { sendChat( "test" , "new value" ) ; sendChat( "test" , eventInfo. newValue ) ; }) ; on( "ready" , function () { sendChat( "test" , "hello" ) ; }) ; The 40k sheet has the following html <input name ="attr_strength" class ="sheet-unnaturaltext" type ="text" value ="0" > and from what i gathered i should get this value now if i change it in my sheet, but it doesnt work. The on ready event fires fine btw. Anything i am not getting?
1621446063
The Aaron
Roll20 Production Team
API Scripter
The API has a more simplistic view of events. You'd need to use on('change:attribute',...), then check if the attribute object's name is strength. 
1621446141

Edited 1621446156
The Aaron
Roll20 Production Team
API Scripter
Also, it doesn't get eventinfo objects. It gets the attribute object and a simple Javascript object representing the previous state. 
Hmm will need to try it out but currently my sandbox is stuck at "detected currently running sandbox... restarting" 
The Aaron said: Also, it doesn't get eventinfo objects. It gets the attribute object and a simple Javascript object representing the previous state.  ok it works now, mostly. But why do all examples in the wiki show examples with ' change:strength ' or some other direct attr_ name
1621464949
The Aaron
Roll20 Production Team
API Scripter
Probably you're looking at Character Sheet Sheet Worker Examples.  Character Sheets were added several years after the API was created, and Sheet Workers (Javascript code on the sheet) were added a few years after that.  The event system for sheet workers is more fine grained than the one for the API.  If you link to the examples in question, I can give you specific feedback on them.
The Aaron said: Probably you're looking at Character Sheet Sheet Worker Examples.  Character Sheets were added several years after the API was created, and Sheet Workers (Javascript code on the sheet) were added a few years after that.  The event system for sheet workers is more fine grained than the one for the API.  If you link to the examples in question, I can give you specific feedback on them. Yea i figured that out so far, i think i got the hang on the basic now tho. Need to work through it now. One thing tho, people would normaly develop most of the code in sheetworkers and some smaller stuff in api in general? I see that working with sheetworkers is a lot easier.
1621466300
The Aaron
Roll20 Production Team
API Scripter
If your functionality is all about manipulating the attributes on the character sheet, you're probably better off doing it in Sheet Workers.  If you're trying to manipulate the state of the Game, you'd need to be in the API.  There are some things that can't be done in Sheet Workers, like chat output, or effects that span characters, for which you need to be in the API.
The Aaron said: If your functionality is all about manipulating the attributes on the character sheet, you're probably better off doing it in Sheet Workers.  If you're trying to manipulate the state of the Game, you'd need to be in the API.  There are some things that can't be done in Sheet Workers, like chat output, or effects that span characters, for which you need to be in the API. Small q, dont want to make a new thread about it. Is there a difference between using /em and /me for sending a chat message?
1621543397
The Aaron
Roll20 Production Team
API Scripter
Zero difference.  One is an alias for the other.
1621543457
The Aaron
Roll20 Production Team
API Scripter
That said, if you're sending output from the API, you have far more options.  You can send raw HTML (for the most part), so can make things look however you like.
Yea i saw will use a mix to make it look nice. That being couldnt i just use custom roll templates to send out full html formated chat messages from the sheets directly?
1621544486
The Aaron
Roll20 Production Team
API Scripter
You certainly can.  But those roll templates are pretty static, and any branching logic must be built into them beforehand.  The API can build up those messages dynamically, and base their output on more than just dice rolls.
1621544578
The Aaron
Roll20 Production Team
API Scripter
You can also do things that would be hard or impossible from the sheet, like sending the output a player requests only to the GM, or to both the player and the GM, or send a slightly different version to multiple players, etc...