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

API instructions out of order?

Query:  Can the API perform instructions out of order? Background:  I'm banging my head against the wall here and after a lot of logging, it appears that the API can perform instructions out of order.  I'm doing a .get on the notes field of a handout and it appears that the script will continue running while the .get function is occurring.  Is this a known thing?  Is there a way to prevent it? Code and results below:         var HistoricalData = findObjs({_type: 'handout', name: 'Weather By Historical Date'})[0];         log (HistoricalData);         log (HistoricalData.id);         var FinalNotes = "Declaration value";         log ("In: " + FinalNotes);         var character = getObj("handout", HistoricalData.id);         character.get("notes", function(n) {             log("Getting notes...");             log("Notes: " + n);             FinalNotes = n;         });         log ("Out: " + FinalNotes);         } Log: {"name":"Weather By Historical Date" <snipped unimportant data> "-K9Jlp_MXau3Tg3WQW4F" "In: Declaration value" "Out: Declaration value" "Getting notes..." "Notes: Test Description and Notes"
1454231760

Edited 1454231930
Lithl
Pro
Sheet Author
API Scripter
.get() for notes and gmnotes on handouts and characters are asynchronous operations. That means that the server will start processing the callback function as soon as you ask, but it will (probably) start the instruction after  get() before finishing the callback. If you have something that absolutely positively has to wait until you're done processing the notes/gmnotes, you need to put that code at the end of the callback (or call a function at the end of the callback which contains the code you want to run). The wiki also has code you can use to implement an  Asynchronous Semaphore , which will let you ensure all of your async operations are complete before running some bit of code.
1454246924
The Aaron
Roll20 Production Team
API Scripter
A brief discussion of Async functions:&nbsp; <a href="https://wiki.roll20.net/API:Use_Guide#A_Treatise_o" rel="nofollow">https://wiki.roll20.net/API:Use_Guide#A_Treatise_o</a>...
Thank you for the info. &nbsp;That took far longer than it should have to figure out what was happening. So is there a list of the asynchronous functions in roll20 so I don't make that mistake again?
1454252011
The Aaron
Roll20 Production Team
API Scripter
I'll go through and annotate them in the wiki later, but anything that takes a callback is probably an Async function (exceptions for the functional programming in underscore: _.map, _.reduce, _.each...)
1454263336
The Aaron
Roll20 Production Team
API Scripter
Annotations added! &nbsp;There aren't that many, really. &nbsp;Just sendChat() with a 3rd parameter and the .get() for notes, gmnotes and bio fields.
TY again for the info! &nbsp;Hopefully someone else finds that before they spend hours trying to figure out inconsistencies in their script.
1454289337
Lithl
Pro
Sheet Author
API Scripter
The Aaron said: Annotations added! &nbsp;There aren't that many, really. &nbsp;Just sendChat() with a 3rd parameter and the .get() for notes, gmnotes and bio fields. And half the stuff in sheet worker scripts. =P
1454290450
The Aaron
Pro
API Scripter
Yeah, I annotated those too. =D