Download presentation
Presentation is loading. Please wait.
Published byBuck Bryan Modified over 8 years ago
1
Sage Franch | Technical Evangelist Susan Ibach | Technical Evangelist
2
Outline Local, global and cloud variables Using cloud data to store a high score
3
Local, Global and Cloud Variables
4
Recall what we already know about variables… Variables store information that can be used again and again throughout the rest of your code A variable has a name, a type and a value The type of a variable is determined when it is declared Variables must be declared before they are used Variables also have one more invisible property that determines when they can be used.
5
Scope = the part of the code in which a variable can be used
6
In many cases, a local variable’s scope is directly related to the indentation of the line on which it is declared x, y, and z can all be used without error x and y can be used without error… But z cannot be found because it is out of scope!
7
There are three types of variables LocalGloba l Cloud Declared and used within a small area of the code Declared in the code and “promoted to data” so they can be used throughout the code Created outside the code so it can be used by multiple instances of the code
8
Local Variables
9
Global Variables
10
When should I use global variables? Promote a variable to data when you need to give it a bigger scope!
11
Unique in each instance of the app – separate users get separate copies of the variable Local and Global Variables
12
Shared across multiple instances of the app – separate users share and access the same cloud variable. Cloud Variables
13
What is cloud? Your data is stored on servers on the internet instead of on your own computer Cloud sessions synchronize the shared data between participants of the same cloud session
14
When would you use cloud data? When you want data to be available to multiple players at once –A high score When you want to collect information from multiple users to be stored in one place –A shared to-do list –An audience poll –Voting When you want users to communicate with each other –Multiplayer games
15
Limitations of using cloud data in TouchDevelop Cloud data is currently NOT supported for exported apps – so you will only be able to use your cloud data for apps hosted in TouchDevelop, not the ones published to stores or to web. Local use only
16
Using Cloud Data to Store a High Score
17
When the game ends, we want to: Compare the user’s score to the high score Update the high score if the user beat it Display the high score and the user’s score Tell the user if they got a new high score
18
Using a cloud variable to track a high score Create a new variable and select the “replicated” radio button
19
Add a new action Accepts a parameter, player score, which is the player’s final score on game end Returns a string, msg, to display to the player If the player has a new score, update the high score variable
20
Using “post to wall” to display text and variables “Post to wall” displays the newest line at the top, so we put the statements in reverse order.
21
DEMO Adding a leaderboard to track high scores
22
Want to skip all that work?
23
The bazaar does it for you! The function that updates the score in the cloud The final score for the game you just played The function that displays the leaderboard
24
Your challenge Add a high score or leaderboard to track high scores for your game
25
The cloud’s the limit! Congratulations!
26
©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.