 All right, now that we're shifted, I think I can go ahead and introduce Martin Guggen, go by Goj. I do. I like it. We're going to look at PlayFab, Azure Functions, and Visual Studio Code. That's right. That sounds really exciting. Why don't you introduce yourself first and talk directly into this mic thing of the jig. All right. Hi. I'm Martin Guggen. I work on the PlayFab team, which is part of the gaming organization here at Microsoft, building back-end services for game developers. I'm going to be talking about what PlayFab is, how we've done some integration with Azure Functions, and we'll show off a cool Visual Studio Code extension as well along the way. We're going to go ahead and plug in your computer. Getting that settled. Okay. We'll go ahead and check your HDMI. Oh, yeah. All right. We're good to go. Excellent. All right. Let's dive straight in. I'm going to spend a little bit of time talking about what PlayFab is, and then also talk about something that we call Cloud Script. Then talk about how we've integrated with Azure Functions, and then most of the talk will actually be a demo of all of this stuff hanging together, and as I'm using Visual Studio Code for some as well, and we'll show a little game written in Unity. What is PlayFab? PlayFab was a company that Microsoft acquired a little less than two years ago, and we build backend services for games. So think matchmaking, leaderboards, servers for multiplayer games, that kind of thing. It's platform agnostic and language agnostic. We support the standard platforms that you might expect from Microsoft, Xbox and PC, but we also have games running on PlayStation, Switch, Android, iOS, other mobile platforms, that kind of thing. Also language agnostic. We have SDKs for all sorts of languages, and we even accept pull requests for new SDKs and additional languages from the community. Customers, they range from small, single developers writing a game, perhaps in their spare time, all the way up to big AAA studios running big multiplayer games on our platform. One of my favorite quotes from the pre-acquisition part of PlayFab was you make it fun, we'll make it run, which is kind of our way of saying, you're the game devs, you know how to make fun games, do all that creative work, you don't want to have to deal with setting up backend services and all that kind of thing. Let us take care of those kind of things so you can focus on making the fun stuff in your game. So what is Cloud Script? Well, PlayFab has a bunch of different services, as I mentioned, and we have a reasonably sized team building more and more of those services over time as we get customer demand, but even with all those developers, we can't build everything that every game will ever need. And so one of the things that we've done is we've provided this thing called Cloud Script, which allows game developers to provide their own logic to integrate with existing PlayFab services or in fact, other external services in such a way that they can then extend our platform to do other things that we actually don't have features for right now. It works actually quite well. What tends to end up happening is a bunch of people build a thing, you know, we notice on the PlayFab side that a lot of people having to build a particular thing in Cloud Script, and then that gives us information about what kind of features we should probably go and make first class in PlayFab over time. It gives us trusted data access, so because PlayFab is actually invoking the scripts, we can get it data for your game, for your players and provide it to the scripts in a secure way. You know, you'll be happy to know that, you know, that the client can't get at that data and manipulate it in any way. It's always secure. You can initiate those calls from the game client. You can also do it from an intermediate server if you have one, or you can actually hook it up to various bits of PlayFab infrastructure and have us call your logic as various things happen in your game. And it really can be any game logic. You know, we don't really control in any way or put any restrictions on what you can or can't do in that game logic. We have some limits around how long that logic can take to run, but in terms of what it does, it's really up to you. So here's just a small diagram of the kind of things that we do with Cloud Script. So at the top, we have the different ways that Cloud Script gets invoked. So directly from clients, directly from servers, you might notice that little arrow going to the thing that says PlayStream Event up on the right. And so PlayStream Events are things that we generate at various points as your game is running. So player logs in, PlayStream Event. Client loses focus, PlayStream Event. Player gains a level in your game, PlayStream Event. And then you can hook up scripts to those events and have them run and apply filters to them and all that kind of thing. We also have the notion of scheduled tasks. So if you want to run some kind of Cloud Script over all of your player base once a day, perhaps, to do some analysis, you can do that kind of thing. And we also have this notion of segmentation. So we can actually divide players into segments, such as players that have logged in every day for the last week, or players that haven't logged in for two weeks, or players that have reached level 50 in your game, or players that have visited half the areas in the map of your game. So we can build these segments dynamically and then we can run Cloud Script based on when players enter or leave those segments. In terms of the kind of things that happen in Cloud Script, we have a few examples down the bottom of this diagram. So perhaps handling player login, perhaps you detect the first login of the day for a player, grant them some login bonus for logging in, that kind of thing. This second guy, he was a lapsed player, he hadn't logged in for a while. So when he came back, we gave him a hat, tracking daily rewards, generating stats, all that kind of thing. Okay, that's enough about PlayFab. What are Azure functions? So PlayFab built this thing called Cloud Script back probably around the same time that the Microsoft folks were building Azure functions. And Azure functions is Microsoft's world-class serverless compute platform. And what does that mean? Well, it means that you just write the code that you need and you deploy it and you don't have to worry about scaling up servers, making sure you have enough machines running, all that kind of thing. The Azure functions run time will scale up and the servers needed to run your code as your demand gets larger. And then it'll scale it back down again as the demand curve drops off as you just go through the kind of natural life cycle of your game during a day. Peaks in the evening when most people are off work and able to play games and then ramps down again overnight. You get a choice of languages Azure functions. I'll be doing the demos here in C-sharp, but you can write in Java, JavaScript. I think we have F-sharp and Python support as well. In terms of deployment, I'll be deploying from Visual Studio Code for these demos because it's fairly quick and easy to get going. But you can also hook it up to all sorts of source code repositories. So in terms of what we do at Inside Playfab, we actually deploy a lot of our stuff directly from GitHub. So we hook up Azure functions to a particular branch and whenever we push to that branch, Azure functions runs the deployment pipeline and deploys our new code. And there's a bunch of free tools. We'll be showing some of them. I'll be showing the extension for Visual Studio Code as part of this demo, but there are also add-ons for Visual Studio as well to let you interact with Azure functions. So we talked a little bit about Cloud Script and a bit about Azure functions. How do those two things relate to one another and what have we been doing for the last few months? Well, one of the main requests we got about Cloud Script Inside Playfab from customers was please let us write code in C-sharp because we only had JavaScript support in the existing system. And also please give us a debugging story because debugging the kind of classic Cloud Script Inside Playfab was basically a case of doing printf inside JavaScript which was not very much fun for anybody. And so we looked around and thought, well, we could try and build our own hosting system for hosting C-sharp code and maybe try and hook debuggers up to it. Or we could take advantage of all the stuff that the Azure functions team has built and just use that. And they have a team that is dedicated to building a world-class serverless compute whereas the Playfab team has a bunch of responsibilities related to games and providing a serverless compute platform is kind of part of that but it's not really our core competency. And so we'd like to build on something built by people for whom it is their core competency. So the way that this works is we've done some integration, we've added some APIs and some portal experiences to Playfab that allow you to, first of all, you publish your functions to Azure just like you would any functions app and you register those functions with Playfab. And currently we have support for HTTP triggered functions. I'm currently working on adding support for queued functions as well. And that'll roll out later in the year. And you register those functions with Playfab, you give them a name, you give us the URL and then you add calls from your game client or from your game server if you have one or you configure it to be run based on events. And then when those things happen, Playfab called your function, passing in a bunch of context about what player was actually playing the game when the call was made, that kind of thing so that you can then run whatever logic is that you need to. All right, that's enough talking. Let's switch to demo mode. I'm just gonna move a few things out of the way here and switch to Unity. So we have a little Unity game here and oh, it's lost the signal. Oh no, click it back in. All right, it's thinking, there we go. Okay, so I have a little Unity game here which we'll be playing with. Apparently in America it's called tic-tac-toe. In England, I know it has noughts and crosses and... Can I pet these here? Of course. I'm changing your resolution to 1920 by 1080. Not at all. I can do a plus second do that. Display settings? Yeah. Let me know in chat if this is only something that Kendra notices. 1920 by 1080? Yeah. All right. And also the screen around here. All right, great. There we go. No problem at all. All right. So hopefully that's a bit more visible for everybody. So we're gonna play this little game called tic-tac-toe. The Unity part of this game is actually fairly minimal and the logic is actually implemented in Azure Functions. The Azure Functions are deployed in Azure Functions app. We go to this, this is Visual Studio Code and here's one of the VS Code extensions. This is an Azure Functions VS Code extension. It gives me a list of the subscriptions that I have and then a list of all my applications. And here's the one that we'll be using, the tic-tac-toe.net conference 2019 demo. And currently we have three functions set up in Azure, make, play, move, reset, game state and win check. So let's go to Unity and just run the game. Let me just bring up Edge before we do that. So this is the PlayFab portal and this just has a bunch of stuff about the game, APIs that have been called, that kind of thing, logins, et cetera. And then we have this thing called PlayStream and PlayStream is this stream of events which will happen as I play the game. So this is empty right now as I start doing stuff in the game this will start filling in and then towards the end of this demo we'll try and hook up an Azure Function to one of those events and actually have it run. Okay, so back to Unity. I'm gonna hit Play here and it's doing something and there we go. So it did log in, it's resetting the game state. So we store the game state server side so the client can't mess with it. So we're just making that and I got a 400 because I forgot to disable something one second. Pay no attention to the man behind the curtain. That is a mighty test bar. It is a mighty test bar. I didn't realize it was gonna be quite so large. So let me just turn that off. No, all good. So let me just stop that and restart, log in, resetting game state and now it's waiting for the player move. So again, if I flip back to edge we should see at least a login event that's happened. So down here, player logged in, unknown city. Apparently this is a secret bunker. Nobody knows where it is. And then player device info. So we got some information about the device. If I click this, we'll see information about the player. So these events are just gonna be generated as I play the game. So if I win, there'll be an event saying I won. If I lose, there'll be an event saying I lose. So I'm gonna click my player move and it's gonna request the I'm I move and then I get an exception. And the reason for that is I haven't yet hooked up the Azure function for the actual computer move. So I have the Azure function for recording where the player decided to place their token but not for the computer part. So let's go to VS Code again. And let's go to make AI move. And I'm actually gonna register a couple of functions here. Make random AI move. I wonder if you can guess what that does. And make mini max AI move. And we're actually gonna deploy both of those functions just straight from here to Azure. So I can do that straight from VS Code. There's this little toolbar here in the Azure functions extension. And here's the deploy option. So I hit deploy. I tell it where I want it to go. And I get the error which means it lost the connection while I was asleep. One second. Let's bring this back. So if you do see the error when you're using the Azure functions extension for VS Code it usually just means that you switch network or something while the extension was running and seems to get a little bit confused. So back we go. Hit deploy. That's where I want it to go. It's gonna say, are you sure that's what you wanna do? I am absolutely sure. So that's gonna run off and deploy the game. Deploy the functions. Well, that's happening because that's gonna take a minute or two. Let's just go look at some of the Unity Code. Pretty easy to actually look at it in VS Code. So here's just another instance of VS Code. And here's for example, the thing that resets the game state. So this is a handler. It sets some data structure. Basically says, hey, this is the player that I want to interact with. And then it calls a PlayFab API called execute function which is the thing that actually then figures out which Azure function to actually call. If everything succeeds, fine. We get an execution completed. If not, then we generate some message and display that in the exception box. We have a bunch of these handlers for dealing with all of the different functions that the game is using. All right, let's see how that deployment is going. So it's finished. So one of the cool things about VS Code and the Azure function extension is I can stream the logs for the functions app directly into VS Code. So I'm gonna choose stream logs. I'm just gonna move that out of the way. It's connecting to the log stream. So now when I go back and play the game we should actually be able to see things happening in that stream there. So let's restart the game. Oh, one last thing. We need to register our function with PlayFab. You may remember from the slides at the beginning. So let's go to the PlayFab Explorer, sign in. This is a little kind of alpha extension that we've built. This gives you a tree view of all of the game studios that you're part of and all the games that they have. And I can get a list of functions that are currently registered. So I currently have three, make, play, move, reset, game state, win check. And I need to register my AI move. And so the easy way to do that is I can go to the Azure function extension and you see those new functions have now appeared and I can grab the URL. There's just a copy function URL menu option here. And then I can switch back to the PlayFab extension and then just say register. Paste in the function URL and then I get to give it a name. Now it'll try and infer a name from the URL and I actually want it to be called make AI move because that's the name that the Unity game knows it as. You'll see why I'm actually making that change in a moment. So I had a little pop-up says registered function. So now they're registered. Hopefully this time when I run the game, the AI will actually be able to play and will actually play a token somewhere on the board. So login resetting game state, waiting for player move. I'm gonna go for the middle. It's played a token. Excellent, I'm gonna go over here. Oh, it's not very bright. Okay, so I win. Marvelous. And so if we go and see over here, you see there were a bunch of events happening. Again, we got login and then my number of wins went from 15 to 16 because I won the game. All right, so if I restart that game, let's see if it can be any clever at the second time. Let's see. No, it's still not very bright. And the problem with this AI is it literally just picks a random square on the board to place its token and it doesn't have any knowledge of how the game works at all. And so that's not very clever. But one of the cool things about server side logic and the way that this is all hooked up through PlayFab is that I can actually go and register a different function under the same name. So I can go and take this Minimax AI move and I can grab the function URL for that. And even while the Unity game is still running, they can come back here and I can register a function and give it the same name. So make AI move rather than make Minimax AI move. And now there's a different set of logic running. In the cloud for this game. And this is just a simple example, but hopefully you can imagine the kind of things that you'd be able to do as a game developer. So I'm gonna restart this. Reset the game state, waiting for the player. I'm gonna go in the middle. It's gonna go there. I'm gonna go here. Oh, okay. I'm gonna go here. Okay, nobody's winning that one. Okay, so that one's a draw. Let's, oh, and it crashed. So what we've done here, I actually played, we're on what's known as the free tier for PlayFab. So the API limits are relatively low. And I played the game a little bit faster than the API can handle due to the rate limiting. And so she failed. So let's restart and see if we can win the second time. Again, I'll play there. No. No. No. Okay, so this API you actually can't, this AI you actually can't beat. You can draw and you can lose, but you can't actually win against this AI. And I like winning. So given I like winning, I can just switch it back to the other function. Just again, just go and copy the URL, re-register it, give it the right name and now we're back to having the easy to beat, dumb computer player. And again, restart. And now again, it's back to not being a smart AI. Okay, so I hope that that gives you some idea of the kind of things that you can do with Cloud Script in terms of its dynamic nature. You can change the behavior of your game without having to change the client at all just by shipping a new function up to Azure and then registering it with PlayFab. So that's all well and good. Let's flip to local debugging. So one of the features that we had got asked for was a good debugging story. And so what I'm gonna do here is I'm just gonna change the name of this to make AI move because again, that's the name that the Unity app knows it has. And then I'm gonna put a breakpoint on that function and then I'm gonna hit F5 and let that run. And then again, in our VS Code extension here, you may have noticed there was an enable local debugging option. And if I click that, it basically enables a little shim inside our Unity SDK and says to it, hey, don't call the PlayFab server to execute through Azure. Call the local Azure Functions runtime that is running inside VS Code or Visual Studio. You could do it in Visual Studio as well. Instead. And so now if I go back to Unity and we restart the game, I forgot to do one thing. Let me just go back here, just kill that. There's another function I just need to add. So we have this thing called execute function, which is effectively a stand-in for the execute function API on the PlayFab server. And so the Unity SDK knows to call this when it's in this local debugging mode. So let's run that. Hopefully it'll work this time. Resetting game state. Oh, that makes me sad. Oh, I was too fast. I didn't wait enough time for the host to actually start up. So it's currently coming up. Why does it think it only has one function? That doesn't sound good. Kill one second. Okay, building, running, finished building. Starting the function host, there it is. And then there we are. Okay, so we have all of our functions are running. Excellent. So back to Unity. So restart this. Maybe the third time it really is the charm. So it's resetting the game state. It's waiting for the player move. Great, so reset game state worked. I'm now gonna do the player move. It's requesting AI move. And that means it should have stopped in the debugger. And lo and behold, it has. And now we're just in a normal debugging environment. So I can use F10 to step through things. I can look at local variables, all the things that you would normally expect to be able to do in a debugger. So that allows you to just debug your server-side logic effectively locally on your machine. Okay, how are we doing for time Kendra? We're doing okay, we can switch over to question. Okay, I have one more thing to show if we have time. Do it quick. Okay, I'll do it quick. Okay, we got it. So back to the portal briefly and just show you this automation tab. And here's a list of my functions. I just wanted to show you how you would hook this up. So here's a list of functions that are registered. You can register them here too, as well as through the VS Code extension. But we have this thing that says rules. And then I can set up a new rule and then let's call it login. And then I get to pick an event. Here's a whole ton of events that PlayFab generates. But there's a player logged in event. And I can then add an action to that. We have a bunch of standard actions that you can use, granting items, virtual currency, that kind of thing. And you can also execute an Azure function. So it then gives me a list of all the Azure functions it knows about. I can just pick one. So I would write some custom function to handle login, register it here. It would show up in the list and then it would run whenever a player logged in. All right, quickly back to slides so that we can wrap up. Shift F5, I think. Yes, excellent. So takeaways, that was a quick run through Azure Functions integration with PlayFab. We're using Azure Functions as our next generation cloud script. It's in private preview today. You can sign up for PlayFab in general at playfab.com. Azure Functions, you can find out about that URL there. The VS code extension is at aka.ms slash playfab explorer. And if you have any questions about any of the above, send mail to me as guj at Microsoft.com. Okay, I'll just grab this mic over from you and act like a real interviewer. Okay, so we have some questions. First off, will this project be available at some point on GitHub? So parts of it will be, some of it already is. So that execute function thing that we use for local debugging, that's actually already in a public GitHub repo under the PlayFab organization. I also hope to open source to Visual Studio Code extension as well. It's kind of almost ready to go. I just have a bunch of publishing stuff I need to figure out how to do to get over that hump. We actually do all our work in PlayFab in GitHub, but the server side code is all in a private repo. Awesome, okay, so we had a question earlier. So it sounds like PlayFab has already glued different systems together, like messaging, queuing, event systems, et cetera. Can it be used for non-game applications? Or is it truly geared toward game? That is a great question. So we are very much focused on games and we are in the gaming org, but we do get a lot of questions along those lines. And we do actually have a couple of people in the team that are working with other industries to try and apply PlayFab to those kind of places too. Because it does actually apply to a whole bunch of places. If you think about, if you don't think about players, but think about the hotel industry and think about guests, right? Guests are kind of like players and maybe you would want to be able to segment those guests according to certain rules and all that kind of things. So yeah, PlayFab does have applications that in those kind of areas, but we're mainly focused on the game side. Yeah, cool, we're excited about it. So yeah, the examples they give in the chat are like chat box or line of business applications, keeping track of achievements, such as like tickets closed or calls taken, pretty cool. Okay, so I assume it would be, oh, let's see. Oh, some other people are saying this would probably be a great learning platform too. And it might be an interesting option for people to start working on a project using PlayFab. Any educational aspirations? So I personally used to be an educator before I joined Microsoft. I spent a lot of time flying around the world teaching various people how to use various bits of technology. And certainly PlayFab does have a free tier, so you can actually play around with it and do stuff with it without it costing you any money. So it is good for learning in that respect. Microsoft has a whole bunch of assets around the education space. One of the ladies who used to be on our team actually was so passionate about education that she actually moved to work on the Minecraft team that works on education assets. So that would be another thing to look at if you're interested in the educational aspects. Great. Okay, one more question. We are at 7.30, so I'm sure the next group will really want to come in here. But can I use this custom scripting with functions with some of their plan types that don't have cold starts like the premium plan? Yeah, so cold start can be an issue. You can absolutely use it with the premium plan so you can deploy your function app into a premium app service and have it always running. We found though that once your game is running, there's enough functions traffic that it kind of never goes cold. And you might want to think about that too because premium plan is limited in terms of how far it will scale. Whereas we've actually scaled the consumption app up to a 3,500 RPS inside a single function app which is way larger than our biggest cloud script user today. All right, we have a bunch of other questions but they can reach you maybe on Twitter at Gudge. Gudge, I'm Gudge pretty much everywhere except Reddit. Okay, cool. Cool, so next up we have Scott Hanselman who will be joining us. I'm sure we have more people tuning in for this. It's a dotnet on a microcontroller exploring Wilderness Labs Meadow.