Interactive development in TouchStudio
Last night I was having so much fun playing around with TouchStudio that I sort of accidently wrote a script to browse images posted on the "pics" subreddit.
I didn't intend to write an image browsing script, that's just what I ended up with after asking myself "I wonder if I can …?" a few times and finding out that the answer was usually "yes".
Below is a video of me recreating the steps I took to write my Reddit image browser. The video is just over 4 minutes long, I'm moving fast on purpose because I'll explain what I'm doing afterwards.
I start by clicking the empty line in the "main()" action (which returns "Nothing")
I add an "assignment" expression (":="), click on the variable name ("result"), and click the "edit at cursor" button so I can rename it to "url".
Then I assign the string "http://reddit.com/r/pics.json" to the "url" variable and click the "Back" button to finish that statement.
Next I click on the "+" button in the ApplicationBar to add a new statement.
I use the "download" method in the "web" service to load the URL contained in the "url" variable and print out the results (called "post to wall")
Again, I click the "Back" button to finish the statement.
I hit the "run" (or "play") button in the ApplicationBar to get this output:
Looking at the JSON output, I can see how to access the array that contains the post data that I want!
I change the statement to assign this data into a variable called "data".
Next I use the "json" method in the "web" service to parse the JSON data and store it in a variable called "rv".
Using the "rv" variable I can interactively explore the JSON data I just got by using the "get field" method and using "post to wall" to check my progress.
After I figure out how to get to the data I want. I store that data in a variable called "children".
Next I add a "foreach" loop to iterate over the values in "children". Check out how TouchStudio has a button with the "children" variable in it!
I add a statement to the "foreach" loop and use the "keys" and "post to wall" methods to make sure that I've got the data that I'm expecting to get:
Yup! There it is!
Almost done!
All I need to do now is change the statement to show the picture title and then add another statement that uses the "deep zoom link" method in the "web" service to show the images. Here's what they look like:
Now all I need to do is hit the "run" button!
