Issues with loading external data using JSON with Javascript actor
-
I found this article by Ryan Webber helpful: http://troikatronix.com/support/kb/how-to-load-external-data-with-javascript/
I followed the above mentioned instructions to load a string of javascript objects from an external file using JSON. All works well - the javascript actor references the external file and pulls up the appropriate value, but the parsing does not work within the Isadora scene, only when I change the actual Javascript.For example, using the code offered in the link above, when I usereturn [data.employees[2].firstname];and change the number [2] within the code, that changes the output.When I change the number for input 1 in the Isadora actor, my thinking was that the output would go through the data sequence. It remains stuck on whatever number is designated within the JSON code.My question is: how should I edit the code below so that I can pulse through the string in my JSON.txt file? As of now, only by changing that number 2 below can I change the data called up for output1.include('JSON.txt');
data = JSON.parse(data);function main()
{
return [data.employees[2].firstName];
}Appreciatively...
-
First, I will let you know I have done an updated version of this tutorial as part of the official Isadora KB.
It can be found here: http://troikatronix.com/support/kb/how-to-load-external-data-with-javascript/It covers in more detail the relation between the different elements.What you want to do is use one of your inputs (available via the args list in Javascript) as the variable that is selecting the element of the Json list.This is covered in this new version of the tutorial.but quickly "return [data.employees[arguments[0]].firstName];"will allow you to use Input 1 to select the different firstnames from the JSON data. -
That makes sense. Thank you, Ryan. I will try it out.
-
That's working. Thank you!