"The book is great! It's clear and easy to read, with loads of examples that showed my students what to do."
-- Larry Snyder, Emeritus Professor, University of Washington, Department of Computer Science and Engineering
“Having the TouchDevelop book available made our events so much easier. Students could figure things out for themselves with help from the book.”
-- Jennifer Marsman, Microsoft Principal Developer Evangelist
Mobiledevices such as smartphones and tablets are set to become the main computersthat virtually all people will own and carry with them at all times. And yet,mobile devices are not yet used for all computing tasks. A project at MicrosoftResearch was created to answer a simple question: “It is possible to createinteresting apps directly on a smartphone or tablet, without using a separatePC or a keyboard?” The result is TouchDevelop, a programming environment thatruns on all modern mobile devices such as Windows Phone, iPhone, iPad, Androidphones and tablets, and also on PCs and Macs.
This book walks you through all of the screens of the TouchDevelop app, and itpoints out similarities and differences of the TouchDevelop language comparedto other programming languages. For users, the book can serve as a handyreference next to the phone. The book systematically addresses all programminglanguage constructs, starting from the very basic constructs such as variablesand loops. The book also explores many of the phone sensors and data sourceswhich make creating apps for mobile devices so rewarding.
If you are new to programming with TouchDevelop, or if you have not yet workedon touchscreen devices, we suggest that you read the book starting from Chapter1. If you are already familiar with the basic paradigm of the TouchDevelopprogramming environment, then feel free to jump ahead to the later chaptersthat address particular topic areas.
This book is written from theperspective of a person developing their code using a web browser. TheTouchDevelop Web App runs in many modern browsers on many different devicesincluding smartphones and tablets, Macs, PC. All screenshots and navigationinstructions refer to the TouchDevelop Web App running in a browser. ForWindows Phone, there is a dedicated TouchDevelop app in the Windows Phone Storewhich gives access to many more sensors and data sources. Starting with theTouchDevelop app v3.0 for Windows Phone 8, the phone app will share the samelook and navigation structure and all features of the Web App.
What you’ll learn
• The little tricks to programming on your mobile devices and for a mobile device
• The scripting language and cloud-based ecosystem
• Using cameras, video and audio, and other sensors such as a microphone, accelerometer, compass, and gyroscope
• Access to the web, authorized access to web services
• How to write simple games using a built-in physics engine
Who this book is for
This programming language was written for people who wish tobe able to create apps from their phone. This scenario is particularlyappealing to enthusiastic end-users who own mobile devices and students, whoare the target audience of this book.
Author(s): R. Nigel Horspool, Nikolai Tillmann
Edition: 3
Publisher: Apress
Year: 2013
Language: English
Pages: 270
Cover
......Page 1
Contents......Page 3
Who this book is for......Page 262
Background to the book......Page 263
The TouchDevelop Team......Page 264
List of figures......Page 268
List of tables......Page 270
1.1
Computers want to be programmed......Page 9
1.2
What is TouchDevelop?......Page 10
1.3
The TouchDevelop ecosystem......Page 12
1.4
History and Future......Page 14
1.5 Platforms......Page 15
1.5.2 Running TouchDevelop on other platforms......Page 16
1.6
The scripting language......Page 17
2.1 Introduction – the language flavor......Page 19
2.1.1 A sample program (/okzc)......Page 20
2.2.2 met hodThe Nothing type or an operation which does not return a usable result, but which......Page 23
Number......Page 24
2.2.3 Reference types......Page 25
Reference types provided by the API......Page 26
Collection types......Page 27
2.2.5The Objects for types.......Page 28
Global persistent data......Page 29
2.3.1 Constants......Page 30
Explicit Constants......Page 31
The invalid value......Page 32
Global data variables......Page 33
2.3.3 Operators......Page 34
2.3.5 Calling an API method......Page 35
2.4.2 Declaration and assignment......Page 36
2.4.4 While loop......Page 37
2.4.6 For each loop......Page 38
2.5.1 Defining an action......Page 39
2.5.4 Result parameters......Page 40
Visibility......Page 41
2.6 Events
......Page 42
Implementation restrictions on libraries......Page 44
3.1.1 Output of simple values......Page 45
3.1.3Dappropriateproduces produces ispla yio bnOutput of composite values ge......Page 47
Output of media values......Page 48
s......Page 49
3.3 Updating the wall’s content......Page 50
3.3.1 Updatable textbox......Page 51
3.3.2 For Updating a board display......Page 52
3.4.1 Tap wall events......Page 53
3.4.2 Tap board events......Page 54
3.6 Titles and subtitles......Page 57
3.7 Wall buttons......Page 58
3.8 On-demand creation of output......Page 60
4.1.1 Working with URLs......Page 61
4.1.2 Creating and using web-based links......Page 62
Using the wall with web-based links......Page 63
4.1.3 Checking the internet connection......Page 65
4.2.1 Downloading a text file or downloading HTML......Page 66
4.2.2 Download a picture......Page 67
4.2.3 Downloading sounds of music......Page 68
4.2.4 Uploading strings and files......Page 69
4.3 Downloading structured data......Page 70
4.3.1 Downloading information in JSON format......Page 72
4.3.2ML i s shDownloading information in XML format......Page 74
4.4 REST guidelines and web requests......Page 77
5.1 Music......Page 81
5.1.1 Working with collections of songs......Page 82
5.1.3 Playing an individual song......Page 84
5.1.4 An ex ample script......Page 86
5.2 Sounds......Page 87
5.3 Microphone......Page 89
6.1 Camera
......Page 91
6.1.1 A sample program......Page 93
6.2.1 Picture albums and picture collections (Windows Phoneand Android)......Page 95
6.2.3 Manipulating a picture......Page 96
6.3 Static graphics drawing and display......Page 101
6.4 Playing videos from the internet......Page 104
7.1 The sensors......Page 105
7.2 Sensor-driven events......Page 106
7.3 Accelerometer......Page 107
7.3.1 Direction of acceleration forces......Page 110
7.3.2 Example script: a light show (/tbcb)......Page 111
7.4 Compass......Page 112
7.5 Gyroscope......Page 113
7.6 Motion......Page 115
8.1 Social messages......Page 119
8.1.1 Working with messages......Page 120
8.2 Locations, places, maps......Page 121
8.3 Emails......Page 123
8.4 Phone Calls......Page 125
8.5 2D barcodes......Page 126
8.6 SMS messages (WP8 only)......Page 127
8.7 Calendar and appointments (WP8 only)......Page 128
8.8 Contacts (WP8 and Android only)......Page 129
9.1.1 What is a sprite?......Page 131
9.2 The Board datatype......Page 132
9.2.1 Creating sprites......Page 133
Gravity and friction......Page 135
Springs and anchors......Page 137
Visual attributes......Page 138
Accelerations, forces and bounces......Page 139
9.3.1 Managing sprites......Page 141
9.4 The Sprite Collection datatype......Page 143
9.5.1 Board touching actions
......Page 144
9.5.3 tap board event......Page 145
9.5.5 tap sprite in XXX event......Page 146
9.5.8 tap sprite SSS, swipe sprite SSS, drag sprite SSS......Page 147
9.6 Debugging games......Page 148
10.1 Page Overview......Page 149
10.2 Box Overview......Page 150
10.3.1 Page Example 1......Page 151
10.3.2 Page Example 2......Page 153
10.3.3 Page Example 3......Page 156
10.4.1 Entering and Leaving a Page......Page 159
10.4.2 Coding Restrictions......Page 160
10.5 Live Editing of the User Interface......Page 161
10.6 API Support for Boxes and Pages......Page 162
11.1 Registering your app......Page 165
11.2 Authenticating......Page 166
11.3 Libraries......Page 168
11.4.1 Unique redirect URIs......Page 169
11.4.2 State variable in redirect URI......Page 170
Appendix A: Editing TouchDevelop Scripts......Page 171
A.1 The starting point......Page 172
Getting started - providing an input parameter......Page 174
Adding the first statement to the action......Page 175
Adding the second and third statements......Page 177
Inserting the if statement......Page 179
Trying out the script......Page 180
Revising the script......Page 181
A.4.1 Refactoring code into a new action......Page 182
A.4.2 I Copying and pasting code......Page 184
A.4.3 Surrounding code in a higher-level construct......Page 185
B.2 box......Page 186
B.4 colors......Page 188
B.6
invalid......Page 190
B.8 locations......Page 192
B.10 math......Page 193
B.11 media......Page 195
B.13 player......Page 196
B.14 senses......Page 197
B.15 social......Page 198
B.17 tile......Page 199
B.19 wall......Page 200
B.20 web......Page 202
C.2 Appointment Collection
......Page 205
C.3 Board......Page 206
C.5 Camera......Page 207
C.7 Contact......Page 208
C.8 Contact Collection......Page 209
C.9 DateTime......Page 210
C.11 Json Builder......Page 211
C.13 Link......Page 212
C.15 Location......Page 213
C.17 Map......Page 214
C.18 Matrix......Page 215
C.19 Message......Page 216
C.20 Message Collection......Page 217
C.22 Number......Page 218
C.24 Number Map......Page 219
C.25 OAuth Response......Page 220
C.29 Picture......Page 221
C.30 Picture Album......Page 223
C.33 Place......Page 224
C.34 Place Collection
......Page 225
C.37 Song......Page 226
C.40 Song Albums......Page 227
C.43
Sprite......Page 228
C.44 Sprite Set......Page 230
C.45 String......Page 231
C.47 String Map......Page 233
C.49 Vector3......Page 234
C.50 Web Request......Page 235
C.52 Xml Object......Page 236
D.2 General Features......Page 239
D.4 Support for Services/Resources......Page 240
D.5.2 Apps for Windows Store......Page 241
E.2 The back button, undo and mistakes......Page 243
E.3 The editing example......Page 244
E.4 Additional steps......Page 249
E.5 Refactoring code into a new action......Page 251
Index......Page 253