values … and types Disclaimer: This document is provided “as-is”. Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and Windows Live are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners. introduction to touchdevelop basic value types o Boolean • o Number • o IEEE floating point numbers, double precision String • o true, false there is no separate character type, consider using strings of length 1 DateTime • date + time introduction to touchdevelop other types o o All other types have “reference semantics” • Values of all other types are references to actual data • Copying values only copies references, not actual data Examples: • Song, Picture, … • all collection types introduction to touchdevelop ‘invalid’ o All types have an ‘invalid’ value • Including Boolean, Number, String, DateTime • For numbers, ‘invalid’ is different from NaN o To check if a value is null, use value→is invalid o To get an invalid value of a type, use invalid→[type name] introduction to touchdevelop ‘invalid’ example var x := senses→current location if x→is invalid then “GPS not working”→post to wall time→stop introduction to touchdevelop ‘invalid’ example var last := invalid→sprite for each current in my sprite set do if not last→is invalid then last→hide last := current current→show board→update on wall introduction to touchdevelop collection types o there are many useful builtin collection types; otherwise, use records o to create a new instance, use collections→create [collection type] o example: var c = collections→create location collection introduction to touchdevelop special collections o o number map • mapping of Numbers to Numbers • keys can be numbers different from 0, 1, 2, … • ‘post to wall’ prints a chart sprite set • think of a simple “sprite collection” • however, it is created from and belongs to a particular ‘board’ introduction to touchdevelop initial values o o local variables • get initial value from assignment expression • example: x := 1 parameters • o returns • o get initial value from calling context are initially ‘invalid’ global variables (◳ data) • most are initially ‘invalid’ (!) • however: Number: 0, Boolean: false, String: “”, Date: 1/1/0001 introduction to touchdevelop