[{"data":1,"prerenderedAt":450},["ShallowReactive",2],{"footer-primary":3,"footer-secondary":93,"footer-description":119,"ready-set-battlesnake-visualize-battlesnake":121,"ready-set-battlesnake-visualize-battlesnake-next":176,"sales-reps":198},{"items":4},[5,29,49,69],{"id":6,"title":7,"url":8,"page":8,"children":9},"522e608a-77b0-4333-820d-d4f44be2ade1","Solutions",null,[10,15,20,25],{"id":11,"title":12,"url":8,"page":13},"fcafe85a-a798-4710-9e7a-776fe413aae5","Headless CMS",{"permalink":14},"/solutions/headless-cms",{"id":16,"title":17,"url":8,"page":18},"79972923-93cf-4777-9e32-5c9b0315fc10","Backend-as-a-Service",{"permalink":19},"/solutions/backend-as-a-service",{"id":21,"title":22,"url":8,"page":23},"0fa8d0c1-7b64-4f6f-939d-d7fdb99fc407","Product Information",{"permalink":24},"/solutions/product-information-management",{"id":26,"title":27,"url":28,"page":8},"63946d54-6052-4780-8ff4-91f5a9931dcc","100+ Things to Build","https://directus.io/blog/100-tools-apps-and-platforms-you-can-build-with-directus",{"id":30,"title":31,"url":8,"page":8,"children":32},"8ab4f9b1-f3e2-44d6-919b-011d91fe072f","Resources",[33,37,41,45],{"id":34,"title":35,"url":36,"page":8},"f951fb84-8777-4b84-9e91-996fe9d25483","Documentation","https://docs.directus.io",{"id":38,"title":39,"url":40,"page":8},"366febc7-a538-4c08-a326-e6204957f1e3","Guides","https://docs.directus.io/guides/",{"id":42,"title":43,"url":44,"page":8},"aeb9128e-1c5f-417f-863c-2449416433cd","Community","https://directus.chat",{"id":46,"title":47,"url":48,"page":8},"da1c2ed8-0a77-49b0-a903-49c56cb07de5","Release Notes","https://github.com/directus/directus/releases",{"id":50,"title":51,"url":8,"page":8,"children":52},"d61fae8c-7502-494a-822f-19ecff3d0256","Support",[53,57,61,65],{"id":54,"title":55,"url":56,"page":8},"8c43c781-7ebd-475f-a931-747e293c0a88","Issue Tracker","https://github.com/directus/directus/issues",{"id":58,"title":59,"url":60,"page":8},"d77bb78e-cf7b-4e01-932a-514414ba49d3","Feature Requests","https://github.com/directus/directus/discussions?discussions_q=is:open+sort:top",{"id":62,"title":63,"url":64,"page":8},"4346be2b-2c53-476e-b53b-becacec626a6","Community Chat","https://discord.com/channels/725371605378924594/741317677397704757",{"id":66,"title":67,"url":68,"page":8},"26c115d2-49f7-4edc-935e-d37d427fb89d","Cloud Dashboard","https://directus.cloud",{"id":70,"title":71,"url":8,"page":8,"children":72},"49141403-4f20-44ac-8453-25ace1265812","Organization",[73,78,84,88],{"id":74,"title":75,"url":76,"page":77},"1f36ea92-8a5e-47c8-914c-9822a8b9538a","About","/about",{"permalink":76},{"id":79,"title":80,"url":81,"page":82},"b84bf525-5471-4b14-a93c-225f6c386005","Careers","#",{"permalink":83},"/careers",{"id":85,"title":86,"url":87,"page":8},"86aabc3a-433d-434b-9efa-ad1d34be0a34","Brand Assets","https://drive.google.com/drive/folders/1lBOTba4RaA5ikqOn8Ewo4RYzD0XcymG9?usp=sharing",{"id":89,"title":90,"url":8,"page":91},"8d2fa1e3-198e-4405-81e1-2ceb858bc237","Contact",{"permalink":92},"/contact",{"items":94},[95,101,107,113],{"id":96,"title":97,"url":8,"page":98,"children":100},"8a1b7bfa-429d-4ffc-a650-2a5fdcf356da","Cloud Policies",{"permalink":99},"/cloud-policies",[],{"id":102,"title":103,"url":81,"page":104,"children":106},"bea848ef-828f-4306-8017-6b00ec5d4a0c","License",{"permalink":105},"/bsl",[],{"id":108,"title":109,"url":81,"page":110,"children":112},"4e914f47-4bee-42b7-b445-3119ee4196ef","Terms",{"permalink":111},"/terms",[],{"id":114,"title":115,"url":81,"page":116,"children":118},"ea69eda6-d317-4981-8421-fcabb1826bfd","Privacy",{"permalink":117},"/privacy",[],{"description":120},"\u003Cp>A composable backend to build your Headless CMS, BaaS, and more.&nbsp;\u003C/p>",{"id":122,"slug":123,"vimeo_id":124,"description":125,"tile":126,"length":127,"resources":8,"people":128,"episode_number":135,"published":136,"title":137,"video_transcript_html":138,"video_transcript_text":139,"content":8,"status":140,"episode_people":141,"recommendations":164,"season":165,"seo":8},"5a14d9c9-0b37-4655-b45a-b4783c0bb92f","visualize-battlesnake","925465713","Having build a very powerful snake, Kevin and Andrew seek to bask in the glory of their intellect by visualizing their wins. But not is all as it seems...","a1039337-33b5-4299-a982-bc258e3b8fa3",130,[129,132],{"name":130,"url":131},"Kevin Lewis","https://directus.io/team/kevin-lewis",{"name":133,"url":134},"Andrew MacLean","https://twitter.com/andrewdmaclean",3,"2024-04-18","Visualize","\u003Cp>Speaker 0: Hello? Oh, were were you waiting to do the thing? Alright. We can\u003C/p>\u003Cp>Speaker 1: I got you excited? I got you excited.\u003C/p>\u003Cp>Speaker 0: Hello, and welcome to ready Ready.\u003C/p>\u003Cp>Speaker 1: Set. Battlesnake.\u003C/p>\u003Cp>Speaker 0: We are running out of time to nail it, and I I have to be honest. My my, my confidence is starting to wane that we're gonna get it. But hello, everyone. Welcome to episode 3 of 4 for Ready, Set, Battlesnake. My name is Kevin.\u003C/p>\u003Cp>I work at Directus and\u003C/p>\u003Cp>Speaker 1: My name is Andrew, and I work at Devcycle.\u003C/p>\u003Cp>Speaker 0: Absolutely. And today, we're gonna pick up right where we left off in building a Battlesnake with, Directus and in the next episode with Devcycle. We've both been involved in the Battlesnake project for some time in various ilks. And honestly, we're we're just having a great time, if I may if I may talk for us both.\u003C/p>\u003Cp>Speaker 1: I'm with you. I think this has just been so fun. I haven't dug into Battlesnake in such a long time that this was such an awesome thing to come back into, especially oh, look at that. My light turned off. Especially after, especially after just getting into the the nitty gritty of Directus over the past, like, couple months, getting ready to build some of this stuff out.\u003C/p>\u003Cp>So, yeah, this has just been it's been so much fun, and I'm excited that we're only halfway through right now. Like, we've got 2 full sessions left, and I think it's\u003C/p>\u003Cp>Speaker 0: gonna be amazing. So am I. So let's recap where we were at just at a high level. So we have a local directors instance running. Inside of that instance, we have a custom endpoint extension.\u003C/p>\u003Cp>We have a custom endpoint extension because we need to know with confidence that, a snake can exist having a root endpoint and a slash move endpoint at the very least. And the webhook, the webhook triggers for flows can't guarantee that you get a random URL and we need we need both of those relative past. So we created an endpoint and all the endpoint does is it fires off this flow. There's one for the info of our snake here, which gives the information about our snake. Is the font size okay?\u003C/p>\u003Cp>I can bump it up if necessary.\u003C/p>\u003Cp>Speaker 1: It's okay. I mean, bump it up a little bit. I feel like it's not bad for folks that are watching. Yeah. Yeah.\u003C/p>\u003Cp>It's good.\u003C/p>\u003Cp>Speaker 0: Yeah. Yeah. Yeah. Yeah. And then our move endpoint, which is what we spent most of our time working on in the last episode.\u003C/p>\u003Cp>So request comes in with a full board state. We set up some global information from that state. We grab is move safe, up, down, left, right, or true. We grab snakes, board width, board height, my head, and you kind of all of these conveniences. Then we run avoid walls, and we see whether whether the wall's gonna be hit.\u003C/p>\u003Cp>But what you'll notice is at the top is that we pull in is move safe. We do all the work to it and then all we do is return is move safe. So we're moving this object down the chain kind of manipulating it at each step because that's ultimately all we need. We avoid the walls. We avoid all bodies of all snakes once again, starting with is move safe, ending with is move safe.\u003C/p>\u003Cp>Then we avoid head to head. This is what we spent most of last session doing once we got the flow running. It might not be the most elegant, but what we do is we look one space around every snake that isn't us, and we avoid those spaces too. Once again, we start with this move safe coming in, and we end with this move safe going out. And finally I love we determine\u003C/p>\u003Cp>Speaker 1: I love that you're saying this is not elegant, Kevin. Like, this is like yours is so much more elegant than mine. As you're gonna find out next week when I jump back in, week 1 week 4 are Andrew, learn learn with Andrew. Specials.\u003C/p>\u003Cp>Speaker 0: Andrew specials.\u003C/p>\u003Cp>Speaker 1: Exactly. So this is such clean code. I love it.\u003C/p>\u003Cp>Speaker 0: Oh, well, thank you very much. I'm sure some of our viewers will disagree and I won't stop them. And then and then finally, we grab that array of is move safe. We basically just pick 1 at random that is still available and we return that as an object move next move, which is either up, down, left or right, and we continue on. And so in this episode, I think we were going to start playing around with not necessarily adding more logic to the snake.\u003C/p>\u003Cp>I think it's a pretty robust snake right now, but instead, we're gonna start saving game data to this director's project, and then perhaps we'll do something with the insights module. How does that sound?\u003C/p>\u003Cp>Speaker 1: That sounds fantastic, Kevin. That sounds like a great way to spend an afternoon for me slash Wonderful.\u003C/p>\u003Cp>Speaker 0: And afternoon, no?\u003C/p>\u003Cp>Speaker 1: It is now but I realized that people are watching this from everywhere. So maybe it's from morning. Everywhere. Technically, it's it's, we've got afternoon for me, evening for Kevin, and morning for one of our wonderful viewers out. I'm sure somebody\u003C/p>\u003Cp>Speaker 0: is more important for you. Good good morning from 9:30 at night. Okay. So so so I've already had to think about how how this should probably shape up, which is this return move this return move operation here does some work, right? It picks the move and then it returns it.\u003C/p>\u003Cp>I think we should decouple these. So we should do one final step which picks a move and then the final step which just returns the move. And then we can put in like an inter we could put in one additional operation in which will store data in a database. I think that's probably the, you know, we have to decouple it and then we can we can take in the entire board state from the trigger, store that and we can store the move that we ended up concluding before we send it on. That's that's what I think we should probably do.\u003C/p>\u003Cp>There is a question of what we want to store. You know, we also have this additional start and end move point. I think end always returns the final state of the board. So there's something to be to be said about that as well. Yeah.\u003C/p>\u003Cp>What do we what do we want to store? Maybe we start with we we just store the the move. Like, we start really simple. We just say what is the final move we chose?\u003C/p>\u003Cp>Speaker 1: Yeah. I think that's probably easy number 1. I was also gonna say we could record win or loss, like, if we wanna go really simple. But technically, I think move is probably simpler because then otherwise, we're gonna have to parse through the JSON data that we get back. So yeah.\u003C/p>\u003Cp>Let's do let's do move and then maybe, like status of the game and, and then go from there.\u003C/p>\u003Cp>Speaker 0: Interesting. Let's just let's just go till we can't go anymore. Now just as a note, there is a limitation that we have to work within with directors. Now we actually just did a different directors TV episode on this. It was request review, filtering JSON objects, I think it was called.\u003C/p>\u003Cp>But, basically, if we store a JSON blob inside of a field in directors, we can't filter inside of that blob. It is just a string. So what we'll need to do is extract specific values and store those as individual values if we want to use them for insights. We just have to be aware of that. Let's let's start by doing what we said we would do, which is adding this extra, splitting this out into 2, and then we can figure out how we're gonna store data.\u003C/p>\u003Cp>I think that's probably the safest bet. So, let's add a new operation here. Let's call this 1, determine move. I think that feels okay. I think we'll give it the key of move.\u003C/p>\u003Cp>And I don't know why I've started doing that without having copied out this. So determine move, and this will be a run script. You can copy and paste that in here, except all we're gonna return now is move next. I think all we need to return is the strength next move. That's all this one has to do.\u003C/p>\u003Cp>And then we're just gonna re kind of configure these. So this one's gonna go here. This one's gonna go here and we hit save. And this keeps happening. Don't know why, but it seems to work if you just kind of what was it?\u003C/p>\u003Cp>Do it again? Yeah. Because that's what it was.\u003C/p>\u003Cp>Speaker 1: Disconnect it and then save and it should work. Yeah.\u003C/p>\u003Cp>Speaker 0: Like this. We do. Well, we did that. Okay. Cool.\u003C/p>\u003Cp>Cool. Cool. Cool.\u003C/p>\u003Cp>Speaker 1: Yes. And now we're\u003C/p>\u003Cp>Speaker 0: And then, which feels odd. Now today, there was actually a release of Directus the day that we are recording this, but I'm not feeling brave enough just just in case. Just saying it. So this this may well have been fixed. Do we remember what it was?\u003C/p>\u003Cp>Because it ain't ain't Don't say these. Bloody words.\u003C/p>\u003Cp>Speaker 1: Is it not working? See. Hang on. Hang on. Okay.\u003C/p>\u003Cp>What if\u003C/p>\u003Cp>Speaker 0: we go this way?\u003C/p>\u003Cp>Speaker 1: Yeah. Okay. Fine. And now switch it.\u003C/p>\u003Cp>Speaker 0: I think we had to, like, maybe.\u003C/p>\u003Cp>Speaker 1: No. What the heck? This this resolved with this last time. So this is\u003C/p>\u003Cp>Speaker 0: Yeah. But nothing nothing's changed, Andrew. Nothing's changed.\u003C/p>\u003Cp>Speaker 1: Okay. Go back, and, like, remove it from there, save, and then go back, go out, and come back in.\u003C/p>\u003Cp>Speaker 0: You think?\u003C/p>\u003Cp>Speaker 1: I don't think that's what we did, but I wonder if\u003C/p>\u003Cp>Speaker 0: it will No. No. We we definitely didn't do that. We did this and then this and then\u003C/p>\u003Cp>Speaker 1: This is why you should always watch your VOD recording if you're trying to bug\u003C/p>\u003Cp>Speaker 0: some of the buttons. We fixed it. Watch your VOD recording. We did. Oh, no.\u003C/p>\u003Cp>Speaker 1: Okay. Remove the okay. But so let's maybe there is actually an error in there. Maybe there is a new error that we've introduced.\u003C/p>\u003Cp>Speaker 0: Alright. But not nothing new has happened. Right. Value fulfilled resolve in collection, direct to this operation has to be unique.\u003C/p>\u003Cp>Speaker 1: Are move the same? Is determine move and return move? Is it the same key? Is that what it is?\u003C/p>\u003Cp>Speaker 0: Oh, possibly, but I really don't think so. This is no. This is called return move.\u003C/p>\u003Cp>Speaker 1: Nope. Nope. It's a return move. You're right.\u003C/p>\u003Cp>Speaker 0: So it works that way around. Cool. Cool. Cool. Cool.\u003C/p>\u003Cp>Cool. So so then we do this. And it does It's this. This is this is where there's a problem.\u003C/p>\u003Cp>Speaker 1: I feel like our logic is not going to work. Can we just trigger another what if we just trigger another flow instead of doing it past the data? I know it's not as clean but, like, if we're gonna, like, bug solve even just temporarily, why don't we just send it to another flow? It's a new thing we haven't looked at as well because you can trigger\u003C/p>\u003Cp>Speaker 0: another flow. I don't wanna do that. I don't I I want it to work.\u003C/p>\u003Cp>Speaker 1: I mean, we all want these things to work.\u003C/p>\u003Cp>Speaker 0: Okay. We're gonna pause and and we're going to come back when we have worked it out.\u003C/p>\u003Cp>Speaker 1: What was so wait, what was, what was the you're right. The solution was exactly what you described last time. Are you getting error logs in your console that are different than that?\u003C/p>\u003Cp>Speaker 0: Oh, no. Really? Shit. It's a great way to start a bloody director's TV thing, isn't it?\u003C/p>\u003Cp>Speaker 1: Fantastic. Bugs are what make this feel interesting. K. Oh, what?\u003C/p>\u003Cp>Speaker 0: No. No. No. This this one was the good one.\u003C/p>\u003Cp>Speaker 1: Oh, that's yes. That's the reversed way, so it won't work that way.\u003C/p>\u003Cp>Speaker 0: What have I just done? So this goes into return move. No. We want this one to go into determine move. Determine move goes into return move, save error.\u003C/p>\u003Cp>Speaker 1: An error. Delete that card and create a new one and see if it solves the problem.\u003C/p>\u003Cp>Speaker 0: Call return move. Card. Oh, doesn't like that.\u003C/p>\u003Cp>Speaker 1: Yeah. Just return. There we go. Same thing. Director's operation.\u003C/p>\u003Cp>What is okay. Can we see that that field go into the data model? Can we not see that operations logic?\u003C/p>\u003Cp>Speaker 0: I mean, I mean, yeah, I guess. But, like, we're looking at quite, like, low level, like, built in system. Okay. Cool. There is an error.\u003C/p>\u003Cp>Copy to action. This is what Riker's just messaged. Hang on. Did it work? No.\u003C/p>\u003Cp>Okay. I'm telling him what happened. Right. I meant I'm talking to the lead maintainer. Node 13 were.\u003C/p>\u003Cp>I made node 2 then changed the nodules.\u003C/p>\u003Cp>Speaker 1: And\u003C/p>\u003Cp>Speaker 0: okay. Fuck. Fuck.\u003C/p>\u003Cp>Speaker 1: This is the way to this is definitely what what what was meant to happen this week. Is it okay. What if we run a simple script? Like, just detach that new one that you just created. Add any random script after the determined move.\u003C/p>\u003Cp>Okay. So we need to create\u003C/p>\u003Cp>Speaker 0: a new one first of all. Right? Yes.\u003C/p>\u003Cp>Speaker 1: Yes. It's\u003C/p>\u003Cp>Speaker 0: great. Do will return data. Great. Right? It's like a pass through.\u003C/p>\u003Cp>It does nothing.\u003C/p>\u003Cp>Speaker 1: Is it the script? What if we do the same thing with the I Yeah. If we duplicate this script, can you duplicate a flow?\u003C/p>\u003Cp>Speaker 0: Not a whole flow. Oh, yeah. Flow? Yeah.\u003C/p>\u003Cp>Speaker 1: I wonder if duplicating the flow might solve this issue.\u003C/p>\u003Cp>Speaker 0: Duplicating the flow will mean we have to reconfigure the extension. But\u003C/p>\u003Cp>Speaker 1: Well, I mean, let's let's see let's see if it works.\u003C/p>\u003Cp>Speaker 0: Well, yeah. Well, I don't know why I'm doing that. So return. Okay. And we'll copy out.\u003C/p>\u003Cp>Blows. And then we can\u003C/p>\u003Cp>Speaker 1: Oh, no. I actually can't duplicate 1.\u003C/p>\u003Cp>Speaker 0: You could, once upon a time. No. It's insights. That's insights.\u003C/p>\u003Cp>Speaker 1: Good to know. Fucking Here we are. Now we'll figure this out. We got this. I have I have faith in us.\u003C/p>\u003Cp>Okay. So our regulars our regular script\u003C/p>\u003Cp>Speaker 0: our no.\u003C/p>\u003Cp>Speaker 1: Our regular script was working. Okay. Skip just to the end. So, like, remove the the head to head and go straight from avoid body to the very end. So skip over the avoid head to head because this is where we started to get these issues.\u003C/p>\u003Cp>No. It's the final card that's fucking this up. No matter what it is.\u003C/p>\u003Cp>Speaker 0: It's reassign.\u003C/p>\u003Cp>Speaker 1: It worked. Did it work?\u003C/p>\u003Cp>Speaker 0: It worked. Don't question it. Okay.\u003C/p>\u003Cp>Speaker 1: It worked. We did it. What what was our solution, Kevin? We just tried many times and then waited to see what happened. Just wait until I cause many problems to my team.\u003C/p>\u003Cp>Okay.\u003C/p>\u003Cp>Speaker 0: On our screen. Okay. Alright. Gonna resume recording. Thanks for the click.\u003C/p>\u003Cp>Speaker 1: We got there. We did it. Go team. Go, Kevin.\u003C/p>\u003Cp>Speaker 0: Okay. Hubert, you're welcome. Alright. Ready to come back?\u003C/p>\u003Cp>Speaker 1: We're ready. Let's do it.\u003C/p>\u003Cp>Speaker 0: Okay. And welcome back. We fixed it. We don't know how we fixed it. It just started working again.\u003C/p>\u003Cp>We will undoubtedly come across this again. Having spoken to like our lead maintainer, he thinks it's a bug, which I will open a GitHub issue on after this recording. Okay. Wicked. So now determining the move and then returning the move.\u003C/p>\u003Cp>Okay, cool. So we determine the move, which just returns the next move. And then all we want to do here, the literally the only thing we want to do here is return last. Right? Data no.\u003C/p>\u003Cp>Last. Last? Yeah. Just last.\u003C/p>\u003Cp>Speaker 1: Yeah. I think just last.\u003C/p>\u003Cp>Speaker 0: Date data dot data dot last.\u003C/p>\u003Cp>Speaker 1: Is it? Alright. And the reason for this, if if nobody realizes this already, is because, like, you have to feedback this very specific JSON structure into the response that that Battlesnake precedes. Which kinda sucks. It just seems like, it should.\u003C/p>\u003Cp>It should just read this the engine should just get it. It should understand at a core level.\u003C/p>\u003Cp>Speaker 0: If you're if you're being told to implement an API specifically, it's fine to have to do it specifically, but we'll test it works. And in theory, we should be able to in theory, we should be able to add another another flow operation here to do logging. Any logging we want at the end of the whole run. So let's manage our battlesnakes. Let's create a game where I'd already set a battlesnake and a hungry bot an 11 by 11 board, and we'll start the game.\u003C/p>\u003Cp>And that should be running game in progress. I can kind of see my logs over here that the game is still happening. I'll wait for the game to conclude, which it has not yet. You know what? I've run out of patience.\u003C/p>\u003Cp>Oh, no. It happened. So let's hit.\u003C/p>\u003Cp>Speaker 1: There we go.\u003C/p>\u003Cp>Speaker 0: Excellent. It did end up doing itself in, so there is something wrong, but we're not we're not looking into that bit right now.\u003C/p>\u003Cp>Speaker 1: It worked. That's the important thing.\u003C/p>\u003Cp>Speaker 0: It it worked for some period. Anyway, that's all so it is it is talking successfully, to directors, which is useful. Now what we now wanna do is figure out what we need to log. And before we do this, let's create a collection for it. So we'll go to our data model, we'll create a collection and what are we going to log?\u003C/p>\u003Cp>I don't think we should log every turn. I mean, we could log every turn.\u003C/p>\u003Cp>Speaker 1: Well, I I mean, we could. I think I don't think it's necessary either. I think let's let's let's right now just log the final move just as like a getting started place. We're just gonna pass that data right through. And then let's do at like, ultimately, we'll end up adding something around, win or loss, because I think there's something cool visualizing that.\u003C/p>\u003Cp>And then I think there's honestly, I'd be love to explore us actually pulling the game GIF from this, which I think is more logic, but I think it's very interesting should be pretty straightforward.\u003C/p>\u003Cp>Speaker 0: So if we want to log this, if we wanna log the the game, we need to be doing this actually in the end endpoint. Right? We don't want to be doing this in the move endpoint. We want to do it in the endgame. So this actually means we need to a little bit more fiddling, a little bit more fiddling with directors.\u003C/p>\u003Cp>And to the dismay of our lovely editor, I'm actually gonna unshare and reshare, but I'm gonna do my whole screen this time because No camera job. It's too late. I'm doing it. It's done. It's gone.\u003C/p>\u003Cp>It's done.\u003C/p>\u003Cp>Speaker 1: Farewell. It's it's gone. Farewell screen.\u003C/p>\u003Cp>Speaker 0: Okay. Apologies for for for that. But what we have here I'm gonna just reconfigure also.\u003C/p>\u003Cp>Speaker 1: See every day, Kevin, by the way? Is this your screen, this large massive thing?\u003C/p>\u003Cp>Speaker 0: It's a 49 inch ultrawide monitor, which will feature in a future episode of What's in My Doc because the final episode of the season is yours truly. We talk about it more then. So if I just make this bigger, we want to we have this move endpoint here. We can delete all of this logic that was left actually. But we have let me just shrink this down a bit.\u003C/p>\u003Cp>Just a reminder, when we hit the root endpoint, we're gonna hit this flow. When we hit the move endpoint, we're gonna hit this flow, the start and there's end. So what we're gonna do is basically add this logic to to end. So what we're gonna do is, kind of similar to the info end point. You know?\u003C/p>\u003Cp>The info end point. Yeah.\u003C/p>\u003Cp>Speaker 1: Yep. Yep. Same thing.\u003C/p>\u003Cp>Speaker 0: Yeah. Although that is a get endpoint. We need a post endpoint. So it's more similar to move, I guess. But what we'll do is we'll create a new one.\u003C/p>\u003Cp>We'll call this snake, end. This can be based on a web hook trigger. It will be a post request. It is a post request. Right?\u003C/p>\u003Cp>I mean, we'll\u003C/p>\u003Cp>Speaker 1: find out together. I'm pretty sure it's a post request. Yeah.\u003C/p>\u003Cp>Speaker 0: We we will, but I'm also gonna I'm also gonna double check.\u003C/p>\u003Cp>Speaker 1: Look at the documentation. Probably smart idea.\u003C/p>\u003Cp>Speaker 0: Look at the documentation.\u003C/p>\u003Cp>Speaker 1: Not there though.\u003C/p>\u003Cp>Speaker 0: Webhooks. Here we are. Game over. It's a post request as an error hit, by the way. It's it's not formatted as a code block, but it's a post request to slash end.\u003C/p>\u003Cp>It will be the game object, the final turn number, which is useful, the board describing the initial state of the game board. That doesn't feel correct. Oh, on that final turn, I guess. And you describing your battle snake. And I wonder if there's a death reason, but we can find out.\u003C/p>\u003Cp>So response body date of last operation. Great. And first thing we're gonna do is just copy this URL. I'll hit save. We'll copy this URL and we will go ahead here and const flow response.\u003C/p>\u003Cp>I'm not sure we need to, respond to this, but we will Await fetch full URL. We're basically just gonna copy and paste the all of these options because they remain the same. And then we're just gonna send okay. We don't need to do like we actually don't care about the flow response. We're just gonna send all the data by fetch and then send okay.\u003C/p>\u003Cp>We just need the data. We don't and eventually to respond. So we'll save that.\u003C/p>\u003Cp>Speaker 1: Hear that flow response? We don't need you. We\u003C/p>\u003Cp>Speaker 0: don't need you. Yeah. So inside of our extensions, director snake, we'll run npm run build. Oh, in today's release of Directus, we squash the bug that stopped the autoreloading working. So That's awesome.\u003C/p>\u003Cp>Nice.\u003C/p>\u003Cp>Speaker 1: Was that because of us?\u003C/p>\u003Cp>Speaker 0: No. Not even remotely. Well, I'd like to think it is. 10.9. 10.9 came out yesterday, so it resolved that.\u003C/p>\u003Cp>So now we have our new extension. With this new endpoint, we don't need to do anything more there. Back over to our code editor here. I suppose we can just we can actually just leave this be. Yeah.\u003C/p>\u003Cp>And we can Yeah.\u003C/p>\u003Cp>Speaker 1: Let's just log, see if it shows\u003C/p>\u003Cp>Speaker 0: before. It. Yeah. Exactly. Create rematch.\u003C/p>\u003Cp>So that whole game is is running. We see that 200 all the way. Really low really low, response. That's great. Running, running, running.\u003C/p>\u003Cp>And then we now no longer, we remove the console log for end. Oh, this is on start. Have we done it in the wrong place? Everyone, we've done it in the wrong place. I know.\u003C/p>\u003Cp>Amateur hour. But it is logging it, so we know what we know what the shape would be. Yep. So we can do that instead. We'll make this async.\u003C/p>\u003Cp>We'll remove async here. We will go and rebuild the extension, and then we'll restart directives. And while that's kinda happening, we can we can take a look at this object here. So we have game, which is an ID, which we'll probably wanna store. The rule set perhaps, probably not for this one, The the final turn, 95.\u003C/p>\u003Cp>Don't know what we wanna know about the board probably because 95, it's the turn where you're dead. So that's that array will not include us or it will include us and we'll be the last one standing, I guess. You has health. So I wonder oh, maybe we won this one. Maybe we won this one.\u003C/p>\u003Cp>Let's, let's watch it. Have a sneaking suspicion we did win. Yeah.\u003C/p>\u003Cp>Speaker 1: So wait. How did we how do does it show that for us in that result? Like, it doesn't it doesn't say, like, in our in\u003C/p>\u003Cp>Speaker 0: the law No. No. But I I I wondered why is it still giving me a health of 90? Why did it give me a health of whatever it was, 83? Smart.\u003C/p>\u003Cp>I have a sneaking suspicion if you die, the payload looks different, but there's only one way to test it, which is I've now restarted Directus. If I refresh this, there should be some logs. So this was the log of the one we just accidentally ran when we shouldn't have. So this is the start. So we'll just forget that one.\u003C/p>\u003Cp>Let's, let's do a rematch. And now we should only get the response when when it dies. So we can see this. We see it's posting slash snake slash move. And the last thing it should do is post slash snake slash end and it should hit a different trigger.\u003C/p>\u003Cp>So we'll just watch that happening and this is happening real quick. Wonderful. And that is what happened. It had a different flow at the end slash snake slash end. So if we go back to our flow now and refresh, we should be able to look at the logs.\u003C/p>\u003Cp>Payload. Okay. So this oh, did we win or or lose? That's probably worth knowing ahead of time. You won\u003C/p>\u003Cp>Speaker 1: again. Come on, ready, set, battle snake. What are you doing winning all the time? You're too good. You're too good.\u003C/p>\u003Cp>Speaker 0: Too good. So 73 turn 73. That is us, ready, set, battlesnake. We know our ID. I wonder if there's something in here where we log what our own Battlesnake is, but it may not be necessary.\u003C/p>\u003Cp>Let let's keep looking. It has health of 92. It has a length of 6, which could be interesting. We don't need to know what all the food is, where all the hazards are. You is just a convenience again.\u003C/p>\u003Cp>Alright. Let's, let's literally just keep creating rematches till we die. We'll let this run-in real time which means we we're gonna have to wait a hot minute as every move happens. Are we too Lindsay.\u003C/p>\u003Cp>Speaker 1: Are we too good at programming Battlesnakes that he will live forever? Is that are we gonna need to are we gonna need to, pause?\u003C/p>\u003Cp>Speaker 0: Artificially. I'm gonna have to artificially make him just, like, die.\u003C/p>\u003Cp>Speaker 1: Come on. I think we oh my goodness. Come on. We gotta do it again. Gotta play again.\u003C/p>\u003Cp>Okay. Okay. Come on. 3rd time's the charm. We did, we did too much, Kevin.\u003C/p>\u003Cp>We went too hard.\u003C/p>\u003Cp>Speaker 0: That, game in progress thing is not behaving, so we'll restart a game this way. I mean, if I just add ourselves, eventually, we'll die.\u003C/p>\u003Cp>Speaker 1: Oh, there you go. Yeah. And it's interesting too. So, I think part of the game in progress thing might be I know I know Battle Sneak scaled down the server load, so it may be something related to that. Maybe.\u003C/p>\u003Cp>But, yes, we should live for we're gonna live forever. That's really what you've just done here. You're about to, you're about to kill your local version of Directus just because this will run forever. Hey. Good time.\u003C/p>\u003Cp>Alright. I immediately got it right and wrong. Thank you. Thank you. I reset Battlesnake.\u003C/p>\u003Cp>Alright.\u003C/p>\u003Cp>Speaker 0: I mean, eventually, we had to lose. Right? So let's look at the final log when we lose. And I have a hunch. It is that our battlesnake does have a health of 97.\u003C/p>\u003Cp>So there is a health in there. So that isn't how we determine whether we live or die, unfortunately. We have a board. We have you. Although, where are the oh, the snakes array is empty.\u003C/p>\u003Cp>So we are not so we are there. Sorry. But we are not present in the snakes array.\u003C/p>\u003Cp>Speaker 1: Oh, okay. That makes sense. So if the snake array is empty, we didn't win. If we are not empty\u003C/p>\u003Cp>Speaker 0: if we are not in it. Yes. If we are not in it. So the easy the easy thing to do here is we have a we know our snake ID. Here it is.\u003C/p>\u003Cp>We could store it in a collection of our snakes to like factor out or we could just hard code it in.\u003C/p>\u003Cp>Speaker 1: Well, let's let's let's have some fun. Let's let's do the more challenging\u003C/p>\u003Cp>Speaker 0: Sure. More challenging. Snakes. And then, actually, if we look at the if we look at the API, I don't think there is a a meta Battlesnake API is there to get information about games and stuff. No, that's fine.\u003C/p>\u003Cp>What else should what there could be. Yeah. What if there is there's a start endpoint. I wonder if no, it's fine. We'll we'll we'll hard code this snakes.\u003C/p>\u003Cp>All we care about snakes is that they have a manually entered string as the ID and we can add all the others later. So if we go to our snakes, we'll put in the ID. That's ours. And you know what? We'll just add a name to it just so we can tell what it is.\u003C/p>\u003Cp>Right? So, this battle snake is ready, set, battlescape, I actually think is its actual name because we wanted to distinguish the one you made to the one I made. And my name is Elsford k. So it's registered Battlescape. Okay.\u003C/p>\u003Cp>Cool. So we've got that. So what are we gonna do inside of this end flow? First thing we need to do, I suppose, is we get this whole payload. The only thing we wanna enrich it with right now is are we alive?\u003C/p>\u003Cp>So Yeah. Is alive. Did live. Did I live? And that's going to run scripts.\u003C/p>\u003Cp>No, it isn't. First of all, we're gonna get all of our snakes. That's what we should do. Read items from the database. So, get snakes.\u003C/p>\u003Cp>Permissions from the from trigger. I'm just gonna give it full access so we don't need to contend with permissions. Snakes. If I don't add any IDs, do I get them all?\u003C/p>\u003Cp>Speaker 1: We'll find out. We gotta find out.\u003C/p>\u003Cp>Speaker 0: This is\u003C/p>\u003Cp>Speaker 1: trial and error, Kevin. This is trial and\u003C/p>\u003Cp>Speaker 0: error. Real, real trial and error thing going on here. Alright. Let's create a rematch with ourselves. I feel like I should add another snake back in just to end the games quicker.\u003C/p>\u003Cp>Speaker 1: So do it. Yeah. Do it. Add another snake in. Just go back and\u003C/p>\u003Cp>Speaker 0: make sure I'll let I'll let this game conclude. We'll do it until the next time we do\u003C/p>\u003Cp>Speaker 1: it.\u003C/p>\u003Cp>Speaker 0: Still running.\u003C/p>\u003Cp>Speaker 1: By the way, it looks\u003C/p>\u003Cp>Speaker 0: like games. Oh, thank you. I actually was really trying to find, like, the end of Loki season 2, all of the timelines. I'm not sure if you've seen it. And so it was kind of Yes, I've probably seen it.\u003C/p>\u003Cp>I've seen it's going for. Yeah. It was kind of that vibe I was going for. Okay. So obviously we eventually die.\u003C/p>\u003Cp>That's just the nature of playing by yourself. Let's just see how they perform now. Okay. Again, no idea why. Really shouldn't be doing that.\u003C/p>\u003Cp>But\u003C/p>\u003Cp>Speaker 1: Don't question it. We wanted that to happen. We willed it into being. We willed it to happen.\u003C/p>\u003Cp>Speaker 0: We want you to be chitter. Alright. There there's all of our snakes. So that's great. So that that returns an array of objects which contain IDs which are our snakes.\u003C/p>\u003Cp>So the next thing we want to do then is did live, like, you know, did live. And we will run a script here. And all we wanna determine here is, what did we call the last one? Snakes. So data dot snakes is the array of snakes and we want to know and we want to know did the trigger dot I need to I don't want I don't wanna close it.\u003C/p>\u003Cp>Don't wanna close it to to take a look. Let's look at the docs. Webhooks. So it will be trigger dot, I think, payload.\u003C/p>\u003Cp>Speaker 1: I think so. Yeah.\u003C/p>\u003Cp>Speaker 0: Yeah. We can always fix that later. The payload.board.snakes. So we wanna see, did that contain that? So, JavaScript, does array contain other does array contain specific item?\u003C/p>\u003Cp>I think it's like includes yeah. Does array contain item from other? Right? I'm pretty sure we just did this in our last episode.\u003C/p>\u003Cp>Speaker 1: I think so. Yeah.\u003C/p>\u003Cp>Speaker 0: Some. And I think I used find instead. So, live, which is like the if it lives, it will be found. So we'll say is inside of data dot snakes, is does that contain yes. Does that contain does data.snakes contain?\u003C/p>\u003Cp>And this is where it gets a bit honky, and I need to just just have a moment to think. So we wanna know out of all of the items in the snake array of which of which we know the I the ID is gonna be snake dot it. We know that already. Does is snake ID equal or does snake ID I got it. Does snake ID feature inside of this array?\u003C/p>\u003Cp>So what we actually wanna do is return whether this array, the one with all the snakes on the board contains, which I think we've determined is includes includes.\u003C/p>\u003Cp>Speaker 1: Yep.\u003C/p>\u003Cp>Speaker 0: Is it includes? I think we need to simp I think we need to do one more step beforehand which is take this big array here and just simplify it down to IDs. So, const IDs, IDs on board. So we'll take all of that and we'll map it and all we wanna do is turn that into an array of IDs. So it's just IDs.\u003C/p>\u003Cp>It's nothing else but IDs. Forget all the other information. That's all of the boards. We don't That's all of the IDs of the snake on the board. Exactly.\u003C/p>\u003Cp>And then we will return whether or not IDs on board that's it. IDs on board includes any of our snakes IDs and we will return to live. So true force, true false, did it. Really?\u003C/p>\u003Cp>Speaker 1: It's gonna work. First time's the charm.\u003C/p>\u003Cp>Speaker 0: Oh, no. I've done it again. I've hit create rematch, But eventually the answer will be false, right, this time with confidence. It should be. Or it'll just live forever and this will be this will be our time.\u003C/p>\u003Cp>Okay. Hit its hit its own tail. Mounted itself into a corner and did itself in. So let's, look at the last log. Cannot read properties of undefined.\u003C/p>\u003Cp>Okay. Cool. And it was body, by the way. It was trigger dot body. So that will probably be why.\u003C/p>\u003Cp>Trigger.body.board.snakes.map. So let's, let's just check that. Body dot board dot snakes. Cool. So we will create rematch.\u003C/p>\u003Cp>Speaker 1: And now second time.\u003C/p>\u003Cp>Speaker 0: And now.\u003C/p>\u003Cp>Speaker 1: Go, red snappettlesnake.\u003C/p>\u003Cp>Speaker 0: So stop eating food. Stop eating food. As it gets towards the food, I'm like, no.\u003C/p>\u003Cp>Speaker 1: Come on. What are you doing? We don't want you to live anymore. What are you why?\u003C/p>\u003Cp>Speaker 0: Why are you doing this? This battle snake is not bad apart from those times it randomly goes off the edge of the board, and we don't know why. I think it's just got\u003C/p>\u003Cp>Speaker 1: a it's got a it's got a spirit of its own.\u003C/p>\u003Cp>Speaker 0: Oh, what's happened there? Oh, there we go. Oh, okay.\u003C/p>\u003Cp>Speaker 1: There was some real They\u003C/p>\u003Cp>Speaker 0: were clearly in a queue or something.\u003C/p>\u003Cp>Speaker 1: Goodness. Wow. We're doing I Oh, there we go. Why did you do\u003C/p>\u003Cp>Speaker 0: that? I don't know. Oh, yeah. Yeah. Yeah.\u003C/p>\u003Cp>Right. It knocked itself into a into that kind of spot where where it can't. There is no viable move. Right. So we'll look at this.\u003C/p>\u003Cp>Cannot read properties of undefined. Okay. Okay. What is undefined? What's undefined is what we're running find on.\u003C/p>\u003Cp>So let's take a look at that. We're running find on data dot snakes. Okay? Except oh, because we call it get snakes. Fair.\u003C/p>\u003Cp>We'll call that snakes. Great rematch. This is the only thing when you'll see ready. Set up\u003C/p>\u003Cp>Speaker 1: the snake. Sorry. This is the only thing when you're debugging. Go on. And you were saying something valuable as part of this conversation.\u003C/p>\u003Cp>I was trying to add\u003C/p>\u003Cp>Speaker 0: some color. Wait. You there's there is just a bit of waiting here. Right? I suppose because the rules engine is open source.\u003C/p>\u003Cp>I imagine people I think people have built, like, line emulators that can obviously execute this way, way, way quicker for the sake of debugging. And I see the value in those tools.\u003C/p>\u003Cp>Speaker 1: Yeah. You can actually do it in the CLI. In the CLI, you can actually play full games and see them.\u003C/p>\u003Cp>Speaker 0: Because we just had to weigh a 153 turns. Alright. Trigger is not defined. Still. Okay.\u003C/p>\u003Cp>Trigger is and you know what? Because it's data dot trigger. So many amateur amateur hour little mistakes today. Never.\u003C/p>\u003Cp>Speaker 1: Never, Kevin. Amateur is, is a term that we need to take back as a positive\u003C/p>\u003Cp>Speaker 0: As amateurs.\u003C/p>\u003Cp>Speaker 1: As amateur. As amateurs, yeah. Alright. Come on, ready set battle snake. You can die.\u003C/p>\u003Cp>Don't survive.\u003C/p>\u003Cp>Speaker 0: Please don't.\u003C/p>\u003Cp>Speaker 1: I believe in I I don't believe in you. I feel like he thrives.\u003C/p>\u003Cp>Speaker 0: So the weather so the weather today.\u003C/p>\u003Cp>Speaker 1: Yeah. Oh. Oh. Is that is this it?\u003C/p>\u003Cp>Speaker 0: No. No. It it will lit. It's just obviously saving up moves. Yeah.\u003C/p>\u003Cp>There we go. Woah. It's like a taunt. That was like a taunt to us.\u003C/p>\u003Cp>Speaker 1: Come on.\u003C/p>\u003Cp>Speaker 0: We're doing exactly as we the thing is we made we made this snake. We made this snake.\u003C/p>\u003Cp>Speaker 1: I feel like we is a very, oh, there we go. Alright. He made himself, really. Alright. Let's see if this worked this time.\u003C/p>\u003Cp>What do our logs say? Hey. We got data.\u003C/p>\u003Cp>Speaker 0: Yeah. But this isn't what we want. What do you mean? What we want. I don't know, but I just want, I just want, I just want a true false value so something's not right.\u003C/p>\u003Cp>Speaker 1: But wait\u003C/p>\u003Cp>Speaker 0: So, yeah, go on.\u003C/p>\u003Cp>Speaker 1: Well, I'm just like, what are we returning? Sorry. It's the text\u003C/p>\u003Cp>Speaker 0: is really small.\u003C/p>\u003Cp>Speaker 1: Not because of your\u003C/p>\u003Cp>Speaker 0: screen. It's because We are returning, the whole, like, body of the script, which feels a little bit weird. And I have a hunch. I have a hunch. It's oh, no.\u003C/p>\u003Cp>Did live. This is live. So what's going on? What's going on there?\u003C/p>\u003Cp>Speaker 1: Super weird. That shouldn't be returning that.\u003C/p>\u003Cp>Speaker 0: No. It should not. Let's, look at our previous flow, the move one, and just maybe not, like just take a little bit of yeah. I mean, if we take all of this, and I'm just doing this as a comparison point just so we can kind of dump it in here and take a look kind of side by side, if you will. Yeah.\u003C/p>\u003Cp>Data dot trigger, Return. We do just return a value. Maybe, let's take a look at, array find method. Let's just understand this a little bit better. This returns the 1st element in the provided array that satisfies the provided testing condition.\u003C/p>\u003Cp>If you need an index, you can use find index. If you need to find the value, if you need to find if a value exists, you can use includes, which actually I think is what we want because that just returns a true or false. So maybe we just swap this out for an includes, includes, And we wanna know yeah. It's like a nested includes. Fine.\u003C/p>\u003Cp>And then we return I'm just I'm a little bit confused why it was returning\u003C/p>\u003Cp>Speaker 1: Yeah. The whole code.\u003C/p>\u003Cp>Speaker 0: Well, we no. You know what? We also don't get here. We don't get a returned payload, which makes me think there was some kind of error happening here that wasn't being captured correctly. Is there anything in here?\u003C/p>\u003Cp>I wouldn't imagine there is, and it's now really hard to tell. Let's, let's create a game. Let's let's make this game a lot, a lot quicker to end.\u003C/p>\u003Cp>Speaker 1: Hey. There we go.\u003C/p>\u003Cp>Speaker 0: Well, do you see how quick that was?\u003C/p>\u003Cp>Speaker 1: That was fast. We are smarter than hungry.\u003C/p>\u003Cp>Speaker 0: Niamis.\u003C/p>\u003Cp>Speaker 1: Come on. What are you doing, Raze at Battlesnake? We want you to not die. We just want you to die.\u003C/p>\u003Cp>Speaker 0: We might we might have to nip out some of the logic or something.\u003C/p>\u003Cp>Speaker 1: I've never had a\u003C/p>\u003Cp>Speaker 0: Well, well, that will that that will be the end. That will be the last move when it finally catches up with that with with Toast. Yeah. Snake end. The game seems to be struggling with the concept of ending, but it has ended.\u003C/p>\u003Cp>Alright. Yeah. Look. We get the options here, but we don't get the payload. Because if you look at the other flows, for example, wow, 1632.\u003C/p>\u003Cp>Wow. You see that all of these run scripts. I know they have the payloads. They have the options and they have a payload. Options payload, determine move interestingly interestingly, does does not have a returned payload.\u003C/p>\u003Cp>Is there something about them returning objects and strings versus just returning like a primitive. Maybe that's what it is. So if I so if I because this could be fine, you know, return. That's returning an object. Right?\u003C/p>\u003Cp>Mhmm. Let's create a rematch. Okay. Our snake just went up and up again. Hey.\u003C/p>\u003Cp>We don't know why happened.\u003C/p>\u003Cp>Speaker 1: Bad things happened. We changed we changed the code. Shouldn't have done that.\u003C/p>\u003Cp>Speaker 0: Changed the code. Shouldn't have done oh, there we are. Did live force. Okay. Awesome.\u003C/p>\u003Cp>Cool. So so there was actually no problem. Just an interesting note there that for it to show up in the payload, it needs to be an object or an array, I presume. So just a good just a good note there. I would love to play a game where we don't lose.\u003C/p>\u003Cp>So we can just so we can just check both sides of that equation and that they make sense. Let's create small boards.\u003C/p>\u003Cp>Speaker 1: If we play with ourselves It wouldn't then technically, we'll always win and always win.\u003C/p>\u003Cp>Speaker 0: Oh, well, yeah. But then I think it's just gonna get a little bit weird. There we are. Hey. We no.\u003C/p>\u003Cp>Wait. That's not what we want.\u003C/p>\u003Cp>Speaker 1: That's what we want. But We've wanted to lose so much that now to win seems like a wrong thing.\u003C/p>\u003Cp>Speaker 0: So did live should be forced. Yeah. Live should be forced. Let's create a rematch. Maybe we need to put in a a a a less clever snake.\u003C/p>\u003Cp>Goodness. Okay. Try Do you want the right bot? Yeah. Yeah?\u003C/p>\u003Cp>We we haven't we haven't gotta live long to make that work. Okay. Great. So now if we refresh, we look at the logs. Did live hopefully should be\u003C/p>\u003Cp>Speaker 1: False. Absolutely. That's totally what we were wanting to have happen.\u003C/p>\u003Cp>Speaker 0: Great. Is this really what we're gonna spend this episode doing? Okay. Fine.\u003C/p>\u003Cp>Speaker 1: That's it. Just debugging JavaScript. That's really what we're here for.\u003C/p>\u003Cp>Speaker 0: Right. All we want to do is now maybe maybe we just roll back for a sec. We're doing all of this grab snakes thing. I don't think this is adding I've deleted it. I've just done it.\u003C/p>\u003Cp>I've just done it. I've been busy for decision. Exec executive decision. All we care about is this ID. Right?\u003C/p>\u003Cp>So let's just we'll we'll delete this. We're gonna\u003C/p>\u003Cp>Speaker 1: hard code it in now. Okay.\u003C/p>\u003Cp>Speaker 0: Yeah. Yeah. Like, I don't think it's worth, like, going at all costs. Right? So all we want to know is does data dot snake say const?\u003C/p>\u003Cp>In fact, I think we can say, does snake include data dot trigger dot body dot board dot snakes dot map. Sure. So that's just a set of IDs. And all we wanna know is, does IDs onboard include this? And I'm I'm assuming can I console log inside of these?\u003C/p>\u003Cp>Best bit of, debugging we got. Great rematch. Well, I think our snake's broken. I think we spoke too soon about the capability of our snake. In it doesn't like includes.\u003C/p>\u003Cp>Payload.body. Right. Hang on. It doesn't like includes, which is this one here. And we don't get a log, annoyingly.\u003C/p>\u003Cp>So all we care about, Let's, you know what? I'm actually gonna be bold here and just remove this, and we can start we can start again. So so all we wanna know is did it live? And to know if it lives, we're gonna go through oh, no. I do need to I need this too.\u003C/p>\u003Cp>Speaker 1: I like it. I like the I like that you were confident in the removal,\u003C/p>\u003Cp>Speaker 0: but also\u003C/p>\u003Cp>Speaker 1: truly confident. That I you\u003C/p>\u003Cp>Speaker 0: know, I really wasn't. So all you wanna know is, does data dot trigger dot body dot board dot snakes, does that include includes includes let's take a look. We need to give it a specific value here. So I think what we'll first do is we'll say snake IDs on board. We'll take this and we'll map it once again.\u003C/p>\u003Cp>So we just extract the IDs. Then all we wanna do is check whether snake IDs on board includes this value here. It's all we wanna know. Please work. Create rematch.\u003C/p>\u003Cp>Speaker 1: We've got this.\u003C/p>\u003Cp>Speaker 0: Okay. Our snake just keeps going up by the way. We fundamentally broken something.\u003C/p>\u003Cp>Speaker 1: But I mean, these things happen. These things happen. We'll figure it out.\u003C/p>\u003Cp>Speaker 0: We've got Live force.\u003C/p>\u003Cp>Speaker 1: The rest of today.\u003C/p>\u003Cp>Speaker 0: Live force. Okay. And we did we did we did live force. Yes. That is that is true.\u003C/p>\u003Cp>And all we need to do is outlive the snake, which we did, and hopefully live is true in this context. We may need to go back as as we commented in Okay. But we lived, but we lived. Let's let's take a look at the payload. Let's take a look at the payload.\u003C/p>\u003Cp>So body dot game, no. Body dot board dot snakes has ready set battlesnake present, and that's it. The snakes have an ID. That's our ID. That is I'm just gonna double check.\u003C/p>\u003Cp>Yep. The ID, nope. Not the ID we've been pasting in. What does it get a different does it well, it's different. So I'm wondering, look at this ID, w d at the end.\u003C/p>\u003Cp>If I look one game back, it gets a different ID every time, Andrew.\u003C/p>\u003Cp>Speaker 1: So we gotta pull name then, I guess. I guess the ID is not\u003C/p>\u003Cp>Speaker 0: I'm literally so mad. Yes. Fine.\u003C/p>\u003Cp>Speaker 1: As well, you should be. Damn you, battle stake and your your ID that is not truly the snake ID. Who do\u003C/p>\u003Cp>Speaker 0: you It does feel that way. I can't believe we sunk so much time into that. Okay. Cool. No.\u003C/p>\u003Cp>Right. Create custom game. Create rematch. Okay. We lost because apparently we just go up now.\u003C/p>\u003Cp>Yeah. Liveforce. Cool. And create rematch. Yeah.\u003C/p>\u003Cp>I mean, we lost again. Sure. Because that's what's happening now. What is going on with that, by the way? What is going on with that?\u003C/p>\u003Cp>Is it is it work. Are we struggling under the number of logs that are being generated?\u003C/p>\u003Cp>Speaker 1: No.\u003C/p>\u003Cp>Speaker 0: I mean, possible. Look, avoid head to head force. So there's something in the avoid head to head. Oh, god. Because there was no head to head issue here.\u003C/p>\u003Cp>No. There wasn't. Let's create rematch just until we get a a seed. I think, yeah, we both die at the same time there. Let's create rematch.\u003C/p>\u003Cp>Let's just create a seed just to test out this logic. Yeah. That's good. Nope. Not good.\u003C/p>\u003Cp>Okay. Create game. Okay. We we broke it. We broke it.\u003C/p>\u003Cp>Okay. We are still not gonna do well this oh, what is going on? There we go. Is it\u003C/p>\u003Cp>Speaker 1: there someone\u003C/p>\u003Cp>Speaker 0: is there something is there something about we did? Is there something about the board size being different that's throwing it off? In which case, I'm quite happy to say how Battlesnake only operates in 11.\u003C/p>\u003Cp>Speaker 1: That's the right answer. Don't make it work on all the boards. Only standard class.\u003C/p>\u003Cp>Speaker 0: True. Okay. Hey. There we go. Finally know whether it lives.\u003C/p>\u003Cp>Now it's all about logging information. So let's look at this payload and see what we have. So we have a game ID, which I think feels like a no brainer. Right? Yeah.\u003C/p>\u003Cp>And you said we can do something with the ID to get the GIF?\u003C/p>\u003Cp>Speaker 1: I believe so. I'm gonna go check and see something right now. I'm gonna go over while you're doing this, I'm gonna go over to my other screen. But, yes, we'll pull back so that we need that.\u003C/p>\u003Cp>Speaker 0: We know the turn of the final move, which is 2. Yep. Right. So that's the term where we were victorious. We know that we lived.\u003C/p>\u003Cp>We know our length, I suppose.\u003C/p>\u003Cp>Speaker 1: Yeah. I think so.\u003C/p>\u003Cp>Speaker 0: Yeah. And maybe we do maybe we start with just games. Games get an ID, which can be a manually entered string because we'll we'll pop that in from the API. And I think all we need here is win or lose, right? Win.\u003C/p>\u003Cp>That's a Boolean. We wanna know what about it. Like, a turn, I suppose. That can be an integer.\u003C/p>\u003Cp>Speaker 1: I mean, game mode? Turns. Yep. Turns.\u003C/p>\u003Cp>Speaker 0: Turns feels better. Yep. Turns. Into game mode, but we're not playing around with other game modes. So I just think That's true.\u003C/p>\u003Cp>Yeah. It's fair. Yeah. But but the idea is, in theory, you could you could store all of this. Wind turns.\u003C/p>\u003Cp>What else have we got at our disposal? Let's take another look at our end state here. We have live die. We had turns. We can start with how many snakes there were on the board from the trigger.\u003C/p>\u003Cp>So snakes dot so trigger trigger body board snakes length. Just quickly gonna go, store. We're gonna prepare data. So trigger dot body dot board, did we say it was? Dot snakes.length.\u003C/p>\u003Cp>So I'm just gonna pop that in there for later. Yeah. So snakes, that can be another integer. What what else what else do we wanna know?\u003C/p>\u003Cp>Speaker 1: I mean, let's let's let's stick it with that. Good because we\u003C/p>\u003Cp>Speaker 0: you could do, like, a win ratio. You could do, like, average turns per game. Like there's lots you can do here. Do you continue getting data if you are not the last to loot? Like if you die and it goes on a few more steps, do you only get the end state on your final turn or do you like, let's take a look.\u003C/p>\u003Cp>Your battle snake will whenever a game it has playing has been ended, use it to learn how you battle snake won or loss and deallocate any server side resources. Okay. This was like a good starting point. So this is what a game looks like. ID win turns snakes.\u003C/p>\u003Cp>So going back to flows, let's, do our end. So did live. We're gonna prepare data. So the only extra thing we wanted to know here was snakes. Snake count.\u003C/p>\u003Cp>What else do we wanna know here? We we might as well get it already to be fair. Might as well just do it straight within here. So snake count. Is this.\u003C/p>\u003Cp>We have we had snake count. We had turns. So once again, let's just take a look at the it was game. I think it's game dot turn. Game?\u003C/p>\u003Cp>Maybe not. Bored?\u003C/p>\u003Cp>Speaker 1: Bored? Bored?\u003C/p>\u003Cp>Speaker 0: Hold on. No. Am I using it? Oh, it's right here. At the root, turn, integer.\u003C/p>\u003Cp>So that should just be trigger.body.turn. And we wanna know we wanna tell how many things. We wanna tell how many turns. We wanna tell whether we lived or died that we needed the ID. ID.\u003C/p>\u003Cp>So trigger dot body dot the ID. I think it's just I game dot ID, I think. We'll find That sounds right. Game dot ID. Yeah.\u003C/p>\u003Cp>Nice. And while we're here, let's, let's just also get the did live. So live. Live? What did what did we call it in our director's collection?\u003C/p>\u003Cp>Speaker 1: Lip libs? Let's take a look. Was just libs?\u003C/p>\u003Cp>Speaker 0: It's called win, actually. Win. Alright. Smart. Win.\u003C/p>\u003Cp>So, oh, so in here, we'll go prepare data. We'll go live, but it's called win here. Live, live. Fine. Whatever.\u003C/p>\u003Cp>So we have, I really don't like using last or I can help it because it allows you to obviously move things around without your data becoming like brittle. So I'm gonna pop did live. And all of these have to be prepended with data. Okay. So in theory, that's the preparation of the data.\u003C/p>\u003Cp>Let's, let's run a custom game one more time. If our snake performs well, it will have been the 7 by 7 board that did it in. Well, I think I think oh, of course, we've just got let's create the game with the ready set battle snake and the hungry bot now. Yeah. Weird, isn't it?\u003C/p>\u003Cp>Anyway That's such a good idea.\u003C/p>\u003Cp>Speaker 1: I wonder what we did. Don't don't wanna know. No. That's a question for, for season 2.\u003C/p>\u003Cp>Speaker 0: That was a question. Set back. That was a question for last week of and now it's this week of do you see how big that snake's getting? Oh, of course, it's hungry, but isn't it? That's its whole that's its whole shtick.\u003C/p>\u003Cp>Speaker 1: Are we gonna win this one? Oh, we won it still.\u003C/p>\u003Cp>Speaker 0: Yes. Legit did. So Well if we refresh here and look at our log payload, snake count 1. This is wrong. So we need to just look at this because we wanna know how many snakes were in the whole game, which in theory should always be\u003C/p>\u003Cp>Speaker 1: no. It won't always be this. End. We're pulling from end, so it's only gonna pull the last snake. Right?\u003C/p>\u003Cp>Is that what we that's what\u003C/p>\u003Cp>Speaker 0: the Yeah. Maybe we maybe we need to do it on start. We need to create it. And then on end, we need to update it. We have turns, we have the ID and we have whether we want, which is true.\u003C/p>\u003Cp>So maybe for snake count, because I do think snake count is interesting. We should create just create the data. What do you think? Or do you think it's too heavy handed to create a whole flow for that?\u003C/p>\u003Cp>Speaker 1: I mean, I don't think we need a whole flow for it. That seems like a bit of\u003C/p>\u003Cp>Speaker 0: a change. I mean, we need we need a flow for it. That's the truth. So may I mean, we we've we've got pretty we've got pretty proficient at it now. So what we're gonna do is create a flow.\u003C/p>\u003Cp>Yeah. Yeah. We'll call it snake start, Right? And so what we're gonna do here is we're gonna do this as a webhook. It'll be a post request.\u003C/p>\u003Cp>We'll go like this. Just double check the API reference webhooks. Your request to this your response to this request will be ignored. We don't need to care about our response. We'll save this, grab this URL, and then we are going to take this whole end here.\u003C/p>\u003Cp>And on the start, we'll make that async. We'll paste that in there, except this time we will change the URL to this 1, 704. So that start, we need to just kill this, go here, rebuild our extension, Done. Go here and Docker Compose up. Wonderful.\u003C/p>\u003Cp>Should be able to refresh. Should be able to refresh. Now I think it just took a moment just a moment to spin up there. And what are we gonna do here? We're first gonna save.\u003C/p>\u003Cp>We're gonna go and create a game. This will need we don't even need to wait for the game to pan out in order to look at this one log. All we care about is I suppose number of snakes here. So trigger, body, board snakes. Trigger body board snakes.\u003C/p>\u003Cp>So what we'll do here is create sorry? Board trigger body snakes. No. Trigger. Shouldn't be Stop it.\u003C/p>\u003Cp>Shouldn't be Stop it.\u003C/p>\u003Cp>Speaker 1: I shouldn't do that.\u003C/p>\u003Cp>Speaker 0: I'm sorry. Create game. We will create data in the game's collection with full access. And all we're gonna do here is we're gonna say the snakes is equal to.\u003C/p>\u003Cp>Speaker 1: Trigger body board snakes. I got it. I got it.\u003C/p>\u003Cp>Speaker 0: They need to be in quotes because it's Jason. Trigger\u003C/p>\u003Cp>Speaker 1: Jason or Jason? I I am a JSON.\u003C/p>\u003Cp>Speaker 0: Jason. There is one there is actually, extract snake count. We just need to get the value out in the previous step. I don't strictly think you need to do this, but just to keep it really clean, what we're gonna do here is we're gonna return snake count. Snakes is equal to data dot trigger dot body dot board dot snakes dot length.\u003C/p>\u003Cp>Snakes. Copy that key. And then the next one, we will create data. The name and key doesn't really matter because it's our last step here. All we care about here is we need to create an ID at the time.\u003C/p>\u003Cp>Oh, but we can create the ID as well. We can get the ID as well at the time of creation. So snakes is going to be equal to, this snake count dot snakes. And I actually think we can ignore this error. There seems to want a string, and I think that's fine even if it's, an int just to stop it moaning.\u003C/p>\u003Cp>And then we also want the ID, which is going to be oh, oh, throwing my cursor around. Here we are. Trigger dot body dot game dot id. So if I save this, we create a new game. Oh, got a little Game in progress.\u003C/p>\u003Cp>I don't think it is. Our snake 1, thank you very much, but we will create a new game. That's fine. Start game. We immediately should get a new log here and we got a trigger but nothing else happened.\u003C/p>\u003Cp>Why? Oh, no. There we are. Create data. Type error cannot read properties of undefined snakes 2 body trigger body game ID.\u003C/p>\u003Cp>Okay. Cannot read properties of undefined reading starts with. Interesting. This looks\u003C/p>\u003Cp>Speaker 1: Looks good.\u003C/p>\u003Cp>Speaker 0: Looks like what we want. Snakes and ID. Is that what we called them? Snakes and ID. What is going on?\u003C/p>\u003Cp>So star. Shrek snake count. Because in theory, this is looking oh, pick collection. That'll do it for the access. Not telling it to do anything.\u003C/p>\u003Cp>Alright. Create game. I've got really you get really proficient at starting new games with Battlesnake, don't you, when debugging? You do. Alright.\u003C/p>\u003Cp>Speaker 1: Did it work? Oh, there we go. Now how That's\u003C/p>\u003Cp>Speaker 0: the idea of a new item, item, which means we now have a new snake. Wonderful. So now going back to our end state, we don't actually want to so let's refresh ourselves. Prepare data, prepares a snake count, turns, ID and win. We do not want a snake count.\u003C/p>\u003Cp>We do not want a snake count. So when we prepare data, we can remove snake count and that leaves us with turns, ID, and win. Yep. Turns, ID, and win. Turns ID and win.\u003C/p>\u003Cp>And, actually, we don't even want the ID here.\u003C/p>\u003Cp>Speaker 1: No. We we do want the ID because we wanna be able to pull that GIF eventually.\u003C/p>\u003Cp>Speaker 0: But we stored it. It already exists.\u003C/p>\u003Cp>Speaker 1: Oh, that's right. Yes. You're right. You're absolutely right.\u003C/p>\u003Cp>Speaker 0: This is what we're gonna This is what we're gonna so all we're gonna do here is now update the data Lovely. In the game's collection with full access with this ID, trigger body game ID, and the payload, I think we might just be able to put in lost and I think that's gonna be equal. I'm not a 100% sure, but I think that's gonna be equal to the object. So we'll see. Alright.\u003C/p>\u003Cp>The first thing we'll do is create a new game, and then I think we'll be ready to jump into insights and see how that works for us. So here's our snake performing well in these apparently quite controlled conditions of an 11 by 11 board with 1 other snake. Okay. Come on. Some something happened now.\u003C/p>\u003Cp>Speaker 1: Come on, hungry. You don't wanna survive. You're not really that hungry anymore.\u003C/p>\u003Cp>Speaker 0: It could be all all one either. You both suck. Hey. Hey. So first thing to do is let's see.\u003C/p>\u003Cp>So you will notice nothing happened there. I've also, to be fair, noticed we don't have any we just have IDs. We probably do also wanna capture, like, the date, like like the now date that's happening because, we just wanna be able to sort the latest item if possible. Yeah.\u003C/p>\u003Cp>Speaker 1: That's fair.\u003C/p>\u003Cp>Speaker 0: So we'll create a date time, finished. We can call this. I think this will work. Date time. Sure.\u003C/p>\u003Cp>And then at the well, firstly, that didn't work. So we don't wanna spend too too much time on this, but we'll prepare the data here and we'll say what was the name of the field? Do you remember?\u003C/p>\u003Cp>Speaker 1: Oh, it was, we didn't call it datetime. We set it today. No. Now? When?\u003C/p>\u003Cp>I'm not sure. Jeez. That that's terrible. Both have forgotten Finished. The minutes of creating it.\u003C/p>\u003Cp>Speaker 0: I mean, same. Same to be fair. Finished. We also wanna store finished, which I think you can just say new date, new date dot now. Is that how you do it in JavaScript?\u003C/p>\u003Cp>Speaker 1: Your guess is as good as mine, sir.\u003C/p>\u003Cp>Speaker 0: Yeah. New date dot now. Cool. But it didn't work. So as much as this is cool, what happened here?\u003C/p>\u003Cp>We updated it. We updated it with the key. Oh, do you wanna know what didn't happen? It isn't showing here that we had a payload. So I think there was an issue with the payload.\u003C/p>\u003Cp>Oh, look, the payload didn't save. Interesting. So I'm just gonna double check that that is what happened there. If I hit save and then step back in, maybe it shouldn't let me do that, but this is okay. We're not gonna lose much sleep over it.\u003C/p>\u003Cp>Finished is going to be, no, last dot finished. Then we had, win is going to be last dot win. We'll wrap that in quotes too. What was the third one? What what are\u003C/p>\u003Cp>Speaker 1: the 2 that we have now?\u003C/p>\u003Cp>Speaker 0: Win, turn Yeah. Turns. I believe. Like\u003C/p>\u003Cp>Speaker 1: a living rubber duck.\u003C/p>\u003Cp>Speaker 0: Last stop turns. Turns. I'll hit save before we, you know, spend time on a full snake. We'll take a look. Turns and win.\u003C/p>\u003Cp>Turns and win. And now we have finished. Turns, win, finished. Turns, win, finished. Great.\u003C/p>\u003Cp>So let's save all of that. Let's create a rematch. We should see, hopefully, that this is stored. And then I don't think we're gonna spend much more time capturing data. Instead, we'll run a few games, and then we'll try some insights.\u003C/p>\u003Cp>Nothing's happening still. So still something done in our logic. Let's look at our latest I'll just refresh it. Let's look at our latest log. Oh, intermediate value dot now is not a function.\u003C/p>\u003Cp>I actually know why this is the case, and it is because, these run script operations running what are known as JavaScript isolates, which are these incredibly limited JavaScript like runtimes that only contain pure JavaScript objects. Let's actually take a quick look at that because I think it's interesting. Isolut. Yeah. This page looks legit.\u003C/p>\u003Cp>That's not what I want. I do kinda wanna show you like pure Java script or, objects. This is what I'm looking for. What I'm looking for is just like, where is the list? Am I am I what's happening?\u003C/p>\u003Cp>You might\u003C/p>\u003Cp>Speaker 1: be imagining. You might be imagining this. You may have already used JavaScript.\u003C/p>\u003Cp>Speaker 0: I just I have imagined it.\u003C/p>\u003Cp>Speaker 1: Created it. Maybe you created. There's no documentation. What did you call them again? Isolates.\u003C/p>\u003Cp>Isolates. Interesting. I've never\u003C/p>\u003Cp>Speaker 0: heard of that. Isolates.\u003C/p>\u003Cp>Speaker 1: And now is that just a security thing within Directus to ensure that, like, bad actors\u003C/p>\u003Cp>Speaker 0: So this So this actually happened in version 10.6. We had I think this is quite what I want. We had prior to version 10.6, you could build, you could use NPM modules inside of extensions. Extensions. Well, video has gone a bit funny.\u003C/p>\u003Cp>I'm not sure if the is fine now. It resolved itself. Anyway, and the library which we use to isolate flows from each other and operations from each other basically became insecure. Like, it was it was became known it was insecure, and so we had to remove it. And in doing that, we replaced it.\u003C/p>\u003Cp>And now it now it runs what are known as isolates. And this is what I'm looking for, I think. 1st class. Nope. I'm looking for oh god.\u003C/p>\u003Cp>It's really bothering me, but I will take a moment to find it. What's is it in our docs? In breaking changes 10.6, we dropped support for custom npm modules in the run script operation. Prior to this release, directors relied on VM 2 to run codes in the run script operations and flows. VM 2 is now unmaintained with a critical security issue that could potentially allow for code to escape the sandbox and access the machine, which hosts directors.\u003C/p>\u003Cp>So we've migrated to isolated VM to allow flows to run safely. This basically means you can't use just arbitrary NPM packages in flows anymore. You can still turn them into custom operations, but it isn't isn't here anyway. I learned a lot in during the process of this. There are lots of things you use in JavaScript, which you think are part of JavaScript, things like set interval, things like console log, set time out, fetch, that you just think, oh, this is part of JavaScript, but it's not part of JavaScript.\u003C/p>\u003Cp>It's either part of the browser's implementation of JavaScript or Node JS' implementation of JavaScript, many of which are shared. Isolates don't have this. Isolates just have pure JavaScript functionality. And the I I what I was trying to find was the list of what that meant. I've I can't find the word off the top of my standard objects.\u003C/p>\u003Cp>Boom. Found it. Thank you. So this chapter documents all of JavaScript standard built in objects. So you have access to global this infinity, not a number undefined.\u003C/p>\u003Cp>You have these function properties only. You have some fundamental objects like object function, Boolean symbol, a few error objects, a few number and dates, a couple of text processing functions, a few on arrays, key collection structured data and so on. What you'll notice here is a lack of console logs. What you'll notice here is a lack of date, which is what I was which is what I was going for there. We're not gonna lose any sleep over this.\u003C/p>\u003Cp>I'm literally just gonna we'll remove finished. It just isn't worth the time right now. You know, I do like it though. I wonder if can I add can I add after the fact a date created? Or did that have to be done at the time of Based on my I think it might have had to be done at Yeah.\u003C/p>\u003Cp>I just scroll down. Though. Exactly. And then just flip it over. I'm just taking a look.\u003C/p>\u003Cp>There's a sort field, which is great. That's okay. Take a little take a little cheeky screenshot of this so I can refer back to it. There we go. I'll put that off at the site, and then we'll delete this collection.\u003C/p>\u003Cp>I there might be a way to do it, but I I don't have the the patience. If I see But what I want is date created because I think that would be interesting. That's all. I just wanted that one extra field. So half width.\u003C/p>\u003Cp>So we also had in here a win, which was a boolean. We had turns, which was an int. We had snakes, which was account. It was a number. It was also an int.\u003C/p>\u003Cp>And we had finished, which we've effectively replaced with a date created. So half, half, and whatever. Half. Okay. So but but so they run-in isolates.\u003C/p>\u003Cp>And isolates what it taught me was all these creature comforts I have in JavaScript are not in JavaScript, they're in Node. Js or they're in the browser implementation of JavaScript. But, yeah, that's how I basically learned that.\u003C/p>\u003Cp>Speaker 1: There you go. I had no idea. I had no idea console log was not built into JavaScript. That seems so odd. But I guess the console you're dealing with is in the browser, so it does make sense.\u003C/p>\u003Cp>Speaker 0: Yeah. Let's create a new game. Let's create a rematch, see if we can get it to work. But, yeah, just fascinating. Yeah.\u003C/p>\u003Cp>Isolates. And isolates are not, you know, while that's running, isolates Cloudflare. I wanna say Cloudflare Workers. Yeah. Here.\u003C/p>\u003Cp>They have some really good reference while I was learning more about it. Isolates. VA orchestrates isolates, lightweight context, provide your code with variables that can access in a safe environment to be executed within. You could even consider an isolate a sandbox for your function to run-in. A single runtime can run hundreds of thousands of isolates switching between them.\u003C/p>\u003Cp>And isolates memory is completely isolated, so each piece of code is protected from other untrusted and user written code in the runtime. Islets are also designed to start very quickly. Instead of creating a virtual machine for each function, ISIT is created within an existing environment, blah, blah, blah, blah, blah. So but what's interesting is they are they are way more limited.\u003C/p>\u003Cp>Speaker 1: Yep.\u003C/p>\u003Cp>Speaker 0: Yeah.\u003C/p>\u003Cp>Speaker 1: I wondered I wondered why because I I think what did I I was reading yeah. I've been reading through the documentation, and it said that the the specific JavaScript that you were able to call within within lots of these areas, the directives were limited. And I was like, oh, that's that's an interesting and I figured it was security, but I didn't realize there was so much to learn here. But that is why you come here to Ready, Set, Battlesnake is to learn things about Battlesnake and JavaScript and directives.\u003C/p>\u003Cp>Speaker 0: And it worked.\u003C/p>\u003Cp>Speaker 1: And it worked. Let's go.\u003C/p>\u003Cp>Speaker 0: And it worked.\u003C/p>\u003Cp>Speaker 1: We did it.\u003C/p>\u003Cp>Speaker 0: So what we're gonna do now really is we're gonna just hit create rematch. And if I can I create loads of games in in, like like Yeah? Yeah.\u003C/p>\u003Cp>Speaker 1: Yeah. It's gonna break things.\u003C/p>\u003Cp>Speaker 0: We we we have also not built just a moment. We have not built logic to know which game is happening. We'll do one at a time. Top of them, we have. We have.\u003C/p>\u003Cp>We have. Because every turn is individual on the move endpoint. And then on the start and end, we're referring to the IDs. Actually, we could be running a load of these in parallel.\u003C/p>\u003Cp>Speaker 1: Alright. So give it a try. Let's see what happens. See what happens.\u003C/p>\u003Cp>Speaker 0: What's the worst that could happen?\u003C/p>\u003Cp>Speaker 1: We end up having to pause our episode because we made a mistake and we have to fix it off camera. That is the really the worst that could happen.\u003C/p>\u003Cp>Speaker 0: Oh, I am a bit concerned now because I don't even know when they've completed. That's another problem is I actually don't know when they I've taken a a guess that they won't take longer than each other. Like, alright, that game's over. I mean, let's just see. There you go.\u003C/p>\u003Cp>We're not winning every time. We have a number of turns. We have a number of snakes. Let's, let's just create a few more games. Like, I I want a a reasonable set to start with.\u003C/p>\u003Cp>All of them are gonna start with 2 snakes. Go on.\u003C/p>\u003Cp>Speaker 1: I was gonna say just so if you, like, if you're if you're watching this and you're like, oh, I don't wanna have to, like, do this. It's it's causing my browser. I don't like all those tabs. You can, like, do all this from the CLI too. Like, you can actually go in and just, like, continually create games for the CLI.\u003C/p>\u003Cp>This is just easier than going in and setting up the CLI right now.\u003C/p>\u003Cp>Speaker 0: And I don't wanna set up the CLI in this moment. So we should actually know if any games are outstanding because, yes, see, there's no turns and no wins on this one, which tells us that game is pending and now it has concluded. So, actually, we do have a little indication of how games are going.\u003C/p>\u003Cp>Speaker 1: Look at us.\u003C/p>\u003Cp>Speaker 0: So we'll create a few more games with a mixed player count. Okay. And if we refresh Directus, we should see okay, there are a few games still pending completion. If I refresh, 2 games pending completion, refresh 1 game pending completion, refresh. That game is still going.\u003C/p>\u003Cp>That game is still going. That game is still going.\u003C/p>\u003Cp>Speaker 1: Oh, still going. We're doing well.\u003C/p>\u003Cp>Speaker 0: Is that is that the last one we created?\u003C/p>\u003Cp>Speaker 1: I mean, we'll find out. It must be. I hope it is.\u003C/p>\u003Cp>Speaker 0: Descending. Oh, they've all concluded now. Okay. I think that's good to start. So Yeah.\u003C/p>\u003Cp>Let's go to insights, see see what we can do. Snake battle station. Let's pick a little kiss. Pick wonderful. Pick a little thing here.\u003C/p>\u003Cp>Is there a I don't is there like a snake? No? Is there is I don't want this game. Yeah. Cool.\u003C/p>\u003Cp>And our battlesnake. You know, do you wanna know why green feels like a very snaky color to me?\u003C/p>\u003Cp>Speaker 1: It does. Save. That is\u003C/p>\u003Cp>Speaker 0: the right one. Snake battle station. So this is, director's insights. It's this little module over here. And here, we can create dashboards.\u003C/p>\u003Cp>I don't really use it very much personally, just because my use cases don't demand many dashboards. So there might be a little bit of learning here. You can create panels. Just as a note, this is panels also an extension type. So if you wanna, you know, build on top of these panels, you know, build additional panels, you're more than welcome to.\u003C/p>\u003Cp>For this, I think we're going to stick in here. You know, we have the pie or donut chart, which feels like a good starting point. So we're gonna look at exactly what I had in mind. So win, Win. Count.\u003C/p>\u003Cp>Sure. Don't care about donut. That's just a display thing. Show labels. Yes, please.\u003C/p>\u003Cp>Show legend. Yeah. Pro oh, do you wanna know what? Let let's just see what happens here. Can because I think we can do conditional styles as well.\u003C/p>\u003Cp>So win rate. Okay.\u003C/p>\u003Cp>Speaker 1: Hey. Dang. That was I don't wanna say that was too easy, but that was very smooth.\u003C/p>\u003Cp>Speaker 0: Yeah. Although I we do need a legend. We do need a legend quite desperately.\u003C/p>\u003Cp>Speaker 1: I would just always assume the the bigger one is my win rate. That's really\u003C/p>\u003Cp>Speaker 0: It it you you are correct. Alright. Win rate win no. Win rate feels good. We can do, games, you know, we could do, the x axis is this one.\u003C/p>\u003Cp>Right? So date created maybe and turns, like how well am I doing over time.\u003C/p>\u003Cp>Speaker 1: Yeah. Yeah. I like it.\u003C/p>\u003Cp>Speaker 0: Aggregation. I don't really know what I'm doing here.\u003C/p>\u003Cp>Speaker 1: Well, okay. Just leave it leave it without aggregation and see what happens.\u003C/p>\u003Cp>Speaker 0: Yeah. Sure. And we'll call this one what are we doing here? Turns. Turns feels like a weird one.\u003C/p>\u003Cp>Maybe we just do turns feels weird. Why don't we do, like, account? Because I think what it will do, that's tell\u003C/p>\u003Cp>Speaker 1: us the number of games. Sure. Let's find out. Right?\u003C/p>\u003Cp>Speaker 0: Right. Games over time. Of course, we'll be looking at a very micro Woah. I'm not sure this is gonna pan out. This totally is not correct.\u003C/p>\u003Cp>Okay. Something. We did a bad thing. Aggregation can be forced as well. Right?\u003C/p>\u003Cp>Speaker 1: Can you? Well, set it as false to see what happens. See what that change does. Oh, didn't like that. We are not doing that.\u003C/p>\u003Cp>I guess we do need to have Oh,\u003C/p>\u003Cp>Speaker 0: aggregation is gone. Okay. So we have turns. We have snakes, we have x axis, which is date created. Do we need something on both axis?\u003C/p>\u003Cp>I'm sure. Do we? Oh, maybe not. I mean, it kind of looks like we do. I mean, I'm kind of as you can tell, I really don't make a lot of dashboards because, you know, it's just not it's just not my world.\u003C/p>\u003Cp>Maybe if we let's let's let's, see what else we can do. We have I like metric firstly, which is like total games played. That one feels easy.\u003C/p>\u003Cp>Speaker 1: Yeah. That's simple.\u003C/p>\u003Cp>Speaker 0: Aggregate function, just count. Count. Yep. And, suffix, Games played. Star decimal unit.\u003C/p>\u003Cp>Notations standard. Yeah. Yeah.\u003C/p>\u003Cp>Speaker 1: Oh. Uh-oh. GraphQL validation error?\u003C/p>\u003Cp>Speaker 0: I think I'm just not I'm genuinely thinking I'm just not selecting enough field. Do we need to do a field ID? Yeah. We did. Oh, there we go.\u003C/p>\u003Cp>15, 15 groups load. Nice. Sure. Okay. It's not pleasing my eyes very much that, but let's, keep taking a look.\u003C/p>\u003Cp>Speaker 1: Yeah. What do we have still?\u003C/p>\u003Cp>Speaker 0: Font size auto, which makes sense, or you can make it fixed and then you can add padding accordingly. I do get the auto. Auto makes a ton of sense. We have a line chart. We have time series.\u003C/p>\u003Cp>So the collection, once again, games, the group aggregation, oh, group precision minute because we set a few games off at the same time. Count, date field, date created, date range, past 15 minutes. Sure. Value field. I, turns.\u003C/p>\u003Cp>Snakes. Oh, I don't know. I mean, can I edit can I can I oh, there it was? Can I clear the value, please? I'm just gonna hit tick.\u003C/p>\u003Cp>Alright. Didn't do anything. I've picked I've picked the wrong combination of picked the wrong\u003C/p>\u003Cp>Speaker 1: combination of options. We almost we almost did it.\u003C/p>\u003Cp>Speaker 0: Did you see how confident I went in?\u003C/p>\u003Cp>Speaker 1: You went in. Listen, confidence is half the game here. We just gotta go in thinking you know what you're doing and, eventually,\u003C/p>\u003Cp>Speaker 0: you know I'm not really sure. I'm not really showing this bit of director stuff pretty well.\u003C/p>\u003Cp>Speaker 1: No. I think it's I think you're doing this fantastic. I like that we've been able to get stuff like we so it's because I said it was so smooth. Hey. There we go.\u003C/p>\u003Cp>Nice. And these are showing us?\u003C/p>\u003Cp>Speaker 0: So this is showing us the number of turns taken on a minutely basis. And that was where I set loads of games off, and this was just as it was coming down from the last data point that was held. If I do it the past 30 minutes, I think I'll get a slightly oh, maybe not.\u003C/p>\u003Cp>Speaker 1: It's a good try.\u003C/p>\u003Cp>Speaker 0: Yeah. This is oh, here we are. Automatic based on data. That feels good. Okay.\u003C/p>\u003Cp>So 80 turns over here and then 320 turns over here. And then if we create a couple more games now, we'll create a game.\u003C/p>\u003Cp>Speaker 1: Yeah. And I do like this. Like, if you were actually looking at this over a period of time, this would make a lot more sense.\u003C/p>\u003Cp>Speaker 0: Could be really insightful. Yeah. So let me just save that, and we'll just make sure. Oh, thank you. Woah.\u003C/p>\u003Cp>Last game has not concluded yet, so we'll just let that conclude. Okay. So if we go back to insights now, there you go. It's a little bit more of a of a view. Right?\u003C/p>\u003Cp>So I don't really wanna look at the number of turns though. I wanna look at is it count? I think that will give us the same graph. Yeah. What I want is I just wanna know how many there are.\u003C/p>\u003Cp>Speaker 1: How many games?\u003C/p>\u003Cp>Speaker 0: How many how many games? Do you think turns is interesting?\u003C/p>\u003Cp>Speaker 1: I no. I mean, I think let's I so turns is interesting, but only if you're playing 1 at a time.\u003C/p>\u003Cp>Speaker 0: Exactly. And I think I think I think there's a way to do that. I've seen other people do it. So we had I think it might this global variable variable key can be like game. Confidence.\u003C/p>\u003Cp>Speaker 1: Lots of confidence.\u003C/p>\u003Cp>Speaker 0: Game interface. That's not what I want. Type. Is it in here? No.\u003C/p>\u003Cp>I've seen it. I've seen it somewhere else. Is it maybe called global relational and you pick a collection, you pick games, display template? Yes. You find the ID.\u003C/p>\u003Cp>I think this is it. So you select a game. So it says select an item. So can I, whatever? But we we won't look at editing that.\u003C/p>\u003Cp>So you select a game, right, like this. Great. And then you can use that global variable in all of the other boards Okay. In all of the other panels. So if I you know, maybe we do this.\u003C/p>\u003Cp>This is like global values up here. Great. And then we have this, you know, dynamic portion. So what do we want to know here? Well, we want to know I I don't know.\u003C/p>\u003Cp>Like, what about are we doing we're not doing per turns. We're not storing turns too. Maybe we just do what do you think?\u003C/p>\u003Cp>Speaker 1: There's only one other thing that I thought would be really fun, but I think that the logic is gonna take too long. No. And it I mean, not gonna be related to this panel. I think it's I I'd be very interested to pull in some custom that that the the actual gift for the game. I think there's something interesting there to be able to pull in.\u003C/p>\u003Cp>Speaker 0: I think we could do that. I think we could do that. Yeah.\u003C/p>\u003Cp>Speaker 1: That's an ambitious it's an ambitious goal. You wanna try?\u003C/p>\u003Cp>Speaker 0: Yeah. Go on then. Right. Tell me how to get the tell me how to get the URL. Go to your game.\u003C/p>\u003Cp>I'm I'm going. Got it. Alright. Go to view\u003C/p>\u003Cp>Speaker 1: as GIF, and then it'll give you the format\u003C/p>\u003Cp>Speaker 0: that you I will only click it when you say it correctly.\u003C/p>\u003Cp>Speaker 1: GIF\u003C/p>\u003Cp>Speaker 0: GIF. You may. GIF. Okay. And there's a URL and that's the game ID.\u003C/p>\u003Cp>Speaker 1: Grab that,\u003C/p>\u003Cp>Speaker 0: And that's that ID is movable. Right? Like, that ID is the ID of the game.\u003C/p>\u003Cp>Speaker 1: So\u003C/p>\u003Cp>Speaker 0: you can buy back\u003C/p>\u003Cp>Speaker 1: and game by game.\u003C/p>\u003Cp>Speaker 0: Yeah. So let's try our hand.\u003C/p>\u003Cp>Speaker 1: We need to do a custom panel.\u003C/p>\u003Cp>Speaker 0: That is that is definitely what we need to do. Yeah. But, right. So what are we gonna do here? We're gonna go up one layer.\u003C/p>\u003Cp>We're gonna go MPX create directus extension at latest. Whoops. Extension. Helps when you type it correctly. Right.\u003C/p>\u003Cp>What we're gonna do, we are oh, you're you're putting me on the spot here. I'm not overly confident. And viewers, if we don't get it done, we're not gonna get it done. But let's call let's consider this a stretch goal. I also haven't used these global variable values too, too much.\u003C/p>\u003Cp>While that's kind of doing its thing whoops. Docs, Data Studio app. I think it might be over in the user guide, insights, panels, global relational value here. Oh, and then in other in other, ones, you can use the variable key like in other panels. That's interesting.\u003C/p>\u003Cp>Anyway, we want a panel, director's extension, snake panel. JavaScript install dependencies. Okeydokey.\u003C/p>\u003Cp>Speaker 1: I'm glad I gave you this challenge, and I am not the one having to implement it. This seems right. This seems good.\u003C/p>\u003Cp>Speaker 0: It all seems good with the world. Alright. So we have the panel here. We have our panel dot view. It has been a while since I built an extension.\u003C/p>\u003Cp>So here we have all of the configs. We'll call this snake GIF snake GIF. Sure. We could do loads of configuration. We're not gonna do that.\u003C/p>\u003Cp>First thing we're gonna test is if we just have a if we just have a string like we manually insert it to start, can we can we play? Can we play it back? So in the panel, we have this text here, and I think all we would need to do, there's a bit of an assumption in here, is we're gonna paste in this URL and we're going to interpolate here the text, right? That feels right?\u003C/p>\u003Cp>Speaker 1: It feels very good.\u003C/p>\u003Cp>Speaker 0: Npm run dev. Sorry. Npm. I'm I'm not even in the Npm run build. I wasn't right running the right command or in the right location.\u003C/p>\u003Cp>And then we will I think what I'll do is I'll can I hang on? Kinda wanna open them side by side. There we go. And then I wanna just kill that, restart it. Once again, fixed as of, like, yesterday's release.\u003C/p>\u003Cp>I just haven't got around to upgrading this one yet. Open up our panel, and I'm hoping snake GIF. Hey. We insert an ID here. Let's go get an ID.\u003C/p>\u003Cp>This one, 72 turns. And so I I can't believe it might actually why did I say that?\u003C/p>\u003Cp>Speaker 1: You've jinxed it now,\u003C/p>\u003Cp>Speaker 0: but it's okay. Here. Hit save. Okay. Save.\u003C/p>\u003Cp>Speaker 1: And\u003C/p>\u003Cp>Speaker 0: oh. Don't know, mate.\u003C/p>\u003Cp>Speaker 1: Happening. Oh,\u003C/p>\u003Cp>Speaker 0: I have my dev tools kind of detached. Content security policy.\u003C/p>\u003Cp>Speaker 1: So this might actually be cross it might be course with the dev side\u003C/p>\u003Cp>Speaker 0: platform. Which is which is, the ilk of what this is. How do I solve it? How do I solve it? It's a GIF.\u003C/p>\u003Cp>It's a GIF at a location. Can we import it maybe? Can we import it? And then how would we import it? Let's take care of let's let's consult the docs.\u003C/p>\u003Cp>So we have in here extensions, developing extensions, extension services, accessing files, import a file. This is inside of an API extension how we would import a file. We would instantiate a file service. We have an asset key, which has the URL and a file object, which contains additional metadata, and then we read it in order to to return it. Excuse me.\u003C/p>\u003Cp>So let's have a think about the right way to play this. We could press a button. It'll import it and then play it back. It's a good idea. Let's try\u003C/p>\u003Cp>Speaker 1: that. That seems easy. Let's\u003C/p>\u003Cp>Speaker 0: try that.\u003C/p>\u003Cp>Speaker 1: I say this. I say this.\u003C/p>\u003Cp>Speaker 0: Easy as a That sounds easy. That sounds easy.\u003C/p>\u003Cp>Speaker 1: Kevin problem. Sounds like an Android watch, and Kevin solves this tactical challenge.\u003C/p>\u003Cp>Speaker 0: Alright. Alright. Alright. So let's just keep this easy for a moment. Let's let's stitch this off, and let's create a new bundle.\u003C/p>\u003Cp>And I'll call this one directus extension, and I'll just call it, Battlesnake Viewer and install dependencies. So that's creating a bundle. In that bundle, we'll have an endpoint and we will have, and we'll have an endpoint and a and a panel. So we'll CD into the battlesnake viewer, and we'll go npm run add. And the first thing we'll add is actually the endpoint.\u003C/p>\u003Cp>We can just call this one importer. JavaScript. And now inside of Battlesnake Viewer, source importer index dot j. So this is again, our custom route as mentioned earlier. Now inside of our existing one, we've actually got this is snake GIF.\u003C/p>\u003Cp>We have our actual snake here. We're gonna we're gonna just kind of nab this structure for a moment, inside of the importer here. We'll remove these actual things here, like so. Okay. So we'll call this one importer.\u003C/p>\u003Cp>Right. So when we hit importer, what we're gonna do, and we're gonna do a post request here, is we are going to access files. I'm gonna copy all of this. Here. We'll see what we can do.\u003C/p>\u003Cp>Oops. Okay. Router dot post. We will create a files service. Now I actually think, the docs do talk about importing that.\u003C/p>\u003Cp>So let's just take a little look at the top here. Yes. Okay. So in the endpoint itself, we have a router and a context. Awesome.\u003C/p>\u003Cp>Let's do a let's do a little more side by side jobby here. Right. So we have router and we have context. And up here, we're going to grab these values out. Then inside of router.post/cool, we will create a new file service.\u003C/p>\u003Cp>We will look at rec. So file.url is going to be req.body. URL. Cool. And the file object itself, how much of this must we pass?\u003C/p>\u003Cp>Let's look at the file object. API reference files. File object looks like this. How much of this must we pass? I don't think any.\u003C/p>\u003Cp>I don't think we need any of this. So I think we'll remove that. So we have our URL. Then we will import it. It will come back.\u003C/p>\u003Cp>We will then have the asset key, and we'll return the data. So if all goes well, npm run build, This is our importer, docker compose up. And I think what we wanna do here is test whether this endpoint works. Now I still have ngrok running. I don't still have it running.\u003C/p>\u003Cp>I've been running it since the beginning of this, this session. And I have hopscotch here, which is similar to Postman. It's just like an HTTP Explorer. So here, if I go importer post and inside of the let's just hit send there. Okay.\u003C/p>\u003Cp>Timing out, timing out, timing out. There is an error, invalid URL, input object object. Okay. Let's just cancel that. Let's set a body.\u003C/p>\u003Cp>Let's set this to be application JSON. There we are. And what we want in here is a URL of and then this exporter battle sync. So hopefully this will return the ID of a new item in our directors project. Okay?\u003C/p>\u003Cp>It's still going. So not feeling good about that. Invalid URL. Is it, though?\u003C/p>\u003Cp>Speaker 1: Is it? Apparent I mean, no.\u003C/p>\u003Cp>Speaker 0: No. No. Object object. Import 1. So it was struggling with import 1.\u003C/p>\u003Cp>So let's let's take another look at this. So it was struggling here with the file service dot import 1. Req dot body dot URL. Now to be fair, we never once took a moment to check whether it was gonna be req dot body. So let's just res.sendokay for a moment and that's console.log req.body.\u003C/p>\u003Cp>There was a bit of an assumption in there. So we will rebuild that and then we will restart that. Okay. And we will send that and we should hopefully get an okay back. We did.\u003C/p>\u003Cp>So let's take a look. So inside of req.body, yeah, dot URL. What's going on? Is this a URL we can hit? Oops.\u003C/p>\u003Cp>Yeah. Should be. Yeah. Sure. And let's just test that there's nothing funny going on with, like, access here.\u003C/p>\u003Cp>If I go to our file library and import, this is the RF for importing and hit import. The GIF is there. So there is nothing wrong with that. So we're just doing that via API instead. So fair enough.\u003C/p>\u003Cp>Fair enough. So we have the URL. We have some accountability, which I think we might just be able to bundle some\u003C/p>\u003Cp>Speaker 1: for now.\u003C/p>\u003Cp>Speaker 0: Get rid of it for now. Let's do npm run build and restart the container. Go to hopscotch and send this.\u003C/p>\u003Cp>Speaker 1: Okay. Great.\u003C/p>\u003Cp>Speaker 0: And this time, we've got a URL, which means there was nothing wrong. So let's just do one step at a time. That's console dot log the asset key. Yep. Rebuild.\u003C/p>\u003Cp>I'm determined to get this to work now.\u003C/p>\u003Cp>Speaker 1: We are gonna do it. We have we have the Cool. Technology.\u003C/p>\u003Cp>Speaker 0: We have the ability. That should still just return an okay, but it hasn't. Why? Code error invalid URL. It gives me it gives me it gives me the docs might not be right, which is possible.\u003C/p>\u003Cp>So as much as I wanna just be like, but that's what it says to do. Let's take a moment and let's actually, if we go to accessing if if let's find let's find the docs for this and let's just step through because all of the services are just in the code base. It's not my preferred way, of course, to be looking at stuff. Let's take let's take a little look. What we care about here is import 1, and it does expect an import URL and a body partial.\u003C/p>\u003Cp>So maybe maybe we did need to pass in, could not fetch from URL. The error said invalid URL out of interest. So maybe yeah. Because what it does is it grabs the raw file and then uploads it. Maybe we need to we must pass in this body.\u003C/p>\u003Cp>Just a thought. And that was the partial body objects. And maybe I mean, that's a partial body object. Maybe there's something else we must pass in this at the time of creation. Let's, let's hit send.\u003C/p>\u003Cp>Speaker 1: Come on. Okay. Okay. Okay.\u003C/p>\u003Cp>Speaker 0: In fact, again, it's taken that long. Yeah. No. Input object object code invalid URL. That invalid URL.\u003C/p>\u003Cp>Couldn't fetch file from URL object object. Isn't that interesting? Because the URL to me is a is a string. Right? Yep.\u003C/p>\u003Cp>And found that URL. But this time, before all of this, I logged service external file is unavailable. Couldn't fetch file from URL object object, but it isn't. It is a string, and this is the string. Fascinating.\u003C/p>\u003Cp>I mean, let let's just, you know, I've been a bit cheeky here. Maybe we, go back to accessing files, and I do actually create it with this accountability object here. Yep. I'll take that. I'm pretty sure I know it's not needed.\u003C/p>\u003Cp>I know it's not needed. But that the error isn't saying something else is missing. You've triggered an unhandled rejection. You may okay. Yeah.\u003C/p>\u003Cp>Fine. Okay. True. So if we go if we try around this, right, and then we catch an error. We console dot log the error.\u003C/p>\u003Cp>And we send this.\u003C/p>\u003Cp>Speaker 1: And\u003C/p>\u003Cp>Speaker 0: We are expecting an error, which is fine. We've got 503 service unavailable. Why? Couldn't fetch file from URL. This is what's troubling me.\u003C/p>\u003Cp>Object object. Let's take a let's just take another look here. So import 1. I think I worked it out.\u003C/p>\u003Cp>Speaker 1: No. That was quick. Goodness.\u003C/p>\u003Cp>Speaker 0: It is an opt I did pass in an object, didn't I? But that's not what's being passed in in the in the reference. The import URL is a string and the body, which is a partial file that should have been passed in as a string. All you need to do, Kevin, is read. Read the docs.\u003C/p>\u003Cp>So read\u003C/p>\u003Cp>Speaker 1: the There's another person here, and we still didn't get there.\u003C/p>\u003Cp>Speaker 0: Yeah. Okay. Asset key. We got an asset key that time. Success.\u003C/p>\u003Cp>There should now be a file in the file library. Right? Correct. So we are loading it in. We are loading it in.\u003C/p>\u003Cp>Title, description, tags, file name disk, all grand, but\u003C/p>\u003Cp>Speaker 1: Beautiful.\u003C/p>\u003Cp>Speaker 0: What we also want to do is this. We want to, YOLO. I can't be bothered with all this. We'll just there we are. We'll take the asset key, then we'll read the new asset, and we'll return the data.\u003C/p>\u003Cp>So what we'll get back in in response to this is it will always import. So that's not ideal because if it already exists, we don't necessarily want to reimport it every time. But for the sake of this little demo, I think it's fine. Then we'll get the ID back. So now if I rebuild this and we run this again oh, it was still spinning up.\u003C/p>\u003Cp>What we should get back is the new file object indeed, including the ID. And the nice thing about this is, if I go to access control, public, and I turn on directors files actually, I don't even need to do that. If I go to httpsphzedm.ngrok.io, right, slash assets slash ID will get a you don't have permission to access this error. Right? But what I can do is go to the user, generate a token.\u003C/p>\u003Cp>Speaker 1: Okay.\u003C/p>\u003Cp>Speaker 0: Generate the token, save it, and I pin that to the URL. Nice. Access token equals. And there's our Hey. Merge directly, which is pretty which is pretty cool.\u003C/p>\u003Cp>That's very cool. To keep this easier, though, I'm actually going to change the permissions of the files collection. So then you net we never need to pass in, pass in the key. So public system collections, directors files, all access on. Great.\u003C/p>\u003Cp>So now that's public. So now we've done the endpoint. The job is to create the panel. So what we'll do here is npm run add.\u003C/p>\u003Cp>Speaker 1: That should be pretty easy, I think. I say that. That's a dangerous\u003C/p>\u003Cp>Speaker 0: Easy for you to say.\u003C/p>\u003Cp>Speaker 1: He does it. I know. It's very easy for I I think you've got this, Kevin. I trust I believe. I trust in Bodie.\u003C/p>\u003Cp>Next week, when I'm when I'm driving again, things are gonna go terribly awry, and you're just gonna kick back and and relax and\u003C/p>\u003Cp>Speaker 0: enjoy the experience. Oh, yeah. I know. Viewer. What did we call the previous attempt to an extension here?\u003C/p>\u003Cp>Snake GIF, find viewer, viewer. This is my custom panel. Now there is some text. Now what we need to do, I think what we'll do is we'll remove the options entirely, right, because we don't want any options. It'll be a standard panel.\u003C/p>\u003Cp>And inside of that panel, we are going to have button button. We no longer have text. That's not a prop that's being passed in anymore. We just deleted it. So what we'll do is we'll do a v button.\u003C/p>\u003Cp>No. We won't. We'll do a v let's talk about what all these v things are for a moment. Back in our docs here, back in our docs, we have, resources for building extensions, components. And we have this components playground.\u003C/p>\u003Cp>These are all of the directors components that are inside of the Data Studio are made available to extensions. So we have here v button, and this is the director's button inside of the director's app. So we we have an immediate availability of this v button component, which is, yeah, pretty, pretty nice. So we can access that straight away. So we can go v.\u003C/p>\u003Cp>I did just notice it was v button like this and we'll call this, not v. I keep going back to the button. Sorry. We're looking for\u003C/p>\u003Cp>Speaker 1: No. That was right.\u003C/p>\u003Cp>Speaker 0: No. Yeah. But we want the input because we want to put in the ID. Yes. Yes.\u003C/p>\u003Cp>Yes. Because we'll keep it easy. We'll we'll put, like, right now, manual ID of a game hit go\u003C/p>\u003Cp>Speaker 1: Yeah.\u003C/p>\u003Cp>Speaker 0: Rather than, Automating it. Yes. Pick pick it from a drop down because we're running we're running out of time. So v input to v model. So, what are we gonna do here?\u003C/p>\u003Cp>Export default. We're gonna do data return, and we'll call this ID. Like so. Then inside of here, we'll put in the v input with a model of ID. Then we'll say on key up dot enter fetch, game, GIF, get GIF, fetch, git.\u003C/p>\u003Cp>Cool. And we will add and this is not really an ideal way of of writing these, of course, but methods and we'll call this fetch GIF. Yeah. And we'll just console dot log or you know what? We'll alert with the this dot ID value.\u003C/p>\u003Cp>That's what we'll do for now just to test all of that works before we go too far. So we'll go in here. Oh, I need to sorry. Npm run build was the command there. Oh, error.\u003C/p>\u003Cp>Speaker 1: Come on. What are you doing, error?\u003C/p>\u003Cp>Speaker 0: What are you doing? After component panel component, we're missing a comma. Okay. NPM run build. Lovely.\u003C/p>\u003Cp>And we'll restart that. Also lovely. So let's refresh. Let's refresh. Just took a hot minute there.\u003C/p>\u003Cp>Insights. New panel. Viewer. No options available. Right?\u003C/p>\u003Cp>Because nothing happens to the panel itself. This, wonderful, is our panel and we'll say we'll save it. Hey, enter. Great. So this means we are able to do something with that.\u003C/p>\u003Cp>What we're gonna do with it is we're going to go back to our docs. We're gonna look at our composables for app extensions, which is what this is. I'm gonna just close out everything else for now. And we're gonna use API. And what this will do is it will allow us to make API calls, to our endpoints that are already authenticated.\u003C/p>\u003Cp>Though, to be fair, I believe this is a completely public endpoint, so it shouldn't matter much. But still, we'll do it as as it should be done. So what we're gonna do here is we are going to import use API. We are going to use this composable, like so, and then we can make our endpoints like and then we can make our calls like this. So we will make this async.\u003C/p>\u003Cp>And what we're gonna do is we're gonna post to slash importer/importer. And we have response dot data here. So all we're going to do is console dot log response dot data. Let's build. And this is all basically to get around that that security issue.\u003C/p>\u003Cp>Speaker 1: Yeah. That course issue. I love that there's always just like a 6 step workaround to deal with course. Thank you.\u003C/p>\u003Cp>Speaker 0: As opposed to just dealing with it head on. Yeah. So, we refreshed it. This is great. What's happened to my text box?\u003C/p>\u003Cp>What's happened to the text box? Is it no, but it's not. Where's my text box? Also, what's happened to this one? What's happening?\u003C/p>\u003Cp>Not seeing any errors. The API could not be found. Couldn't load extensions. Okeydokey. Have I missed a step?\u003C/p>\u003Cp>Have I rushed it again? Have I rushed a little bit? Oh, script setup. So we'll be using, we have to move this to script setup. And let's just take a quick look at how this I need to refactor this.\u003C/p>\u003Cp>Of course, we do, but that is fine. Async fetch GIF should just be able to, for the most part, come up here. We'll say, const fetch GIF equals a sync function like so. Then is that legit? Yeah.\u003C/p>\u003Cp>That is legit. And then so that's the methods. Then we have the data, which is the ID. So we will be import import ref from view. We'll create a new variable for that.\u003C/p>\u003Cp>We'll go const ID equals ref. Great. So we've handled that. Then we have props. And I believe the way to do props here is we say define props.\u003C/p>\u003Cp>Can we do this? I think we can do this. And all we care about here is show header, which to be honest, I do not care about. In theory, I've just refactored all of that. Let's take one more quick look, fetch GIF.\u003C/p>\u003Cp>So we have this dot ID. So we don't need that anymore. It'd be ID dot value, but we're not gonna alert it anyway. Kevin, watching\u003C/p>\u003Cp>Speaker 1: your work is just fantastic, by the way. I love that I gave you this challenge and, like, everything has gone wrong. Okay.\u003C/p>\u003Cp>Speaker 0: This is this is an Axios instance. I don't quite remember how it bloody works. So I think what we do here is we do, and I need to check, axios post. Oh, we do we literally just pass in the whole object as the second. Great.\u003C/p>\u003Cp>So in here, we're gonna do URL equals ID dot value. Okay. And then we have response dot data. Cool. So we'll console mock that.\u003C/p>\u003Cp>Alright. Let's rebuild that. Is it gonna complain this time? No, it bloody isn't. Docker Compose up.\u003C/p>\u003Cp>You give me a right workout here. Let's refresh, and we should now have access to use API. Now none of it's loading. Now it is. And there's our text box.\u003C/p>\u003Cp>Let's open up our dev tools. Of course, it didn't like the URL that was before. That was this panel here. Just testing that out. So in here Can I grab a screen?\u003C/p>\u003Cp>Pop it off at the side. Over here, yeah, we need a game ID. So we can do that here. Game ID. So we're not done yet because we're not gonna display it yet.\u003C/p>\u003Cp>If we hit enter, what's happened?\u003C/p>\u003Cp>Speaker 1: Refused refused to load the images.\u003C/p>\u003Cp>Speaker 0: No. No. No. That that's the old one. That's the old one.\u003C/p>\u003Cp>In fact, if I just remove that whole thing, we'll be better off for it. Let's refresh. See no errors. Let's paste that and let's hit enter. Nothing's happening.\u003C/p>\u003Cp>Why? Fetch GIF. Let's make sure this is ever running. You know what? This is all cute and all this.\u003C/p>\u003Cp>Let's just, just in case it's some silly async fetch gift, just in case it's some silly, async function, just in case it's something silly in the way that oh, I think it might have said invalid URL. I think it might. Do you wanna know why invalid URL? Because it isn't the full URL. We're just posting the ID.\u003C/p>\u003Cp>Oh, that's right. Yes. So what we'll do on the importer package is we're actually going to, we're gonna import req.body.url. Cool. So we're gonna make URL.\u003C/p>\u003Cp>Where is it? Here. Exported.battlesnake.comporter.battlesnake.games. And then here, req.body.idgamegame, maybe we call it. And in here, we pass in the earth.\u003C/p>\u003Cp>So now it needs a game. That's the value we need to pass going back to our panel. This is going to be game ID dot value. Let's rebuild the extension. Okay.\u003C/p>\u003Cp>Oh, yeah. We'll refresh. I do understand our network error showing there. Now we'll paste in the ID of the game. We'll hit enter.\u003C/p>\u003Cp>Oh, you know what we didn't do? We didn't open up dev tools. Let's skip to console. Wicked. Okay.\u003C/p>\u003Cp>We now have an ID of a directus I like, a directus asset in the ID. So all we need is the ID here. So this is the ID of the game, game ID, game ID, and then an image in here and the source of that image is going to be, how is this going to work? We need to just have a quick think about this. I'm gonna try something out.\u003C/p>\u003Cp>I think if we go /assets slash and then we need a value in here. So in here, we're gonna go image ID, and it's gonna be a ref and image ID dot value equals response dot data dot ID. Right? So Yep. Now this has the value in it of the ID, image ID.\u003C/p>\u003Cp>First thing we'll do here is just a quick v if image ID. We only wanna show it when that's the ID, and then here is going to be image ID. Let's see if that works. I'm not a 100% sure it will, but should do.\u003C/p>\u003Cp>Speaker 1: I have faith oh, yep. There we go.\u003C/p>\u003Cp>Speaker 0: I don't. Let's refresh.\u003C/p>\u003Cp>Speaker 1: 1 of us has got 2.\u003C/p>\u003Cp>Speaker 0: Great. ID is not defined. Why? Because ID dot value is gonna be game ID dot value. I'm feeling the heat, but I'm having a blast.\u003C/p>\u003Cp>Speaker 1: I know. I was gonna say I feel like I gave you, like, the small challenge that became the much larger Yeah.\u003C/p>\u003Cp>Speaker 0: But not not 145 in or whenever it was. That's not really the time to do it. But if we wait just a moment, nothing happens. Why? Console.\u003C/p>\u003Cp>Assets undefined 4 3. Fine. Let's figure out oh, image ID. Complete typo there.\u003C/p>\u003Cp>Speaker 1: Remember this, Kevin. Remember this as the challenge comes next week.\u003C/p>\u003Cp>Speaker 0: I'm having I'm having a blast. I really enjoyed last week, last episode. And now\u003C/p>\u003Cp>Speaker 1: we have Hey. What is I? Kevin. Kevin. Kevin.\u003C/p>\u003Cp>Kevin.\u003C/p>\u003Cp>Speaker 0: In an ideal world, you can obviously select from your existing games. It will handle all the logic for you. I think we're firmly out of time to do that this time around. Next time we and next time we won't be touching insights. But everyone, I hope you've had a wicked time.\u003C/p>\u003Cp>Any final remarks, Andrew?\u003C/p>\u003Cp>Speaker 1: Thank you, Kevin, for taking on the challenge. Thank you all for watching. And be sure to tune in for our next episode of\u003C/p>\u003Cp>Speaker 0: Ready.\u003C/p>\u003Cp>Speaker 1: Ready. Set. Set. Battlesnake. Battlesnake.\u003C/p>\u003Cp>Speaker 0: Nat, when you edit this, can you just time it so we get that right? Thank you. Bye.\u003C/p>","Hello? Oh, were were you waiting to do the thing? Alright. We can I got you excited? I got you excited. Hello, and welcome to ready Ready. Set. Battlesnake. We are running out of time to nail it, and I I have to be honest. My my, my confidence is starting to wane that we're gonna get it. But hello, everyone. Welcome to episode 3 of 4 for Ready, Set, Battlesnake. My name is Kevin. I work at Directus and My name is Andrew, and I work at Devcycle. Absolutely. And today, we're gonna pick up right where we left off in building a Battlesnake with, Directus and in the next episode with Devcycle. We've both been involved in the Battlesnake project for some time in various ilks. And honestly, we're we're just having a great time, if I may if I may talk for us both. I'm with you. I think this has just been so fun. I haven't dug into Battlesnake in such a long time that this was such an awesome thing to come back into, especially oh, look at that. My light turned off. Especially after, especially after just getting into the the nitty gritty of Directus over the past, like, couple months, getting ready to build some of this stuff out. So, yeah, this has just been it's been so much fun, and I'm excited that we're only halfway through right now. Like, we've got 2 full sessions left, and I think it's gonna be amazing. So am I. So let's recap where we were at just at a high level. So we have a local directors instance running. Inside of that instance, we have a custom endpoint extension. We have a custom endpoint extension because we need to know with confidence that, a snake can exist having a root endpoint and a slash move endpoint at the very least. And the webhook, the webhook triggers for flows can't guarantee that you get a random URL and we need we need both of those relative past. So we created an endpoint and all the endpoint does is it fires off this flow. There's one for the info of our snake here, which gives the information about our snake. Is the font size okay? I can bump it up if necessary. It's okay. I mean, bump it up a little bit. I feel like it's not bad for folks that are watching. Yeah. Yeah. It's good. Yeah. Yeah. Yeah. Yeah. And then our move endpoint, which is what we spent most of our time working on in the last episode. So request comes in with a full board state. We set up some global information from that state. We grab is move safe, up, down, left, right, or true. We grab snakes, board width, board height, my head, and you kind of all of these conveniences. Then we run avoid walls, and we see whether whether the wall's gonna be hit. But what you'll notice is at the top is that we pull in is move safe. We do all the work to it and then all we do is return is move safe. So we're moving this object down the chain kind of manipulating it at each step because that's ultimately all we need. We avoid the walls. We avoid all bodies of all snakes once again, starting with is move safe, ending with is move safe. Then we avoid head to head. This is what we spent most of last session doing once we got the flow running. It might not be the most elegant, but what we do is we look one space around every snake that isn't us, and we avoid those spaces too. Once again, we start with this move safe coming in, and we end with this move safe going out. And finally I love we determine I love that you're saying this is not elegant, Kevin. Like, this is like yours is so much more elegant than mine. As you're gonna find out next week when I jump back in, week 1 week 4 are Andrew, learn learn with Andrew. Specials. Andrew specials. Exactly. So this is such clean code. I love it. Oh, well, thank you very much. I'm sure some of our viewers will disagree and I won't stop them. And then and then finally, we grab that array of is move safe. We basically just pick 1 at random that is still available and we return that as an object move next move, which is either up, down, left or right, and we continue on. And so in this episode, I think we were going to start playing around with not necessarily adding more logic to the snake. I think it's a pretty robust snake right now, but instead, we're gonna start saving game data to this director's project, and then perhaps we'll do something with the insights module. How does that sound? That sounds fantastic, Kevin. That sounds like a great way to spend an afternoon for me slash Wonderful. And afternoon, no? It is now but I realized that people are watching this from everywhere. So maybe it's from morning. Everywhere. Technically, it's it's, we've got afternoon for me, evening for Kevin, and morning for one of our wonderful viewers out. I'm sure somebody is more important for you. Good good morning from 9:30 at night. Okay. So so so I've already had to think about how how this should probably shape up, which is this return move this return move operation here does some work, right? It picks the move and then it returns it. I think we should decouple these. So we should do one final step which picks a move and then the final step which just returns the move. And then we can put in like an inter we could put in one additional operation in which will store data in a database. I think that's probably the, you know, we have to decouple it and then we can we can take in the entire board state from the trigger, store that and we can store the move that we ended up concluding before we send it on. That's that's what I think we should probably do. There is a question of what we want to store. You know, we also have this additional start and end move point. I think end always returns the final state of the board. So there's something to be to be said about that as well. Yeah. What do we what do we want to store? Maybe we start with we we just store the the move. Like, we start really simple. We just say what is the final move we chose? Yeah. I think that's probably easy number 1. I was also gonna say we could record win or loss, like, if we wanna go really simple. But technically, I think move is probably simpler because then otherwise, we're gonna have to parse through the JSON data that we get back. So yeah. Let's do let's do move and then maybe, like status of the game and, and then go from there. Interesting. Let's just let's just go till we can't go anymore. Now just as a note, there is a limitation that we have to work within with directors. Now we actually just did a different directors TV episode on this. It was request review, filtering JSON objects, I think it was called. But, basically, if we store a JSON blob inside of a field in directors, we can't filter inside of that blob. It is just a string. So what we'll need to do is extract specific values and store those as individual values if we want to use them for insights. We just have to be aware of that. Let's let's start by doing what we said we would do, which is adding this extra, splitting this out into 2, and then we can figure out how we're gonna store data. I think that's probably the safest bet. So, let's add a new operation here. Let's call this 1, determine move. I think that feels okay. I think we'll give it the key of move. And I don't know why I've started doing that without having copied out this. So determine move, and this will be a run script. You can copy and paste that in here, except all we're gonna return now is move next. I think all we need to return is the strength next move. That's all this one has to do. And then we're just gonna re kind of configure these. So this one's gonna go here. This one's gonna go here and we hit save. And this keeps happening. Don't know why, but it seems to work if you just kind of what was it? Do it again? Yeah. Because that's what it was. Disconnect it and then save and it should work. Yeah. Like this. We do. Well, we did that. Okay. Cool. Cool. Cool. Cool. Yes. And now we're And then, which feels odd. Now today, there was actually a release of Directus the day that we are recording this, but I'm not feeling brave enough just just in case. Just saying it. So this this may well have been fixed. Do we remember what it was? Because it ain't ain't Don't say these. Bloody words. Is it not working? See. Hang on. Hang on. Okay. What if we go this way? Yeah. Okay. Fine. And now switch it. I think we had to, like, maybe. No. What the heck? This this resolved with this last time. So this is Yeah. But nothing nothing's changed, Andrew. Nothing's changed. Okay. Go back, and, like, remove it from there, save, and then go back, go out, and come back in. You think? I don't think that's what we did, but I wonder if it will No. No. We we definitely didn't do that. We did this and then this and then This is why you should always watch your VOD recording if you're trying to bug some of the buttons. We fixed it. Watch your VOD recording. We did. Oh, no. Okay. Remove the okay. But so let's maybe there is actually an error in there. Maybe there is a new error that we've introduced. Alright. But not nothing new has happened. Right. Value fulfilled resolve in collection, direct to this operation has to be unique. Are move the same? Is determine move and return move? Is it the same key? Is that what it is? Oh, possibly, but I really don't think so. This is no. This is called return move. Nope. Nope. It's a return move. You're right. So it works that way around. Cool. Cool. Cool. Cool. Cool. So so then we do this. And it does It's this. This is this is where there's a problem. I feel like our logic is not going to work. Can we just trigger another what if we just trigger another flow instead of doing it past the data? I know it's not as clean but, like, if we're gonna, like, bug solve even just temporarily, why don't we just send it to another flow? It's a new thing we haven't looked at as well because you can trigger another flow. I don't wanna do that. I don't I I want it to work. I mean, we all want these things to work. Okay. We're gonna pause and and we're going to come back when we have worked it out. What was so wait, what was, what was the you're right. The solution was exactly what you described last time. Are you getting error logs in your console that are different than that? Oh, no. Really? Shit. It's a great way to start a bloody director's TV thing, isn't it? Fantastic. Bugs are what make this feel interesting. K. Oh, what? No. No. No. This this one was the good one. Oh, that's yes. That's the reversed way, so it won't work that way. What have I just done? So this goes into return move. No. We want this one to go into determine move. Determine move goes into return move, save error. An error. Delete that card and create a new one and see if it solves the problem. Call return move. Card. Oh, doesn't like that. Yeah. Just return. There we go. Same thing. Director's operation. What is okay. Can we see that that field go into the data model? Can we not see that operations logic? I mean, I mean, yeah, I guess. But, like, we're looking at quite, like, low level, like, built in system. Okay. Cool. There is an error. Copy to action. This is what Riker's just messaged. Hang on. Did it work? No. Okay. I'm telling him what happened. Right. I meant I'm talking to the lead maintainer. Node 13 were. I made node 2 then changed the nodules. And okay. Fuck. Fuck. This is the way to this is definitely what what what was meant to happen this week. Is it okay. What if we run a simple script? Like, just detach that new one that you just created. Add any random script after the determined move. Okay. So we need to create a new one first of all. Right? Yes. Yes. It's great. Do will return data. Great. Right? It's like a pass through. It does nothing. Is it the script? What if we do the same thing with the I Yeah. If we duplicate this script, can you duplicate a flow? Not a whole flow. Oh, yeah. Flow? Yeah. I wonder if duplicating the flow might solve this issue. Duplicating the flow will mean we have to reconfigure the extension. But Well, I mean, let's let's see let's see if it works. Well, yeah. Well, I don't know why I'm doing that. So return. Okay. And we'll copy out. Blows. And then we can Oh, no. I actually can't duplicate 1. You could, once upon a time. No. It's insights. That's insights. Good to know. Fucking Here we are. Now we'll figure this out. We got this. I have I have faith in us. Okay. So our regulars our regular script our no. Our regular script was working. Okay. Skip just to the end. So, like, remove the the head to head and go straight from avoid body to the very end. So skip over the avoid head to head because this is where we started to get these issues. No. It's the final card that's fucking this up. No matter what it is. It's reassign. It worked. Did it work? It worked. Don't question it. Okay. It worked. We did it. What what was our solution, Kevin? We just tried many times and then waited to see what happened. Just wait until I cause many problems to my team. Okay. On our screen. Okay. Alright. Gonna resume recording. Thanks for the click. We got there. We did it. Go team. Go, Kevin. Okay. Hubert, you're welcome. Alright. Ready to come back? We're ready. Let's do it. Okay. And welcome back. We fixed it. We don't know how we fixed it. It just started working again. We will undoubtedly come across this again. Having spoken to like our lead maintainer, he thinks it's a bug, which I will open a GitHub issue on after this recording. Okay. Wicked. So now determining the move and then returning the move. Okay, cool. So we determine the move, which just returns the next move. And then all we want to do here, the literally the only thing we want to do here is return last. Right? Data no. Last. Last? Yeah. Just last. Yeah. I think just last. Date data dot data dot last. Is it? Alright. And the reason for this, if if nobody realizes this already, is because, like, you have to feedback this very specific JSON structure into the response that that Battlesnake precedes. Which kinda sucks. It just seems like, it should. It should just read this the engine should just get it. It should understand at a core level. If you're if you're being told to implement an API specifically, it's fine to have to do it specifically, but we'll test it works. And in theory, we should be able to in theory, we should be able to add another another flow operation here to do logging. Any logging we want at the end of the whole run. So let's manage our battlesnakes. Let's create a game where I'd already set a battlesnake and a hungry bot an 11 by 11 board, and we'll start the game. And that should be running game in progress. I can kind of see my logs over here that the game is still happening. I'll wait for the game to conclude, which it has not yet. You know what? I've run out of patience. Oh, no. It happened. So let's hit. There we go. Excellent. It did end up doing itself in, so there is something wrong, but we're not we're not looking into that bit right now. It worked. That's the important thing. It it worked for some period. Anyway, that's all so it is it is talking successfully, to directors, which is useful. Now what we now wanna do is figure out what we need to log. And before we do this, let's create a collection for it. So we'll go to our data model, we'll create a collection and what are we going to log? I don't think we should log every turn. I mean, we could log every turn. Well, I I mean, we could. I think I don't think it's necessary either. I think let's let's let's right now just log the final move just as like a getting started place. We're just gonna pass that data right through. And then let's do at like, ultimately, we'll end up adding something around, win or loss, because I think there's something cool visualizing that. And then I think there's honestly, I'd be love to explore us actually pulling the game GIF from this, which I think is more logic, but I think it's very interesting should be pretty straightforward. So if we want to log this, if we wanna log the the game, we need to be doing this actually in the end endpoint. Right? We don't want to be doing this in the move endpoint. We want to do it in the endgame. So this actually means we need to a little bit more fiddling, a little bit more fiddling with directors. And to the dismay of our lovely editor, I'm actually gonna unshare and reshare, but I'm gonna do my whole screen this time because No camera job. It's too late. I'm doing it. It's done. It's gone. It's done. Farewell. It's it's gone. Farewell screen. Okay. Apologies for for for that. But what we have here I'm gonna just reconfigure also. See every day, Kevin, by the way? Is this your screen, this large massive thing? It's a 49 inch ultrawide monitor, which will feature in a future episode of What's in My Doc because the final episode of the season is yours truly. We talk about it more then. So if I just make this bigger, we want to we have this move endpoint here. We can delete all of this logic that was left actually. But we have let me just shrink this down a bit. Just a reminder, when we hit the root endpoint, we're gonna hit this flow. When we hit the move endpoint, we're gonna hit this flow, the start and there's end. So what we're gonna do is basically add this logic to to end. So what we're gonna do is, kind of similar to the info end point. You know? The info end point. Yeah. Yep. Yep. Same thing. Yeah. Although that is a get endpoint. We need a post endpoint. So it's more similar to move, I guess. But what we'll do is we'll create a new one. We'll call this snake, end. This can be based on a web hook trigger. It will be a post request. It is a post request. Right? I mean, we'll find out together. I'm pretty sure it's a post request. Yeah. We we will, but I'm also gonna I'm also gonna double check. Look at the documentation. Probably smart idea. Look at the documentation. Not there though. Webhooks. Here we are. Game over. It's a post request as an error hit, by the way. It's it's not formatted as a code block, but it's a post request to slash end. It will be the game object, the final turn number, which is useful, the board describing the initial state of the game board. That doesn't feel correct. Oh, on that final turn, I guess. And you describing your battle snake. And I wonder if there's a death reason, but we can find out. So response body date of last operation. Great. And first thing we're gonna do is just copy this URL. I'll hit save. We'll copy this URL and we will go ahead here and const flow response. I'm not sure we need to, respond to this, but we will Await fetch full URL. We're basically just gonna copy and paste the all of these options because they remain the same. And then we're just gonna send okay. We don't need to do like we actually don't care about the flow response. We're just gonna send all the data by fetch and then send okay. We just need the data. We don't and eventually to respond. So we'll save that. Hear that flow response? We don't need you. We don't need you. Yeah. So inside of our extensions, director snake, we'll run npm run build. Oh, in today's release of Directus, we squash the bug that stopped the autoreloading working. So That's awesome. Nice. Was that because of us? No. Not even remotely. Well, I'd like to think it is. 10.9. 10.9 came out yesterday, so it resolved that. So now we have our new extension. With this new endpoint, we don't need to do anything more there. Back over to our code editor here. I suppose we can just we can actually just leave this be. Yeah. And we can Yeah. Let's just log, see if it shows before. It. Yeah. Exactly. Create rematch. So that whole game is is running. We see that 200 all the way. Really low really low, response. That's great. Running, running, running. And then we now no longer, we remove the console log for end. Oh, this is on start. Have we done it in the wrong place? Everyone, we've done it in the wrong place. I know. Amateur hour. But it is logging it, so we know what we know what the shape would be. Yep. So we can do that instead. We'll make this async. We'll remove async here. We will go and rebuild the extension, and then we'll restart directives. And while that's kinda happening, we can we can take a look at this object here. So we have game, which is an ID, which we'll probably wanna store. The rule set perhaps, probably not for this one, The the final turn, 95. Don't know what we wanna know about the board probably because 95, it's the turn where you're dead. So that's that array will not include us or it will include us and we'll be the last one standing, I guess. You has health. So I wonder oh, maybe we won this one. Maybe we won this one. Let's, let's watch it. Have a sneaking suspicion we did win. Yeah. So wait. How did we how do does it show that for us in that result? Like, it doesn't it doesn't say, like, in our in the law No. No. But I I I wondered why is it still giving me a health of 90? Why did it give me a health of whatever it was, 83? Smart. I have a sneaking suspicion if you die, the payload looks different, but there's only one way to test it, which is I've now restarted Directus. If I refresh this, there should be some logs. So this was the log of the one we just accidentally ran when we shouldn't have. So this is the start. So we'll just forget that one. Let's, let's do a rematch. And now we should only get the response when when it dies. So we can see this. We see it's posting slash snake slash move. And the last thing it should do is post slash snake slash end and it should hit a different trigger. So we'll just watch that happening and this is happening real quick. Wonderful. And that is what happened. It had a different flow at the end slash snake slash end. So if we go back to our flow now and refresh, we should be able to look at the logs. Payload. Okay. So this oh, did we win or or lose? That's probably worth knowing ahead of time. You won again. Come on, ready, set, battle snake. What are you doing winning all the time? You're too good. You're too good. Too good. So 73 turn 73. That is us, ready, set, battlesnake. We know our ID. I wonder if there's something in here where we log what our own Battlesnake is, but it may not be necessary. Let let's keep looking. It has health of 92. It has a length of 6, which could be interesting. We don't need to know what all the food is, where all the hazards are. You is just a convenience again. Alright. Let's, let's literally just keep creating rematches till we die. We'll let this run-in real time which means we we're gonna have to wait a hot minute as every move happens. Are we too Lindsay. Are we too good at programming Battlesnakes that he will live forever? Is that are we gonna need to are we gonna need to, pause? Artificially. I'm gonna have to artificially make him just, like, die. Come on. I think we oh my goodness. Come on. We gotta do it again. Gotta play again. Okay. Okay. Come on. 3rd time's the charm. We did, we did too much, Kevin. We went too hard. That, game in progress thing is not behaving, so we'll restart a game this way. I mean, if I just add ourselves, eventually, we'll die. Oh, there you go. Yeah. And it's interesting too. So, I think part of the game in progress thing might be I know I know Battle Sneak scaled down the server load, so it may be something related to that. Maybe. But, yes, we should live for we're gonna live forever. That's really what you've just done here. You're about to, you're about to kill your local version of Directus just because this will run forever. Hey. Good time. Alright. I immediately got it right and wrong. Thank you. Thank you. I reset Battlesnake. Alright. I mean, eventually, we had to lose. Right? So let's look at the final log when we lose. And I have a hunch. It is that our battlesnake does have a health of 97. So there is a health in there. So that isn't how we determine whether we live or die, unfortunately. We have a board. We have you. Although, where are the oh, the snakes array is empty. So we are not so we are there. Sorry. But we are not present in the snakes array. Oh, okay. That makes sense. So if the snake array is empty, we didn't win. If we are not empty if we are not in it. Yes. If we are not in it. So the easy the easy thing to do here is we have a we know our snake ID. Here it is. We could store it in a collection of our snakes to like factor out or we could just hard code it in. Well, let's let's let's have some fun. Let's let's do the more challenging Sure. More challenging. Snakes. And then, actually, if we look at the if we look at the API, I don't think there is a a meta Battlesnake API is there to get information about games and stuff. No, that's fine. What else should what there could be. Yeah. What if there is there's a start endpoint. I wonder if no, it's fine. We'll we'll we'll hard code this snakes. All we care about snakes is that they have a manually entered string as the ID and we can add all the others later. So if we go to our snakes, we'll put in the ID. That's ours. And you know what? We'll just add a name to it just so we can tell what it is. Right? So, this battle snake is ready, set, battlescape, I actually think is its actual name because we wanted to distinguish the one you made to the one I made. And my name is Elsford k. So it's registered Battlescape. Okay. Cool. So we've got that. So what are we gonna do inside of this end flow? First thing we need to do, I suppose, is we get this whole payload. The only thing we wanna enrich it with right now is are we alive? So Yeah. Is alive. Did live. Did I live? And that's going to run scripts. No, it isn't. First of all, we're gonna get all of our snakes. That's what we should do. Read items from the database. So, get snakes. Permissions from the from trigger. I'm just gonna give it full access so we don't need to contend with permissions. Snakes. If I don't add any IDs, do I get them all? We'll find out. We gotta find out. This is trial and error, Kevin. This is trial and error. Real, real trial and error thing going on here. Alright. Let's create a rematch with ourselves. I feel like I should add another snake back in just to end the games quicker. So do it. Yeah. Do it. Add another snake in. Just go back and make sure I'll let I'll let this game conclude. We'll do it until the next time we do it. Still running. By the way, it looks like games. Oh, thank you. I actually was really trying to find, like, the end of Loki season 2, all of the timelines. I'm not sure if you've seen it. And so it was kind of Yes, I've probably seen it. I've seen it's going for. Yeah. It was kind of that vibe I was going for. Okay. So obviously we eventually die. That's just the nature of playing by yourself. Let's just see how they perform now. Okay. Again, no idea why. Really shouldn't be doing that. But Don't question it. We wanted that to happen. We willed it into being. We willed it to happen. We want you to be chitter. Alright. There there's all of our snakes. So that's great. So that that returns an array of objects which contain IDs which are our snakes. So the next thing we want to do then is did live, like, you know, did live. And we will run a script here. And all we wanna determine here is, what did we call the last one? Snakes. So data dot snakes is the array of snakes and we want to know and we want to know did the trigger dot I need to I don't want I don't wanna close it. Don't wanna close it to to take a look. Let's look at the docs. Webhooks. So it will be trigger dot, I think, payload. I think so. Yeah. Yeah. We can always fix that later. The payload.board.snakes. So we wanna see, did that contain that? So, JavaScript, does array contain other does array contain specific item? I think it's like includes yeah. Does array contain item from other? Right? I'm pretty sure we just did this in our last episode. I think so. Yeah. Some. And I think I used find instead. So, live, which is like the if it lives, it will be found. So we'll say is inside of data dot snakes, is does that contain yes. Does that contain does data.snakes contain? And this is where it gets a bit honky, and I need to just just have a moment to think. So we wanna know out of all of the items in the snake array of which of which we know the I the ID is gonna be snake dot it. We know that already. Does is snake ID equal or does snake ID I got it. Does snake ID feature inside of this array? So what we actually wanna do is return whether this array, the one with all the snakes on the board contains, which I think we've determined is includes includes. Yep. Is it includes? I think we need to simp I think we need to do one more step beforehand which is take this big array here and just simplify it down to IDs. So, const IDs, IDs on board. So we'll take all of that and we'll map it and all we wanna do is turn that into an array of IDs. So it's just IDs. It's nothing else but IDs. Forget all the other information. That's all of the boards. We don't That's all of the IDs of the snake on the board. Exactly. And then we will return whether or not IDs on board that's it. IDs on board includes any of our snakes IDs and we will return to live. So true force, true false, did it. Really? It's gonna work. First time's the charm. Oh, no. I've done it again. I've hit create rematch, But eventually the answer will be false, right, this time with confidence. It should be. Or it'll just live forever and this will be this will be our time. Okay. Hit its hit its own tail. Mounted itself into a corner and did itself in. So let's, look at the last log. Cannot read properties of undefined. Okay. Cool. And it was body, by the way. It was trigger dot body. So that will probably be why. Trigger.body.board.snakes.map. So let's, let's just check that. Body dot board dot snakes. Cool. So we will create rematch. And now second time. And now. Go, red snappettlesnake. So stop eating food. Stop eating food. As it gets towards the food, I'm like, no. Come on. What are you doing? We don't want you to live anymore. What are you why? Why are you doing this? This battle snake is not bad apart from those times it randomly goes off the edge of the board, and we don't know why. I think it's just got a it's got a it's got a spirit of its own. Oh, what's happened there? Oh, there we go. Oh, okay. There was some real They were clearly in a queue or something. Goodness. Wow. We're doing I Oh, there we go. Why did you do that? I don't know. Oh, yeah. Yeah. Yeah. Right. It knocked itself into a into that kind of spot where where it can't. There is no viable move. Right. So we'll look at this. Cannot read properties of undefined. Okay. Okay. What is undefined? What's undefined is what we're running find on. So let's take a look at that. We're running find on data dot snakes. Okay? Except oh, because we call it get snakes. Fair. We'll call that snakes. Great rematch. This is the only thing when you'll see ready. Set up the snake. Sorry. This is the only thing when you're debugging. Go on. And you were saying something valuable as part of this conversation. I was trying to add some color. Wait. You there's there is just a bit of waiting here. Right? I suppose because the rules engine is open source. I imagine people I think people have built, like, line emulators that can obviously execute this way, way, way quicker for the sake of debugging. And I see the value in those tools. Yeah. You can actually do it in the CLI. In the CLI, you can actually play full games and see them. Because we just had to weigh a 153 turns. Alright. Trigger is not defined. Still. Okay. Trigger is and you know what? Because it's data dot trigger. So many amateur amateur hour little mistakes today. Never. Never, Kevin. Amateur is, is a term that we need to take back as a positive As amateurs. As amateur. As amateurs, yeah. Alright. Come on, ready set battle snake. You can die. Don't survive. Please don't. I believe in I I don't believe in you. I feel like he thrives. So the weather so the weather today. Yeah. Oh. Oh. Is that is this it? No. No. It it will lit. It's just obviously saving up moves. Yeah. There we go. Woah. It's like a taunt. That was like a taunt to us. Come on. We're doing exactly as we the thing is we made we made this snake. We made this snake. I feel like we is a very, oh, there we go. Alright. He made himself, really. Alright. Let's see if this worked this time. What do our logs say? Hey. We got data. Yeah. But this isn't what we want. What do you mean? What we want. I don't know, but I just want, I just want, I just want a true false value so something's not right. But wait So, yeah, go on. Well, I'm just like, what are we returning? Sorry. It's the text is really small. Not because of your screen. It's because We are returning, the whole, like, body of the script, which feels a little bit weird. And I have a hunch. I have a hunch. It's oh, no. Did live. This is live. So what's going on? What's going on there? Super weird. That shouldn't be returning that. No. It should not. Let's, look at our previous flow, the move one, and just maybe not, like just take a little bit of yeah. I mean, if we take all of this, and I'm just doing this as a comparison point just so we can kind of dump it in here and take a look kind of side by side, if you will. Yeah. Data dot trigger, Return. We do just return a value. Maybe, let's take a look at, array find method. Let's just understand this a little bit better. This returns the 1st element in the provided array that satisfies the provided testing condition. If you need an index, you can use find index. If you need to find the value, if you need to find if a value exists, you can use includes, which actually I think is what we want because that just returns a true or false. So maybe we just swap this out for an includes, includes, And we wanna know yeah. It's like a nested includes. Fine. And then we return I'm just I'm a little bit confused why it was returning Yeah. The whole code. Well, we no. You know what? We also don't get here. We don't get a returned payload, which makes me think there was some kind of error happening here that wasn't being captured correctly. Is there anything in here? I wouldn't imagine there is, and it's now really hard to tell. Let's, let's create a game. Let's let's make this game a lot, a lot quicker to end. Hey. There we go. Well, do you see how quick that was? That was fast. We are smarter than hungry. Niamis. Come on. What are you doing, Raze at Battlesnake? We want you to not die. We just want you to die. We might we might have to nip out some of the logic or something. I've never had a Well, well, that will that that will be the end. That will be the last move when it finally catches up with that with with Toast. Yeah. Snake end. The game seems to be struggling with the concept of ending, but it has ended. Alright. Yeah. Look. We get the options here, but we don't get the payload. Because if you look at the other flows, for example, wow, 1632. Wow. You see that all of these run scripts. I know they have the payloads. They have the options and they have a payload. Options payload, determine move interestingly interestingly, does does not have a returned payload. Is there something about them returning objects and strings versus just returning like a primitive. Maybe that's what it is. So if I so if I because this could be fine, you know, return. That's returning an object. Right? Mhmm. Let's create a rematch. Okay. Our snake just went up and up again. Hey. We don't know why happened. Bad things happened. We changed we changed the code. Shouldn't have done that. Changed the code. Shouldn't have done oh, there we are. Did live force. Okay. Awesome. Cool. So so there was actually no problem. Just an interesting note there that for it to show up in the payload, it needs to be an object or an array, I presume. So just a good just a good note there. I would love to play a game where we don't lose. So we can just so we can just check both sides of that equation and that they make sense. Let's create small boards. If we play with ourselves It wouldn't then technically, we'll always win and always win. Oh, well, yeah. But then I think it's just gonna get a little bit weird. There we are. Hey. We no. Wait. That's not what we want. That's what we want. But We've wanted to lose so much that now to win seems like a wrong thing. So did live should be forced. Yeah. Live should be forced. Let's create a rematch. Maybe we need to put in a a a a less clever snake. Goodness. Okay. Try Do you want the right bot? Yeah. Yeah? We we haven't we haven't gotta live long to make that work. Okay. Great. So now if we refresh, we look at the logs. Did live hopefully should be False. Absolutely. That's totally what we were wanting to have happen. Great. Is this really what we're gonna spend this episode doing? Okay. Fine. That's it. Just debugging JavaScript. That's really what we're here for. Right. All we want to do is now maybe maybe we just roll back for a sec. We're doing all of this grab snakes thing. I don't think this is adding I've deleted it. I've just done it. I've just done it. I've been busy for decision. Exec executive decision. All we care about is this ID. Right? So let's just we'll we'll delete this. We're gonna hard code it in now. Okay. Yeah. Yeah. Like, I don't think it's worth, like, going at all costs. Right? So all we want to know is does data dot snake say const? In fact, I think we can say, does snake include data dot trigger dot body dot board dot snakes dot map. Sure. So that's just a set of IDs. And all we wanna know is, does IDs onboard include this? And I'm I'm assuming can I console log inside of these? Best bit of, debugging we got. Great rematch. Well, I think our snake's broken. I think we spoke too soon about the capability of our snake. In it doesn't like includes. Payload.body. Right. Hang on. It doesn't like includes, which is this one here. And we don't get a log, annoyingly. So all we care about, Let's, you know what? I'm actually gonna be bold here and just remove this, and we can start we can start again. So so all we wanna know is did it live? And to know if it lives, we're gonna go through oh, no. I do need to I need this too. I like it. I like the I like that you were confident in the removal, but also truly confident. That I you know, I really wasn't. So all you wanna know is, does data dot trigger dot body dot board dot snakes, does that include includes includes let's take a look. We need to give it a specific value here. So I think what we'll first do is we'll say snake IDs on board. We'll take this and we'll map it once again. So we just extract the IDs. Then all we wanna do is check whether snake IDs on board includes this value here. It's all we wanna know. Please work. Create rematch. We've got this. Okay. Our snake just keeps going up by the way. We fundamentally broken something. But I mean, these things happen. These things happen. We'll figure it out. We've got Live force. The rest of today. Live force. Okay. And we did we did we did live force. Yes. That is that is true. And all we need to do is outlive the snake, which we did, and hopefully live is true in this context. We may need to go back as as we commented in Okay. But we lived, but we lived. Let's let's take a look at the payload. Let's take a look at the payload. So body dot game, no. Body dot board dot snakes has ready set battlesnake present, and that's it. The snakes have an ID. That's our ID. That is I'm just gonna double check. Yep. The ID, nope. Not the ID we've been pasting in. What does it get a different does it well, it's different. So I'm wondering, look at this ID, w d at the end. If I look one game back, it gets a different ID every time, Andrew. So we gotta pull name then, I guess. I guess the ID is not I'm literally so mad. Yes. Fine. As well, you should be. Damn you, battle stake and your your ID that is not truly the snake ID. Who do you It does feel that way. I can't believe we sunk so much time into that. Okay. Cool. No. Right. Create custom game. Create rematch. Okay. We lost because apparently we just go up now. Yeah. Liveforce. Cool. And create rematch. Yeah. I mean, we lost again. Sure. Because that's what's happening now. What is going on with that, by the way? What is going on with that? Is it is it work. Are we struggling under the number of logs that are being generated? No. I mean, possible. Look, avoid head to head force. So there's something in the avoid head to head. Oh, god. Because there was no head to head issue here. No. There wasn't. Let's create rematch just until we get a a seed. I think, yeah, we both die at the same time there. Let's create rematch. Let's just create a seed just to test out this logic. Yeah. That's good. Nope. Not good. Okay. Create game. Okay. We we broke it. We broke it. Okay. We are still not gonna do well this oh, what is going on? There we go. Is it there someone is there something is there something about we did? Is there something about the board size being different that's throwing it off? In which case, I'm quite happy to say how Battlesnake only operates in 11. That's the right answer. Don't make it work on all the boards. Only standard class. True. Okay. Hey. There we go. Finally know whether it lives. Now it's all about logging information. So let's look at this payload and see what we have. So we have a game ID, which I think feels like a no brainer. Right? Yeah. And you said we can do something with the ID to get the GIF? I believe so. I'm gonna go check and see something right now. I'm gonna go over while you're doing this, I'm gonna go over to my other screen. But, yes, we'll pull back so that we need that. We know the turn of the final move, which is 2. Yep. Right. So that's the term where we were victorious. We know that we lived. We know our length, I suppose. Yeah. I think so. Yeah. And maybe we do maybe we start with just games. Games get an ID, which can be a manually entered string because we'll we'll pop that in from the API. And I think all we need here is win or lose, right? Win. That's a Boolean. We wanna know what about it. Like, a turn, I suppose. That can be an integer. I mean, game mode? Turns. Yep. Turns. Turns feels better. Yep. Turns. Into game mode, but we're not playing around with other game modes. So I just think That's true. Yeah. It's fair. Yeah. But but the idea is, in theory, you could you could store all of this. Wind turns. What else have we got at our disposal? Let's take another look at our end state here. We have live die. We had turns. We can start with how many snakes there were on the board from the trigger. So snakes dot so trigger trigger body board snakes length. Just quickly gonna go, store. We're gonna prepare data. So trigger dot body dot board, did we say it was? Dot snakes.length. So I'm just gonna pop that in there for later. Yeah. So snakes, that can be another integer. What what else what else do we wanna know? I mean, let's let's let's stick it with that. Good because we you could do, like, a win ratio. You could do, like, average turns per game. Like there's lots you can do here. Do you continue getting data if you are not the last to loot? Like if you die and it goes on a few more steps, do you only get the end state on your final turn or do you like, let's take a look. Your battle snake will whenever a game it has playing has been ended, use it to learn how you battle snake won or loss and deallocate any server side resources. Okay. This was like a good starting point. So this is what a game looks like. ID win turns snakes. So going back to flows, let's, do our end. So did live. We're gonna prepare data. So the only extra thing we wanted to know here was snakes. Snake count. What else do we wanna know here? We we might as well get it already to be fair. Might as well just do it straight within here. So snake count. Is this. We have we had snake count. We had turns. So once again, let's just take a look at the it was game. I think it's game dot turn. Game? Maybe not. Bored? Bored? Bored? Hold on. No. Am I using it? Oh, it's right here. At the root, turn, integer. So that should just be trigger.body.turn. And we wanna know we wanna tell how many things. We wanna tell how many turns. We wanna tell whether we lived or died that we needed the ID. ID. So trigger dot body dot the ID. I think it's just I game dot ID, I think. We'll find That sounds right. Game dot ID. Yeah. Nice. And while we're here, let's, let's just also get the did live. So live. Live? What did what did we call it in our director's collection? Lip libs? Let's take a look. Was just libs? It's called win, actually. Win. Alright. Smart. Win. So, oh, so in here, we'll go prepare data. We'll go live, but it's called win here. Live, live. Fine. Whatever. So we have, I really don't like using last or I can help it because it allows you to obviously move things around without your data becoming like brittle. So I'm gonna pop did live. And all of these have to be prepended with data. Okay. So in theory, that's the preparation of the data. Let's, let's run a custom game one more time. If our snake performs well, it will have been the 7 by 7 board that did it in. Well, I think I think oh, of course, we've just got let's create the game with the ready set battle snake and the hungry bot now. Yeah. Weird, isn't it? Anyway That's such a good idea. I wonder what we did. Don't don't wanna know. No. That's a question for, for season 2. That was a question. Set back. That was a question for last week of and now it's this week of do you see how big that snake's getting? Oh, of course, it's hungry, but isn't it? That's its whole that's its whole shtick. Are we gonna win this one? Oh, we won it still. Yes. Legit did. So Well if we refresh here and look at our log payload, snake count 1. This is wrong. So we need to just look at this because we wanna know how many snakes were in the whole game, which in theory should always be no. It won't always be this. End. We're pulling from end, so it's only gonna pull the last snake. Right? Is that what we that's what the Yeah. Maybe we maybe we need to do it on start. We need to create it. And then on end, we need to update it. We have turns, we have the ID and we have whether we want, which is true. So maybe for snake count, because I do think snake count is interesting. We should create just create the data. What do you think? Or do you think it's too heavy handed to create a whole flow for that? I mean, I don't think we need a whole flow for it. That seems like a bit of a change. I mean, we need we need a flow for it. That's the truth. So may I mean, we we've we've got pretty we've got pretty proficient at it now. So what we're gonna do is create a flow. Yeah. Yeah. We'll call it snake start, Right? And so what we're gonna do here is we're gonna do this as a webhook. It'll be a post request. We'll go like this. Just double check the API reference webhooks. Your request to this your response to this request will be ignored. We don't need to care about our response. We'll save this, grab this URL, and then we are going to take this whole end here. And on the start, we'll make that async. We'll paste that in there, except this time we will change the URL to this 1, 704. So that start, we need to just kill this, go here, rebuild our extension, Done. Go here and Docker Compose up. Wonderful. Should be able to refresh. Should be able to refresh. Now I think it just took a moment just a moment to spin up there. And what are we gonna do here? We're first gonna save. We're gonna go and create a game. This will need we don't even need to wait for the game to pan out in order to look at this one log. All we care about is I suppose number of snakes here. So trigger, body, board snakes. Trigger body board snakes. So what we'll do here is create sorry? Board trigger body snakes. No. Trigger. Shouldn't be Stop it. Shouldn't be Stop it. I shouldn't do that. I'm sorry. Create game. We will create data in the game's collection with full access. And all we're gonna do here is we're gonna say the snakes is equal to. Trigger body board snakes. I got it. I got it. They need to be in quotes because it's Jason. Trigger Jason or Jason? I I am a JSON. Jason. There is one there is actually, extract snake count. We just need to get the value out in the previous step. I don't strictly think you need to do this, but just to keep it really clean, what we're gonna do here is we're gonna return snake count. Snakes is equal to data dot trigger dot body dot board dot snakes dot length. Snakes. Copy that key. And then the next one, we will create data. The name and key doesn't really matter because it's our last step here. All we care about here is we need to create an ID at the time. Oh, but we can create the ID as well. We can get the ID as well at the time of creation. So snakes is going to be equal to, this snake count dot snakes. And I actually think we can ignore this error. There seems to want a string, and I think that's fine even if it's, an int just to stop it moaning. And then we also want the ID, which is going to be oh, oh, throwing my cursor around. Here we are. Trigger dot body dot game dot id. So if I save this, we create a new game. Oh, got a little Game in progress. I don't think it is. Our snake 1, thank you very much, but we will create a new game. That's fine. Start game. We immediately should get a new log here and we got a trigger but nothing else happened. Why? Oh, no. There we are. Create data. Type error cannot read properties of undefined snakes 2 body trigger body game ID. Okay. Cannot read properties of undefined reading starts with. Interesting. This looks Looks good. Looks like what we want. Snakes and ID. Is that what we called them? Snakes and ID. What is going on? So star. Shrek snake count. Because in theory, this is looking oh, pick collection. That'll do it for the access. Not telling it to do anything. Alright. Create game. I've got really you get really proficient at starting new games with Battlesnake, don't you, when debugging? You do. Alright. Did it work? Oh, there we go. Now how That's the idea of a new item, item, which means we now have a new snake. Wonderful. So now going back to our end state, we don't actually want to so let's refresh ourselves. Prepare data, prepares a snake count, turns, ID and win. We do not want a snake count. We do not want a snake count. So when we prepare data, we can remove snake count and that leaves us with turns, ID, and win. Yep. Turns, ID, and win. Turns ID and win. And, actually, we don't even want the ID here. No. We we do want the ID because we wanna be able to pull that GIF eventually. But we stored it. It already exists. Oh, that's right. Yes. You're right. You're absolutely right. This is what we're gonna This is what we're gonna so all we're gonna do here is now update the data Lovely. In the game's collection with full access with this ID, trigger body game ID, and the payload, I think we might just be able to put in lost and I think that's gonna be equal. I'm not a 100% sure, but I think that's gonna be equal to the object. So we'll see. Alright. The first thing we'll do is create a new game, and then I think we'll be ready to jump into insights and see how that works for us. So here's our snake performing well in these apparently quite controlled conditions of an 11 by 11 board with 1 other snake. Okay. Come on. Some something happened now. Come on, hungry. You don't wanna survive. You're not really that hungry anymore. It could be all all one either. You both suck. Hey. Hey. So first thing to do is let's see. So you will notice nothing happened there. I've also, to be fair, noticed we don't have any we just have IDs. We probably do also wanna capture, like, the date, like like the now date that's happening because, we just wanna be able to sort the latest item if possible. Yeah. That's fair. So we'll create a date time, finished. We can call this. I think this will work. Date time. Sure. And then at the well, firstly, that didn't work. So we don't wanna spend too too much time on this, but we'll prepare the data here and we'll say what was the name of the field? Do you remember? Oh, it was, we didn't call it datetime. We set it today. No. Now? When? I'm not sure. Jeez. That that's terrible. Both have forgotten Finished. The minutes of creating it. I mean, same. Same to be fair. Finished. We also wanna store finished, which I think you can just say new date, new date dot now. Is that how you do it in JavaScript? Your guess is as good as mine, sir. Yeah. New date dot now. Cool. But it didn't work. So as much as this is cool, what happened here? We updated it. We updated it with the key. Oh, do you wanna know what didn't happen? It isn't showing here that we had a payload. So I think there was an issue with the payload. Oh, look, the payload didn't save. Interesting. So I'm just gonna double check that that is what happened there. If I hit save and then step back in, maybe it shouldn't let me do that, but this is okay. We're not gonna lose much sleep over it. Finished is going to be, no, last dot finished. Then we had, win is going to be last dot win. We'll wrap that in quotes too. What was the third one? What what are the 2 that we have now? Win, turn Yeah. Turns. I believe. Like a living rubber duck. Last stop turns. Turns. I'll hit save before we, you know, spend time on a full snake. We'll take a look. Turns and win. Turns and win. And now we have finished. Turns, win, finished. Turns, win, finished. Great. So let's save all of that. Let's create a rematch. We should see, hopefully, that this is stored. And then I don't think we're gonna spend much more time capturing data. Instead, we'll run a few games, and then we'll try some insights. Nothing's happening still. So still something done in our logic. Let's look at our latest I'll just refresh it. Let's look at our latest log. Oh, intermediate value dot now is not a function. I actually know why this is the case, and it is because, these run script operations running what are known as JavaScript isolates, which are these incredibly limited JavaScript like runtimes that only contain pure JavaScript objects. Let's actually take a quick look at that because I think it's interesting. Isolut. Yeah. This page looks legit. That's not what I want. I do kinda wanna show you like pure Java script or, objects. This is what I'm looking for. What I'm looking for is just like, where is the list? Am I am I what's happening? You might be imagining. You might be imagining this. You may have already used JavaScript. I just I have imagined it. Created it. Maybe you created. There's no documentation. What did you call them again? Isolates. Isolates. Interesting. I've never heard of that. Isolates. And now is that just a security thing within Directus to ensure that, like, bad actors So this So this actually happened in version 10.6. We had I think this is quite what I want. We had prior to version 10.6, you could build, you could use NPM modules inside of extensions. Extensions. Well, video has gone a bit funny. I'm not sure if the is fine now. It resolved itself. Anyway, and the library which we use to isolate flows from each other and operations from each other basically became insecure. Like, it was it was became known it was insecure, and so we had to remove it. And in doing that, we replaced it. And now it now it runs what are known as isolates. And this is what I'm looking for, I think. 1st class. Nope. I'm looking for oh god. It's really bothering me, but I will take a moment to find it. What's is it in our docs? In breaking changes 10.6, we dropped support for custom npm modules in the run script operation. Prior to this release, directors relied on VM 2 to run codes in the run script operations and flows. VM 2 is now unmaintained with a critical security issue that could potentially allow for code to escape the sandbox and access the machine, which hosts directors. So we've migrated to isolated VM to allow flows to run safely. This basically means you can't use just arbitrary NPM packages in flows anymore. You can still turn them into custom operations, but it isn't isn't here anyway. I learned a lot in during the process of this. There are lots of things you use in JavaScript, which you think are part of JavaScript, things like set interval, things like console log, set time out, fetch, that you just think, oh, this is part of JavaScript, but it's not part of JavaScript. It's either part of the browser's implementation of JavaScript or Node JS' implementation of JavaScript, many of which are shared. Isolates don't have this. Isolates just have pure JavaScript functionality. And the I I what I was trying to find was the list of what that meant. I've I can't find the word off the top of my standard objects. Boom. Found it. Thank you. So this chapter documents all of JavaScript standard built in objects. So you have access to global this infinity, not a number undefined. You have these function properties only. You have some fundamental objects like object function, Boolean symbol, a few error objects, a few number and dates, a couple of text processing functions, a few on arrays, key collection structured data and so on. What you'll notice here is a lack of console logs. What you'll notice here is a lack of date, which is what I was which is what I was going for there. We're not gonna lose any sleep over this. I'm literally just gonna we'll remove finished. It just isn't worth the time right now. You know, I do like it though. I wonder if can I add can I add after the fact a date created? Or did that have to be done at the time of Based on my I think it might have had to be done at Yeah. I just scroll down. Though. Exactly. And then just flip it over. I'm just taking a look. There's a sort field, which is great. That's okay. Take a little take a little cheeky screenshot of this so I can refer back to it. There we go. I'll put that off at the site, and then we'll delete this collection. I there might be a way to do it, but I I don't have the the patience. If I see But what I want is date created because I think that would be interesting. That's all. I just wanted that one extra field. So half width. So we also had in here a win, which was a boolean. We had turns, which was an int. We had snakes, which was account. It was a number. It was also an int. And we had finished, which we've effectively replaced with a date created. So half, half, and whatever. Half. Okay. So but but so they run-in isolates. And isolates what it taught me was all these creature comforts I have in JavaScript are not in JavaScript, they're in Node. Js or they're in the browser implementation of JavaScript. But, yeah, that's how I basically learned that. There you go. I had no idea. I had no idea console log was not built into JavaScript. That seems so odd. But I guess the console you're dealing with is in the browser, so it does make sense. Yeah. Let's create a new game. Let's create a rematch, see if we can get it to work. But, yeah, just fascinating. Yeah. Isolates. And isolates are not, you know, while that's running, isolates Cloudflare. I wanna say Cloudflare Workers. Yeah. Here. They have some really good reference while I was learning more about it. Isolates. VA orchestrates isolates, lightweight context, provide your code with variables that can access in a safe environment to be executed within. You could even consider an isolate a sandbox for your function to run-in. A single runtime can run hundreds of thousands of isolates switching between them. And isolates memory is completely isolated, so each piece of code is protected from other untrusted and user written code in the runtime. Islets are also designed to start very quickly. Instead of creating a virtual machine for each function, ISIT is created within an existing environment, blah, blah, blah, blah, blah. So but what's interesting is they are they are way more limited. Yep. Yeah. I wondered I wondered why because I I think what did I I was reading yeah. I've been reading through the documentation, and it said that the the specific JavaScript that you were able to call within within lots of these areas, the directives were limited. And I was like, oh, that's that's an interesting and I figured it was security, but I didn't realize there was so much to learn here. But that is why you come here to Ready, Set, Battlesnake is to learn things about Battlesnake and JavaScript and directives. And it worked. And it worked. Let's go. And it worked. We did it. So what we're gonna do now really is we're gonna just hit create rematch. And if I can I create loads of games in in, like like Yeah? Yeah. Yeah. It's gonna break things. We we we have also not built just a moment. We have not built logic to know which game is happening. We'll do one at a time. Top of them, we have. We have. We have. Because every turn is individual on the move endpoint. And then on the start and end, we're referring to the IDs. Actually, we could be running a load of these in parallel. Alright. So give it a try. Let's see what happens. See what happens. What's the worst that could happen? We end up having to pause our episode because we made a mistake and we have to fix it off camera. That is the really the worst that could happen. Oh, I am a bit concerned now because I don't even know when they've completed. That's another problem is I actually don't know when they I've taken a a guess that they won't take longer than each other. Like, alright, that game's over. I mean, let's just see. There you go. We're not winning every time. We have a number of turns. We have a number of snakes. Let's, let's just create a few more games. Like, I I want a a reasonable set to start with. All of them are gonna start with 2 snakes. Go on. I was gonna say just so if you, like, if you're if you're watching this and you're like, oh, I don't wanna have to, like, do this. It's it's causing my browser. I don't like all those tabs. You can, like, do all this from the CLI too. Like, you can actually go in and just, like, continually create games for the CLI. This is just easier than going in and setting up the CLI right now. And I don't wanna set up the CLI in this moment. So we should actually know if any games are outstanding because, yes, see, there's no turns and no wins on this one, which tells us that game is pending and now it has concluded. So, actually, we do have a little indication of how games are going. Look at us. So we'll create a few more games with a mixed player count. Okay. And if we refresh Directus, we should see okay, there are a few games still pending completion. If I refresh, 2 games pending completion, refresh 1 game pending completion, refresh. That game is still going. That game is still going. That game is still going. Oh, still going. We're doing well. Is that is that the last one we created? I mean, we'll find out. It must be. I hope it is. Descending. Oh, they've all concluded now. Okay. I think that's good to start. So Yeah. Let's go to insights, see see what we can do. Snake battle station. Let's pick a little kiss. Pick wonderful. Pick a little thing here. Is there a I don't is there like a snake? No? Is there is I don't want this game. Yeah. Cool. And our battlesnake. You know, do you wanna know why green feels like a very snaky color to me? It does. Save. That is the right one. Snake battle station. So this is, director's insights. It's this little module over here. And here, we can create dashboards. I don't really use it very much personally, just because my use cases don't demand many dashboards. So there might be a little bit of learning here. You can create panels. Just as a note, this is panels also an extension type. So if you wanna, you know, build on top of these panels, you know, build additional panels, you're more than welcome to. For this, I think we're going to stick in here. You know, we have the pie or donut chart, which feels like a good starting point. So we're gonna look at exactly what I had in mind. So win, Win. Count. Sure. Don't care about donut. That's just a display thing. Show labels. Yes, please. Show legend. Yeah. Pro oh, do you wanna know what? Let let's just see what happens here. Can because I think we can do conditional styles as well. So win rate. Okay. Hey. Dang. That was I don't wanna say that was too easy, but that was very smooth. Yeah. Although I we do need a legend. We do need a legend quite desperately. I would just always assume the the bigger one is my win rate. That's really It it you you are correct. Alright. Win rate win no. Win rate feels good. We can do, games, you know, we could do, the x axis is this one. Right? So date created maybe and turns, like how well am I doing over time. Yeah. Yeah. I like it. Aggregation. I don't really know what I'm doing here. Well, okay. Just leave it leave it without aggregation and see what happens. Yeah. Sure. And we'll call this one what are we doing here? Turns. Turns feels like a weird one. Maybe we just do turns feels weird. Why don't we do, like, account? Because I think what it will do, that's tell us the number of games. Sure. Let's find out. Right? Right. Games over time. Of course, we'll be looking at a very micro Woah. I'm not sure this is gonna pan out. This totally is not correct. Okay. Something. We did a bad thing. Aggregation can be forced as well. Right? Can you? Well, set it as false to see what happens. See what that change does. Oh, didn't like that. We are not doing that. I guess we do need to have Oh, aggregation is gone. Okay. So we have turns. We have snakes, we have x axis, which is date created. Do we need something on both axis? I'm sure. Do we? Oh, maybe not. I mean, it kind of looks like we do. I mean, I'm kind of as you can tell, I really don't make a lot of dashboards because, you know, it's just not it's just not my world. Maybe if we let's let's let's, see what else we can do. We have I like metric firstly, which is like total games played. That one feels easy. Yeah. That's simple. Aggregate function, just count. Count. Yep. And, suffix, Games played. Star decimal unit. Notations standard. Yeah. Yeah. Oh. Uh-oh. GraphQL validation error? I think I'm just not I'm genuinely thinking I'm just not selecting enough field. Do we need to do a field ID? Yeah. We did. Oh, there we go. 15, 15 groups load. Nice. Sure. Okay. It's not pleasing my eyes very much that, but let's, keep taking a look. Yeah. What do we have still? Font size auto, which makes sense, or you can make it fixed and then you can add padding accordingly. I do get the auto. Auto makes a ton of sense. We have a line chart. We have time series. So the collection, once again, games, the group aggregation, oh, group precision minute because we set a few games off at the same time. Count, date field, date created, date range, past 15 minutes. Sure. Value field. I, turns. Snakes. Oh, I don't know. I mean, can I edit can I can I oh, there it was? Can I clear the value, please? I'm just gonna hit tick. Alright. Didn't do anything. I've picked I've picked the wrong combination of picked the wrong combination of options. We almost we almost did it. Did you see how confident I went in? You went in. Listen, confidence is half the game here. We just gotta go in thinking you know what you're doing and, eventually, you know I'm not really sure. I'm not really showing this bit of director stuff pretty well. No. I think it's I think you're doing this fantastic. I like that we've been able to get stuff like we so it's because I said it was so smooth. Hey. There we go. Nice. And these are showing us? So this is showing us the number of turns taken on a minutely basis. And that was where I set loads of games off, and this was just as it was coming down from the last data point that was held. If I do it the past 30 minutes, I think I'll get a slightly oh, maybe not. It's a good try. Yeah. This is oh, here we are. Automatic based on data. That feels good. Okay. So 80 turns over here and then 320 turns over here. And then if we create a couple more games now, we'll create a game. Yeah. And I do like this. Like, if you were actually looking at this over a period of time, this would make a lot more sense. Could be really insightful. Yeah. So let me just save that, and we'll just make sure. Oh, thank you. Woah. Last game has not concluded yet, so we'll just let that conclude. Okay. So if we go back to insights now, there you go. It's a little bit more of a of a view. Right? So I don't really wanna look at the number of turns though. I wanna look at is it count? I think that will give us the same graph. Yeah. What I want is I just wanna know how many there are. How many games? How many how many games? Do you think turns is interesting? I no. I mean, I think let's I so turns is interesting, but only if you're playing 1 at a time. Exactly. And I think I think I think there's a way to do that. I've seen other people do it. So we had I think it might this global variable variable key can be like game. Confidence. Lots of confidence. Game interface. That's not what I want. Type. Is it in here? No. I've seen it. I've seen it somewhere else. Is it maybe called global relational and you pick a collection, you pick games, display template? Yes. You find the ID. I think this is it. So you select a game. So it says select an item. So can I, whatever? But we we won't look at editing that. So you select a game, right, like this. Great. And then you can use that global variable in all of the other boards Okay. In all of the other panels. So if I you know, maybe we do this. This is like global values up here. Great. And then we have this, you know, dynamic portion. So what do we want to know here? Well, we want to know I I don't know. Like, what about are we doing we're not doing per turns. We're not storing turns too. Maybe we just do what do you think? There's only one other thing that I thought would be really fun, but I think that the logic is gonna take too long. No. And it I mean, not gonna be related to this panel. I think it's I I'd be very interested to pull in some custom that that the the actual gift for the game. I think there's something interesting there to be able to pull in. I think we could do that. I think we could do that. Yeah. That's an ambitious it's an ambitious goal. You wanna try? Yeah. Go on then. Right. Tell me how to get the tell me how to get the URL. Go to your game. I'm I'm going. Got it. Alright. Go to view as GIF, and then it'll give you the format that you I will only click it when you say it correctly. GIF GIF. You may. GIF. Okay. And there's a URL and that's the game ID. Grab that, And that's that ID is movable. Right? Like, that ID is the ID of the game. So you can buy back and game by game. Yeah. So let's try our hand. We need to do a custom panel. That is that is definitely what we need to do. Yeah. But, right. So what are we gonna do here? We're gonna go up one layer. We're gonna go MPX create directus extension at latest. Whoops. Extension. Helps when you type it correctly. Right. What we're gonna do, we are oh, you're you're putting me on the spot here. I'm not overly confident. And viewers, if we don't get it done, we're not gonna get it done. But let's call let's consider this a stretch goal. I also haven't used these global variable values too, too much. While that's kind of doing its thing whoops. Docs, Data Studio app. I think it might be over in the user guide, insights, panels, global relational value here. Oh, and then in other in other, ones, you can use the variable key like in other panels. That's interesting. Anyway, we want a panel, director's extension, snake panel. JavaScript install dependencies. Okeydokey. I'm glad I gave you this challenge, and I am not the one having to implement it. This seems right. This seems good. It all seems good with the world. Alright. So we have the panel here. We have our panel dot view. It has been a while since I built an extension. So here we have all of the configs. We'll call this snake GIF snake GIF. Sure. We could do loads of configuration. We're not gonna do that. First thing we're gonna test is if we just have a if we just have a string like we manually insert it to start, can we can we play? Can we play it back? So in the panel, we have this text here, and I think all we would need to do, there's a bit of an assumption in here, is we're gonna paste in this URL and we're going to interpolate here the text, right? That feels right? It feels very good. Npm run dev. Sorry. Npm. I'm I'm not even in the Npm run build. I wasn't right running the right command or in the right location. And then we will I think what I'll do is I'll can I hang on? Kinda wanna open them side by side. There we go. And then I wanna just kill that, restart it. Once again, fixed as of, like, yesterday's release. I just haven't got around to upgrading this one yet. Open up our panel, and I'm hoping snake GIF. Hey. We insert an ID here. Let's go get an ID. This one, 72 turns. And so I I can't believe it might actually why did I say that? You've jinxed it now, but it's okay. Here. Hit save. Okay. Save. And oh. Don't know, mate. Happening. Oh, I have my dev tools kind of detached. Content security policy. So this might actually be cross it might be course with the dev side platform. Which is which is, the ilk of what this is. How do I solve it? How do I solve it? It's a GIF. It's a GIF at a location. Can we import it maybe? Can we import it? And then how would we import it? Let's take care of let's let's consult the docs. So we have in here extensions, developing extensions, extension services, accessing files, import a file. This is inside of an API extension how we would import a file. We would instantiate a file service. We have an asset key, which has the URL and a file object, which contains additional metadata, and then we read it in order to to return it. Excuse me. So let's have a think about the right way to play this. We could press a button. It'll import it and then play it back. It's a good idea. Let's try that. That seems easy. Let's try that. I say this. I say this. Easy as a That sounds easy. That sounds easy. Kevin problem. Sounds like an Android watch, and Kevin solves this tactical challenge. Alright. Alright. Alright. So let's just keep this easy for a moment. Let's let's stitch this off, and let's create a new bundle. And I'll call this one directus extension, and I'll just call it, Battlesnake Viewer and install dependencies. So that's creating a bundle. In that bundle, we'll have an endpoint and we will have, and we'll have an endpoint and a and a panel. So we'll CD into the battlesnake viewer, and we'll go npm run add. And the first thing we'll add is actually the endpoint. We can just call this one importer. JavaScript. And now inside of Battlesnake Viewer, source importer index dot j. So this is again, our custom route as mentioned earlier. Now inside of our existing one, we've actually got this is snake GIF. We have our actual snake here. We're gonna we're gonna just kind of nab this structure for a moment, inside of the importer here. We'll remove these actual things here, like so. Okay. So we'll call this one importer. Right. So when we hit importer, what we're gonna do, and we're gonna do a post request here, is we are going to access files. I'm gonna copy all of this. Here. We'll see what we can do. Oops. Okay. Router dot post. We will create a files service. Now I actually think, the docs do talk about importing that. So let's just take a little look at the top here. Yes. Okay. So in the endpoint itself, we have a router and a context. Awesome. Let's do a let's do a little more side by side jobby here. Right. So we have router and we have context. And up here, we're going to grab these values out. Then inside of router.post/cool, we will create a new file service. We will look at rec. So file.url is going to be req.body. URL. Cool. And the file object itself, how much of this must we pass? Let's look at the file object. API reference files. File object looks like this. How much of this must we pass? I don't think any. I don't think we need any of this. So I think we'll remove that. So we have our URL. Then we will import it. It will come back. We will then have the asset key, and we'll return the data. So if all goes well, npm run build, This is our importer, docker compose up. And I think what we wanna do here is test whether this endpoint works. Now I still have ngrok running. I don't still have it running. I've been running it since the beginning of this, this session. And I have hopscotch here, which is similar to Postman. It's just like an HTTP Explorer. So here, if I go importer post and inside of the let's just hit send there. Okay. Timing out, timing out, timing out. There is an error, invalid URL, input object object. Okay. Let's just cancel that. Let's set a body. Let's set this to be application JSON. There we are. And what we want in here is a URL of and then this exporter battle sync. So hopefully this will return the ID of a new item in our directors project. Okay? It's still going. So not feeling good about that. Invalid URL. Is it, though? Is it? Apparent I mean, no. No. No. Object object. Import 1. So it was struggling with import 1. So let's let's take another look at this. So it was struggling here with the file service dot import 1. Req dot body dot URL. Now to be fair, we never once took a moment to check whether it was gonna be req dot body. So let's just res.sendokay for a moment and that's console.log req.body. There was a bit of an assumption in there. So we will rebuild that and then we will restart that. Okay. And we will send that and we should hopefully get an okay back. We did. So let's take a look. So inside of req.body, yeah, dot URL. What's going on? Is this a URL we can hit? Oops. Yeah. Should be. Yeah. Sure. And let's just test that there's nothing funny going on with, like, access here. If I go to our file library and import, this is the RF for importing and hit import. The GIF is there. So there is nothing wrong with that. So we're just doing that via API instead. So fair enough. Fair enough. So we have the URL. We have some accountability, which I think we might just be able to bundle some for now. Get rid of it for now. Let's do npm run build and restart the container. Go to hopscotch and send this. Okay. Great. And this time, we've got a URL, which means there was nothing wrong. So let's just do one step at a time. That's console dot log the asset key. Yep. Rebuild. I'm determined to get this to work now. We are gonna do it. We have we have the Cool. Technology. We have the ability. That should still just return an okay, but it hasn't. Why? Code error invalid URL. It gives me it gives me it gives me the docs might not be right, which is possible. So as much as I wanna just be like, but that's what it says to do. Let's take a moment and let's actually, if we go to accessing if if let's find let's find the docs for this and let's just step through because all of the services are just in the code base. It's not my preferred way, of course, to be looking at stuff. Let's take let's take a little look. What we care about here is import 1, and it does expect an import URL and a body partial. So maybe maybe we did need to pass in, could not fetch from URL. The error said invalid URL out of interest. So maybe yeah. Because what it does is it grabs the raw file and then uploads it. Maybe we need to we must pass in this body. Just a thought. And that was the partial body objects. And maybe I mean, that's a partial body object. Maybe there's something else we must pass in this at the time of creation. Let's, let's hit send. Come on. Okay. Okay. Okay. In fact, again, it's taken that long. Yeah. No. Input object object code invalid URL. That invalid URL. Couldn't fetch file from URL object object. Isn't that interesting? Because the URL to me is a is a string. Right? Yep. And found that URL. But this time, before all of this, I logged service external file is unavailable. Couldn't fetch file from URL object object, but it isn't. It is a string, and this is the string. Fascinating. I mean, let let's just, you know, I've been a bit cheeky here. Maybe we, go back to accessing files, and I do actually create it with this accountability object here. Yep. I'll take that. I'm pretty sure I know it's not needed. I know it's not needed. But that the error isn't saying something else is missing. You've triggered an unhandled rejection. You may okay. Yeah. Fine. Okay. True. So if we go if we try around this, right, and then we catch an error. We console dot log the error. And we send this. And We are expecting an error, which is fine. We've got 503 service unavailable. Why? Couldn't fetch file from URL. This is what's troubling me. Object object. Let's take a let's just take another look here. So import 1. I think I worked it out. No. That was quick. Goodness. It is an opt I did pass in an object, didn't I? But that's not what's being passed in in the in the reference. The import URL is a string and the body, which is a partial file that should have been passed in as a string. All you need to do, Kevin, is read. Read the docs. So read the There's another person here, and we still didn't get there. Yeah. Okay. Asset key. We got an asset key that time. Success. There should now be a file in the file library. Right? Correct. So we are loading it in. We are loading it in. Title, description, tags, file name disk, all grand, but Beautiful. What we also want to do is this. We want to, YOLO. I can't be bothered with all this. We'll just there we are. We'll take the asset key, then we'll read the new asset, and we'll return the data. So what we'll get back in in response to this is it will always import. So that's not ideal because if it already exists, we don't necessarily want to reimport it every time. But for the sake of this little demo, I think it's fine. Then we'll get the ID back. So now if I rebuild this and we run this again oh, it was still spinning up. What we should get back is the new file object indeed, including the ID. And the nice thing about this is, if I go to access control, public, and I turn on directors files actually, I don't even need to do that. If I go to httpsphzedm.ngrok.io, right, slash assets slash ID will get a you don't have permission to access this error. Right? But what I can do is go to the user, generate a token. Okay. Generate the token, save it, and I pin that to the URL. Nice. Access token equals. And there's our Hey. Merge directly, which is pretty which is pretty cool. That's very cool. To keep this easier, though, I'm actually going to change the permissions of the files collection. So then you net we never need to pass in, pass in the key. So public system collections, directors files, all access on. Great. So now that's public. So now we've done the endpoint. The job is to create the panel. So what we'll do here is npm run add. That should be pretty easy, I think. I say that. That's a dangerous Easy for you to say. He does it. I know. It's very easy for I I think you've got this, Kevin. I trust I believe. I trust in Bodie. Next week, when I'm when I'm driving again, things are gonna go terribly awry, and you're just gonna kick back and and relax and enjoy the experience. Oh, yeah. I know. Viewer. What did we call the previous attempt to an extension here? Snake GIF, find viewer, viewer. This is my custom panel. Now there is some text. Now what we need to do, I think what we'll do is we'll remove the options entirely, right, because we don't want any options. It'll be a standard panel. And inside of that panel, we are going to have button button. We no longer have text. That's not a prop that's being passed in anymore. We just deleted it. So what we'll do is we'll do a v button. No. We won't. We'll do a v let's talk about what all these v things are for a moment. Back in our docs here, back in our docs, we have, resources for building extensions, components. And we have this components playground. These are all of the directors components that are inside of the Data Studio are made available to extensions. So we have here v button, and this is the director's button inside of the director's app. So we we have an immediate availability of this v button component, which is, yeah, pretty, pretty nice. So we can access that straight away. So we can go v. I did just notice it was v button like this and we'll call this, not v. I keep going back to the button. Sorry. We're looking for No. That was right. No. Yeah. But we want the input because we want to put in the ID. Yes. Yes. Yes. Because we'll keep it easy. We'll we'll put, like, right now, manual ID of a game hit go Yeah. Rather than, Automating it. Yes. Pick pick it from a drop down because we're running we're running out of time. So v input to v model. So, what are we gonna do here? Export default. We're gonna do data return, and we'll call this ID. Like so. Then inside of here, we'll put in the v input with a model of ID. Then we'll say on key up dot enter fetch, game, GIF, get GIF, fetch, git. Cool. And we will add and this is not really an ideal way of of writing these, of course, but methods and we'll call this fetch GIF. Yeah. And we'll just console dot log or you know what? We'll alert with the this dot ID value. That's what we'll do for now just to test all of that works before we go too far. So we'll go in here. Oh, I need to sorry. Npm run build was the command there. Oh, error. Come on. What are you doing, error? What are you doing? After component panel component, we're missing a comma. Okay. NPM run build. Lovely. And we'll restart that. Also lovely. So let's refresh. Let's refresh. Just took a hot minute there. Insights. New panel. Viewer. No options available. Right? Because nothing happens to the panel itself. This, wonderful, is our panel and we'll say we'll save it. Hey, enter. Great. So this means we are able to do something with that. What we're gonna do with it is we're going to go back to our docs. We're gonna look at our composables for app extensions, which is what this is. I'm gonna just close out everything else for now. And we're gonna use API. And what this will do is it will allow us to make API calls, to our endpoints that are already authenticated. Though, to be fair, I believe this is a completely public endpoint, so it shouldn't matter much. But still, we'll do it as as it should be done. So what we're gonna do here is we are going to import use API. We are going to use this composable, like so, and then we can make our endpoints like and then we can make our calls like this. So we will make this async. And what we're gonna do is we're gonna post to slash importer/importer. And we have response dot data here. So all we're going to do is console dot log response dot data. Let's build. And this is all basically to get around that that security issue. Yeah. That course issue. I love that there's always just like a 6 step workaround to deal with course. Thank you. As opposed to just dealing with it head on. Yeah. So, we refreshed it. This is great. What's happened to my text box? What's happened to the text box? Is it no, but it's not. Where's my text box? Also, what's happened to this one? What's happening? Not seeing any errors. The API could not be found. Couldn't load extensions. Okeydokey. Have I missed a step? Have I rushed it again? Have I rushed a little bit? Oh, script setup. So we'll be using, we have to move this to script setup. And let's just take a quick look at how this I need to refactor this. Of course, we do, but that is fine. Async fetch GIF should just be able to, for the most part, come up here. We'll say, const fetch GIF equals a sync function like so. Then is that legit? Yeah. That is legit. And then so that's the methods. Then we have the data, which is the ID. So we will be import import ref from view. We'll create a new variable for that. We'll go const ID equals ref. Great. So we've handled that. Then we have props. And I believe the way to do props here is we say define props. Can we do this? I think we can do this. And all we care about here is show header, which to be honest, I do not care about. In theory, I've just refactored all of that. Let's take one more quick look, fetch GIF. So we have this dot ID. So we don't need that anymore. It'd be ID dot value, but we're not gonna alert it anyway. Kevin, watching your work is just fantastic, by the way. I love that I gave you this challenge and, like, everything has gone wrong. Okay. This is this is an Axios instance. I don't quite remember how it bloody works. So I think what we do here is we do, and I need to check, axios post. Oh, we do we literally just pass in the whole object as the second. Great. So in here, we're gonna do URL equals ID dot value. Okay. And then we have response dot data. Cool. So we'll console mock that. Alright. Let's rebuild that. Is it gonna complain this time? No, it bloody isn't. Docker Compose up. You give me a right workout here. Let's refresh, and we should now have access to use API. Now none of it's loading. Now it is. And there's our text box. Let's open up our dev tools. Of course, it didn't like the URL that was before. That was this panel here. Just testing that out. So in here Can I grab a screen? Pop it off at the side. Over here, yeah, we need a game ID. So we can do that here. Game ID. So we're not done yet because we're not gonna display it yet. If we hit enter, what's happened? Refused refused to load the images. No. No. No. That that's the old one. That's the old one. In fact, if I just remove that whole thing, we'll be better off for it. Let's refresh. See no errors. Let's paste that and let's hit enter. Nothing's happening. Why? Fetch GIF. Let's make sure this is ever running. You know what? This is all cute and all this. Let's just, just in case it's some silly async fetch gift, just in case it's some silly, async function, just in case it's something silly in the way that oh, I think it might have said invalid URL. I think it might. Do you wanna know why invalid URL? Because it isn't the full URL. We're just posting the ID. Oh, that's right. Yes. So what we'll do on the importer package is we're actually going to, we're gonna import req.body.url. Cool. So we're gonna make URL. Where is it? Here. Exported.battlesnake.comporter.battlesnake.games. And then here, req.body.idgamegame, maybe we call it. And in here, we pass in the earth. So now it needs a game. That's the value we need to pass going back to our panel. This is going to be game ID dot value. Let's rebuild the extension. Okay. Oh, yeah. We'll refresh. I do understand our network error showing there. Now we'll paste in the ID of the game. We'll hit enter. Oh, you know what we didn't do? We didn't open up dev tools. Let's skip to console. Wicked. Okay. We now have an ID of a directus I like, a directus asset in the ID. So all we need is the ID here. So this is the ID of the game, game ID, game ID, and then an image in here and the source of that image is going to be, how is this going to work? We need to just have a quick think about this. I'm gonna try something out. I think if we go /assets slash and then we need a value in here. So in here, we're gonna go image ID, and it's gonna be a ref and image ID dot value equals response dot data dot ID. Right? So Yep. Now this has the value in it of the ID, image ID. First thing we'll do here is just a quick v if image ID. We only wanna show it when that's the ID, and then here is going to be image ID. Let's see if that works. I'm not a 100% sure it will, but should do. I have faith oh, yep. There we go. I don't. Let's refresh. 1 of us has got 2. Great. ID is not defined. Why? Because ID dot value is gonna be game ID dot value. I'm feeling the heat, but I'm having a blast. I know. I was gonna say I feel like I gave you, like, the small challenge that became the much larger Yeah. But not not 145 in or whenever it was. That's not really the time to do it. But if we wait just a moment, nothing happens. Why? Console. Assets undefined 4 3. Fine. Let's figure out oh, image ID. Complete typo there. Remember this, Kevin. Remember this as the challenge comes next week. I'm having I'm having a blast. I really enjoyed last week, last episode. And now we have Hey. What is I? Kevin. Kevin. Kevin. Kevin. In an ideal world, you can obviously select from your existing games. It will handle all the logic for you. I think we're firmly out of time to do that this time around. Next time we and next time we won't be touching insights. But everyone, I hope you've had a wicked time. Any final remarks, Andrew? Thank you, Kevin, for taking on the challenge. Thank you all for watching. And be sure to tune in for our next episode of Ready. Ready. Set. Set. Battlesnake. Battlesnake. Nat, when you edit this, can you just time it so we get that right? Thank you. Bye.","published",[142,155],{"people_id":143},{"id":144,"first_name":145,"last_name":146,"avatar":147,"bio":148,"links":149},"e7311cbc-d404-4e18-83d9-bca26206057e","Andrew","MacLean","6ac0ee16-495a-4316-859f-1af70f83c618","Developer Relations Manager at DevCycle",[150,152],{"url":134,"service":151},"twitter",{"service":153,"url":154},"website","https://edulinqs.com/andrewdmaclean",{"people_id":156},{"id":157,"first_name":158,"last_name":159,"avatar":160,"bio":161,"links":162},"82b3f7e5-637b-4890-93b2-378b497d5dc6","Kevin","Lewis","a662f91b-1ee9-4277-8c9d-3ac1878e44ad","Director of Developer Experience at Directus",[163],{"url":131,"service":153},[],{"id":166,"number":167,"year":168,"episodes":169,"show":173},"398d2955-6ca4-4847-810d-a07f4f48a319",1,"2024",[170,171,122,172],"08d92984-9c2a-496d-a748-2ba54e64e378","7c58048d-ab8e-42cc-823d-541848ad4a7d","fa776fca-1f88-44ac-8c54-96232474282d",{"title":174,"tile":175},"Ready Set Battlesnake","a9af3e01-33c2-4e06-8836-bcb759570406",{"id":172,"slug":177,"season":166,"vimeo_id":178,"description":179,"tile":180,"length":181,"resources":182,"people":186,"episode_number":189,"published":190,"title":191,"video_transcript_html":192,"video_transcript_text":193,"content":8,"seo":8,"status":140,"episode_people":194,"recommendations":197},"toggle","925489400","In the season finale, Kevin and Andrew fly close to the sun to understand which snake strategies work best, by A/B testing live with DevCycle. Do they keep their wings?","b98c544a-5cc0-453f-bce6-d75614580ac3",105,[183],{"name":184,"url":185},"DevCycle","https://devcycle.com/",[187,188],{"name":130,"url":131},{"name":133,"url":134},4,"2024-05-02","Toggle","\u003Cp>Speaker 0: Hello, everybody.\u003C/p>\u003Cp>Speaker 1: Hello. I'm sorry, Kevin. Ready yet.\u003C/p>\u003Cp>Speaker 0: You are ready. Alright. Let's try this again. Alright. 3, 2, 1.\u003C/p>\u003Cp>Hello, everybody, and welcome to ready no. I\u003C/p>\u003Cp>Speaker 1: didn't know where to do that. We're gonna\u003C/p>\u003Cp>Speaker 0: do it. Ready. Ready. Set. Set.\u003C/p>\u003Cp>Battlesnake. I don't think we're gonna get it, Kevin. I don't think\u003C/p>\u003Cp>Speaker 1: we're gonna say the final episode of\u003C/p>\u003Cp>Speaker 0: Alright. We're gonna try this again. I feel like this is I feel like this is good for the final episode. Let's do this. For the final episode.\u003C/p>\u003Cp>Let's get this right. Welcome to the final episode of Ready set, set, battle mistake. Mistake. We're close enough. We got there.\u003C/p>\u003Cp>Speaker 1: Close enough.\u003C/p>\u003Cp>Speaker 0: We got there. I'm gonna count it. Alright. So welcome, everyone. Episode 4 of Ready, Set, Battlesnape.\u003C/p>\u003Cp>I'm Andrew. This person either down below or to my right or left. I don't know where he's he is right\u003C/p>\u003Cp>Speaker 1: now. Direction.\u003C/p>\u003Cp>Speaker 0: Is Kevin, and we are your your snake charmers, your code, your code coaches, your, your fun fans. I don't even know. But we are here today.\u003C/p>\u003Cp>Speaker 1: You are fully overestimating our entertainment value.\u003C/p>\u003Cp>Speaker 0: I I don't know what you're talking about. I feel like our entertainment value can never be underestimated. We are we are more entertaining than we even think. Thank you so much for coming back and checking this out, Kevin. Thank you so much for for coming back again after I kinda threw you, a little bit of a, a little bit of a challenge at the end of our our last episode together.\u003C/p>\u003Cp>Speaker 1: It was tough.\u003C/p>\u003Cp>Speaker 0: But we got there. I'm sure you'll return the favor to me today. Yeah. So if you haven't caught episodes 1, 2, and 3, you should probably go back and check those out. We, kind of we're gonna talk a little bit more about exactly what we've been doing, But, in episode 1, we built a Battlesnake, and we'll talk a little bit about Battlesnake kind of as we go through.\u003C/p>\u003Cp>Obviously, in episode 2, we implemented, that same logic from our 1st JavaScript starter snake in, Directus. In episode 3, we added a whole bunch more logic to our snake but mostly just to visualize the games that were coming through the platform. And today Kevin, do you know what we're doing today?\u003C/p>\u003Cp>Speaker 1: I I do, but I will let you I will let you share. I think it's your turn.\u003C/p>\u003Cp>Speaker 0: I think it is. I feel like you've been leading the show for the entire time. So it's probably my turn. Also, I feel like should I be let me see. I'm, like, wanting to be more centered.\u003C/p>\u003Cp>Oh, where are we? There we go. Now I'm feeling good.\u003C/p>\u003Cp>Speaker 1: Okay. Good.\u003C/p>\u003Cp>Speaker 0: Alright. I thought that, like, make make the choice to change where your camera is as you're as you're on on camera. Yeah. Screw it.\u003C/p>\u003Cp>Speaker 1: Why not?\u003C/p>\u003Cp>Speaker 0: Good vibes. Good vibes. So, on today's episode, we are going to be, implementing a new technology that we haven't really looked at, called Devcycle. And so, you now know from the last few episodes about what Battlesnake is. You know what Directus is because you're here on Directus TV.\u003C/p>\u003Cp>And so now is the time to introduce you to the technology that I work with on a daily basis as a developer advocate at Devcycle, which is a feature flag management platform. So our plan today is to try and add some logic to our, Directus snake to get this, working is maybe a relative term. Getting the the dev cycle platform yourself\u003C/p>\u003Cp>Speaker 1: a lot of scope there. A lot of scope. Working is a relative term.\u003C/p>\u003Cp>Speaker 0: But we're gonna use the dev cycle platform to, add a little bit of, add a little bit of flavor to our snake and give it a little bit of, give it a little bit of control. And that will make a lot more sense in a minute. But Kevin, you look like you have something to say.\u003C/p>\u003Cp>Speaker 1: I I mean, I'm gonna ask the question which I think you're probably gonna work towards, which is like, can we just talk for a moment about what feature flags are and then maybe what you had in mind, and then we launch straight in.\u003C/p>\u003Cp>Speaker 0: I love it. So, a feature flag, if you've never heard of them before, condition conditional statement in your code, that allows for you to, turn features on and off depending on a bunch of targeting criteria. So let's say you are working on a new feature on your platform, or a new feature maybe for your Battlesnake, and you're not quite ready to to roll that out in all of the games, you could add a feature flag. Just wrap it around the code and then through a feature management platform like DevCycle, you can say, for these kind of games, I want you to use kind of this logic. And for these kind of games, I want you to use these this logic.\u003C/p>\u003Cp>It's a really big part of things like trunk based development. So if you're moving from, like, branch based development where you're sort of, like, having features in branches that are long lived, and then we all had to deal with sort of, like, long lived branches and merging and dealing with merge conflicts. Mhmm. Feature flags are kind of a way to avoid those things just by constantly having your new features in code, and you can kind of decouple the code release from the feature release process.\u003C/p>\u003Cp>Speaker 1: Interesting. Okay. And just to embellish this with my understanding, and you can tell me if I'm wrong, they basically work. So you put these conditional statements in your code, and what triggers those is this feature management platform. And typically, you would do that with some form of either like AB testing where people get allotted into these random buckets or you can be a bit more pragmatic and say 5% of users are gonna have this conditional turned on and therefore get a new feature.\u003C/p>\u003Cp>And then we will also, like, we'll analyze their behavior as a result and decide whether it works, if people get it, and so on, rather than going it's an all or nothing kind of deal. Right?\u003C/p>\u003Cp>Speaker 0: You got it. You got it.\u003C/p>\u003Cp>Speaker 1: Got it.\u003C/p>\u003Cp>Speaker 0: That's it. Alright. Money. So Great. That is a very ambitious plan that I just laid out, by the way.\u003C/p>\u003Cp>I I feel as though may we get to a stage where we're able to, like, just determine, what kind of gameplay we're gonna have? That's possible. Maybe not in a 2 hour stream, but, we are gonna get Directus and Devcycle working together. How do I know they work together? Because I've already written a blog post on this separately from Battlesnake, so I got to explore.\u003C/p>\u003Cp>And so now is the time to use my knowledge for for good and for evil.\u003C/p>\u003Cp>Speaker 1: We'll link the blog post, by the way. We'll link the blog post. There are 2. There's 1 on our blog, that Esther wrote, which uses dev cycle, and 1 on the dev cycle blog, which you wrote, which is direct us. And I'll put a link to both of them in the resources section that accompany this video.\u003C/p>\u003Cp>Speaker 0: Yes. I love it. So, y'all are seeing my screen right now. And so up here, you'll notice that this looks very similar, to, 1, mister Kevin Lewis's screen, although not in the Arc browser. I'm not apparently a strong enough, software developer to use Arc.\u003C/p>\u003Cp>Not there yet. Once it comes to Windows, I'll start using it. It's it's it's happening. I know it's coming. I'm in a month of this.\u003C/p>\u003Cp>Speaker 1: And then people will full on get this, but we're clearly recording this a day after the last one because they these are the games from the last episode they created about 23 3 hours ago, which is completely legit. We did something a little cheeky before this stream. We in a completely low rim fashion, you're running a director's to project. And I literally was like, here's a sequel database file and here's the extensions. Go run them and here's the creds I used to go log in.\u003C/p>\u003Cp>We may have to reconcile with that at some point when things break. So there is a chance things won't behave and we'll have to fix that on the fly, but should be okay.\u003C/p>\u003Cp>Speaker 0: I love it. So we have our snake our direct to snake here. It's alive. It works. Not yet.\u003C/p>\u003Cp>We haven't determined if it works yet, which we probably will have to do. I also have our snake that was running on Replit. So the original, ready set battle snake that we created from the JavaScript starter snake. So Mhmm. I have that snake, but Replit was getting real mad at me today because I was using too much RAM and and compute.\u003C/p>\u003Cp>So I pulled that down, and put it into this wonderful, repo here. Yes, sir.\u003C/p>\u003Cp>Speaker 1: And you're gonna be bumping your font size up about 5 times.\u003C/p>\u003Cp>Speaker 0: No. We're gonna expect everyone to to zoom in. Exactly. Exactly. That's the look of the look at\u003C/p>\u003Cp>Speaker 1: my spectacles.\u003C/p>\u003Cp>Speaker 0: Everyone has. And so, yeah, let's let's zoom in here a little bit. Alright. So this is the the kind of the original snake that our code is based off. So you will notice here that not all the logic that we implemented over the past couple of episodes are in here.\u003C/p>\u003Cp>That's fine. This is more just to, like, show us how it's gonna work once we get there, and then we're gonna implement this indirect disk. We're gonna try and implement it in direct disk. But I think maybe the first thing we should do, Kevin, is actually get our Directus snake working. What do you think?\u003C/p>\u003Cp>I feel like that's a logical first step.\u003C/p>\u003Cp>Speaker 1: And what we're gonna do to make that happen is we're gonna set up ngrok. And so do you pay for ngrok?\u003C/p>\u003Cp>Speaker 0: I don't, but I have ngrok. So, like, I can I can set it up right now, but it'll be ephemeral?\u003C/p>\u003Cp>Speaker 1: Incredibly heavily, like, rate limit to you. Let's pause here. Let's get NGROC set up and using temporarily my auth token, and then we will come back. Great. So this bit, we won't we won't publish.\u003C/p>\u003Cp>But, yeah, it was actually the one thing we forgot before we started. So let me just figure that out.\u003C/p>\u003Cp>Speaker 0: Yeah. Throw me the key and then I can,\u003C/p>\u003Cp>Speaker 1: Indeed.\u003C/p>\u003Cp>Speaker 0: Alright. And let me just go to engrok now because I was actually logged in earlier. It was working for me in the games that I was playing, but,\u003C/p>\u003Cp>Speaker 1: it but then it gets mad. That's the whole problem here. So what we want here is your auth token. So, here is the engrok command you are going to want to run here in the chat. Yep.\u003C/p>\u003Cp>Speaker 0: Sorry. I'm just\u003C/p>\u003Cp>Speaker 1: then because I'm on, like, old, the command looks slightly different, and that's there.\u003C/p>\u003Cp>Speaker 0: Where are you hiding? Hold on. My windows have all disappeared. Where are you, Kevin? There you are, in chat here.\u003C/p>\u003Cp>Alright. Wonderful. There's a chat. Here's a command. We're gonna add this auth token.\u003C/p>\u003Cp>Beautiful. And we're gonna head back over here to our terminal and oh, nice. There we go. Paste. Beautiful.\u003C/p>\u003Cp>Auth token saved, and let's run\u003C/p>\u003Cp>Speaker 1: Nice. This.\u003C/p>\u003Cp>Speaker 0: It's good. I set up ng croc earlier.\u003C/p>\u003Cp>Speaker 1: I knew Yeah. Yeah. Absolutely.\u003C/p>\u003Cp>Speaker 0: Beautiful. Alright.\u003C/p>\u003Cp>Speaker 1: Good. So I think we can actually snap back now, and Yep. It's up to you what you want on the screen. We could be here if you want.\u003C/p>\u003Cp>Speaker 0: Yeah. I mean, I mean, if you've never used ngrok before, I mean, we talked about this in episode, I guess, 2. We were looking at this. I have the free version. Kevin's got one that's less rate limited, so we're using that one.\u003C/p>\u003Cp>But it's super easy to install. Like, just homebrew it, and then you add your auth token to ensure things are happening. But, anyways, we've got it running right now. And then my direct to snake over here is should technically be working. Now, Kevin, I'm really curious.\u003C/p>\u003Cp>You should technically be able to go and run a game on yours, and see if it works. And I'm interested I think\u003C/p>\u003Cp>Speaker 1: Are you running directors?\u003C/p>\u003Cp>Speaker 0: Apparently, I am not. I think I might have closed it. Nope. I'm running it. Yep.\u003C/p>\u003Cp>We're all good. Where is it running though? That's the real oh, you know it's running in another one.\u003C/p>\u003Cp>Speaker 1: Do you have another\u003C/p>\u003Cp>Speaker 0: I do.\u003C/p>\u003Cp>Speaker 1: Versus code do. Window. There it is. Awesome. So we're gonna watch\u003C/p>\u003Cp>Speaker 0: these logs here. We're gonna bump Shall\u003C/p>\u003Cp>Speaker 1: we whack the font size up there as well? So I'll add ready set battlesnake and hungry bot once again to an 11 by 11 board. I'll hit start game.\u003C/p>\u003Cp>Speaker 0: Yeah. And there we go. It's coming through. Awesome. We're working.\u003C/p>\u003Cp>And you're like, but Andrew and Kevin, we can't see the games, and therefore, this isn't fun and enjoyable for us. Us. Fear not. Because I think actually an easy way to do this so we can keep ready, set, battlesnake in your repo. Can you make ready, set, battles cake public so that I can add him to my Yeah.\u003C/p>\u003Cp>Speaker 1: I can. Yeah. My battlesnakes. Ready set battles cake. We named it that.\u003C/p>\u003Cp>So it had a k instead of an n because it was the Kevin version of the snake as an FYI, and it is now public.\u003C/p>\u003Cp>Speaker 0: Awesome. And so if you're ever in the Battlesnake platform, really easy. All you gotta do is just search for snake. Ready, set. Should find him skate.\u003C/p>\u003Cp>There we go. That's what we want it to look like. And so now we've got them in there. And now we're gonna see this game going on, and it should be all of our logic and direct us. Something's not happening.\u003C/p>\u003Cp>Something's unhappy here. Let's see what it is.\u003C/p>\u003Cp>Speaker 1: Womp womp.\u003C/p>\u003Cp>Speaker 0: I love that we tried and then we failed.\u003C/p>\u003Cp>Speaker 1: Could you remove the what the old one password, pop up?\u003C/p>\u003Cp>Speaker 0: I certainly can. Okay. There we go. Oh, no. Nope.\u003C/p>\u003Cp>Same thing happened again, actually. Create Rematch.\u003C/p>\u003Cp>Speaker 1: So let's think it through. What is going wrong here? It could be that our flow isn't running correctly, but it should be. Yeah. Like, it's going off.\u003C/p>\u003Cp>It's triggering the flows. It's getting a 200, which means it's getting a response, and it's returning. So what is going what is going on?\u003C/p>\u003Cp>Speaker 0: What is going on? We haven't gotten Because\u003C/p>\u003Cp>Speaker 1: it was randomly breaking last time too. At the end of session 2, at the end of the second episode, our snake was, like, overpowered. Like, it was so good, and then it started to crumble. It started to grumble, last time.\u003C/p>\u003Cp>Speaker 0: Let's take a look at our logs. We have got some logs in here. Holy moly.\u003C/p>\u003Cp>Speaker 1: We do.\u003C/p>\u003Cp>Speaker 0: Let's look here. So is there anything going on in here? We've got move now. Original. Yeah.\u003C/p>\u003Cp>So I think we've got something going on there. Some so what do we have here? Yes. Feeding a lot of things there. False, false, false, false.\u003C/p>\u003Cp>Oh, no safe moves. Avoid head to head. I think it might be in there. False, false, false, true, true. Yeah.\u003C/p>\u003Cp>I think the issue is in\u003C/p>\u003Cp>Speaker 1: Which we've already determined that we think is the case. So you know what we'll do to keep ourselves moving? If you close the pane, why don't we just avoid that entire operation and just take avoid body straight to determine move? Avoid head to head is a, you have to just hit the little edit in the top right of the Oh,\u003C/p>\u003Cp>Speaker 0: of course, we do see.\u003C/p>\u003Cp>Speaker 1: Yeah. And hopefully yeah. If we just do that and hit save, yeah, just yeah.\u003C/p>\u003Cp>Speaker 0: Oh, we're back. We are back. We're back. It's alright. We're there.\u003C/p>\u003Cp>I have a belief that if you just hit the save button enough times, we're gonna be able to resolve.\u003C/p>\u003Cp>Speaker 1: I'm pretty sure that's the definition of insanity. I\u003C/p>\u003Cp>Speaker 0: think it is too. We're gonna switch things up for just a minute. Yeah.\u003C/p>\u003Cp>Speaker 1: And save\u003C/p>\u003Cp>Speaker 0: this, and that didn't work. And then we're going to go back over here. And then we're going to go back here. And we're going to see if that worked. Oh, disk.\u003C/p>\u003Cp>It was a bug.\u003C/p>\u003Cp>Speaker 1: It was a bug, by the way. And it had an issue has been opened on this bug. So there you go. Maybe just discard the changes and just we can have\u003C/p>\u003Cp>Speaker 0: Alright.\u003C/p>\u003Cp>Speaker 1: Let's see\u003C/p>\u003Cp>Speaker 0: if we can create another game, see if this will do it. I mean Okay. The oh, nope. Still doing the same thing. Still so moving out of bounds, logic is there.\u003C/p>\u003Cp>It's definitely happening in 2 minutes ago. Let's get You\u003C/p>\u003Cp>Speaker 1: have to refresh. Sorry.\u003C/p>\u003Cp>Speaker 0: Alright. So let's go here, and let's see again. So determine move is still where things are, yeah, getting hung up.\u003C/p>\u003Cp>Speaker 1: Oh, and you're saying avoid head to head is where everything went to force when they're logically, it should not been happening.\u003C/p>\u003Cp>Speaker 0: I think so. Maybe that's what it is. Let's go avoid head to head options. There we go. False, false, false, false.\u003C/p>\u003Cp>Payload. Avoid bodies.\u003C/p>\u003Cp>Speaker 1: Okay. So so you know what we're gonna do? We're gonna jump into avoid head to head, and we're just gonna return the inbound date. Like, we're not gonna do anything.\u003C/p>\u003Cp>Speaker 0: Alright. Let's go in there and do that. So here we go.\u003C/p>\u003Cp>Speaker 1: Right. Because that's clearly where it were. Yeah. We're gonna literally delete everything apart from line 2 and 30. So everything in the middle there, ditch it off.\u003C/p>\u003Cp>Doesn't matter.\u003C/p>\u003Cp>Speaker 0: Can we not just oh, we can't comment. Really?\u003C/p>\u003Cp>Speaker 1: I think no. So just but it's fine. We don't need it. This is this is the last episode. There we go.\u003C/p>\u003Cp>I also have a copy of it, so it's fine.\u003C/p>\u003Cp>Speaker 0: Ah, success. Alright. So let's save this and see if it works. There we go. And now let's go and try and recreate a game again.\u003C/p>\u003Cp>Speaker 1: Because if that's the step that was causing grief.\u003C/p>\u003Cp>Speaker 0: It was. Yep. Do\u003C/p>\u003Cp>Speaker 1: you remember when I wrote all that really elegant code and it worked fantastically? Turns out not so much.\u003C/p>\u003Cp>Speaker 0: Well, it's alright. It worked fantastically until it didn't. And that is the key to all the programming. It's all good until, you crash production.\u003C/p>\u003Cp>Speaker 1: Okay. That makes me feel better that we've identified the issue and removed it for now.\u003C/p>\u003Cp>Speaker 0: Okay. So ready, set, battlescape is working, and this is really the key here. It's still doing the job that it needs to do. So we're gonna make, we're gonna do something a little bit different now. We are going to actually be, having we're gonna bring ready set battlesnake back from the dead, in a new world.\u003C/p>\u003Cp>So let's, let's kinda go over here. So this is good. Directus is working, and now we're gonna we're gonna ignore that Directus even exists for the next little while. And we're actually gonna head back over to\u003C/p>\u003Cp>Speaker 1: Who needs to pay rent?\u003C/p>\u003Cp>Speaker 0: Who needs to pay rent? Not me today. And I wanna look at, wanna look at our code here. And so is this okay for you, Kevin, or is it still too small?\u003C/p>\u003Cp>Speaker 1: Yeah. Maybe take up another yeah. Maybe that maybe that's good, I think, for people watching.\u003C/p>\u003Cp>Speaker 0: Awesome. So in here, not a lot has changed from when we were dealing in replit. So we still have our server dotjs, which is just an express server. We've got the 4 endpoints, the sort of root endpoint, start, move, end, and then we've got a bunch of stuff in here that's kind of, yeah, talking about what it's returning. We've got a read me here, which explains just how this works, which we don't really care about right now.\u003C/p>\u003Cp>And then we've got our package. Json. I haven't added anything new to here except for this new dependency, which is the dev cycle, SDK. And so this is necessary for us to implement dev cycle. If we want to do it this way, technically, we could do all of this via our management and bucketing APIs, but I think it's cleaner through the through the SDK.\u003C/p>\u003Cp>And then, there's some small changes. There's another file that's here, and we'll maybe call this in just a second. And I'll explain how I got to this file, which was not fun this morning when I was prepping for the show. So, originally, in here, we had our run server. We had our info endpoint.\u003C/p>\u003Cp>We had our start and end endpoints. And then we had this move endpoint, which actually had some really good logic inside, that if we go and ignore all of this stuff, here was our original logic. And I'm gonna uncomment all of this stuff. Oh, I'm gonna try and uncomment all of this stuff if I actually uncomment the right section. There we go.\u003C/p>\u003Cp>So this was our original logic. And I'm actually think just to make sure that this is working because, yeah, I've changed this so it wasn't async now, which was part of my issue earlier. I'm gonna save this. So this was sort of our dumb snake that we first started with. So Not dumb.\u003C/p>\u003Cp>Yeah. But, like, dumber. And so you can see here all of our steps have kind of been implemented here. The base steps here, same thing that's going on over in Directus. Disk.\u003C/p>\u003Cp>So let's see if this is working. I'm gonna run this express server. I think it's node index dotjs. So this is gonna run\u003C/p>\u003Cp>Speaker 1: How are you gonna expose this as a Battlesnake if we're already running ngrok for directors?\u003C/p>\u003Cp>Speaker 0: Oh my good guy. Also, updated cache direction to down. It is constantly running that caching. Interesting. That's fun.\u003C/p>\u003Cp>Speaker 1: So the caching wasn't originally there, Andrew. So Wasn't. And please tell us about the cursed file.\u003C/p>\u003Cp>Speaker 0: So we're gonna ignore the cursed file for a minute, and then we'll get to the cursed file. But let's see if we run this right now. Technically, I should be able to run 2, right, through engronk?\u003C/p>\u003Cp>Speaker 1: I'm not convinced, but we'll we'll find out.\u003C/p>\u003Cp>Speaker 0: Okay. What port does Directus run on?\u003C/p>\u003Cp>Speaker 1: Not that one.\u003C/p>\u003Cp>Speaker 0: K. Well, let's see if this works. No. It works. It's there.\u003C/p>\u003Cp>Speaker 1: No. No. No.\u003C/p>\u003Cp>Speaker 0: No. No. No. No. No.\u003C/p>\u003Cp>No. No. No.\u003C/p>\u003Cp>Speaker 1: Locally, but you still have to expose it.\u003C/p>\u003Cp>Speaker 0: Yes. So can you see if one shows up in your, is it list it'll show up on your ngrok dashboard on your end if it's running.\u003C/p>\u003Cp>Speaker 1: I didn't even know there was an ngrok dash I didn't even know there was an ngrok dashboard.\u003C/p>\u003Cp>Speaker 0: We'll see. But yeah.\u003C/p>\u003Cp>Speaker 1: Let's take a look.\u003C/p>\u003Cp>Speaker 0: So behind the scenes, I'll actually pull this up just so people can see what this looks like. So when you go to the ngrok dashboard and you're logged in, if I am logged in, so you have, like, this authentication and set up stuff. And then you also have this tunnel section. And in the tunnels, I think it's tunnels where it actually shows you, yeah, what are currently online in your account. Account.\u003C/p>\u003Cp>And so you should see you should see\u003C/p>\u003Cp>Speaker 1: I've got one.\u003C/p>\u003Cp>Speaker 0: You've got one? K. So this is not doing what we wanted to do. Wait.\u003C/p>\u003Cp>Speaker 1: Wait. Wait. Wait. No. No.\u003C/p>\u003Cp>Yeah. And the one is you. Oh, it is? Yeah. Started 10 minutes ago.\u003C/p>\u003Cp>I'm not running anything locally.\u003C/p>\u003Cp>Speaker 0: That's that's Directus, though. That's why.\u003C/p>\u003Cp>Speaker 1: That's directives.\u003C/p>\u003Cp>Speaker 0: Okay. So here's what we're gonna do. And now we need\u003C/p>\u003Cp>Speaker 1: to try and run it a second time, but I'm not convinced.\u003C/p>\u003Cp>Speaker 0: We can shut down directives for right now because we don't need it as we're just kinda demonstrating how this works in the index dot JS. So we're gonna shut down Directus for a second, and then we're gonna run it over on our other one. Alright. So we've shut down Directus, and let's go back over to index dot j s. Let's cancel this out and awesome.\u003C/p>\u003Cp>Restarted that. What is the address that I'm wanting to go to, Kevin? Can you paste it somewhere for me?\u003C/p>\u003Cp>Speaker 1: I don't understand what you're asking.\u003C/p>\u003Cp>Speaker 0: Never mind.\u003C/p>\u003Cp>Speaker 1: I But, also\u003C/p>\u003Cp>Speaker 0: yeah. I've But you're not running ngrok yet. Right? Oh, that's right. I have to rerun.\u003C/p>\u003Cp>No. I am running it.\u003C/p>\u003Cp>Speaker 1: You need to rerun it.\u003C/p>\u003Cp>Speaker 0: Exactly. Rerun ngrok. Yeah. Oh, there we go.\u003C/p>\u003Cp>Speaker 1: Got it.\u003C/p>\u003Cp>Speaker 0: Bad things happening. Okay. Let's go\u003C/p>\u003Cp>Speaker 1: But this time, not 8,055. Yeah. Yeah.\u003C/p>\u003Cp>Speaker 0: 8000. Alright. Here we go. Beautiful. Alright.\u003C/p>\u003Cp>Alright. So let's go over here and see if this is working. Beautiful. Alright. So this is running now.\u003C/p>\u003Cp>So if I go back over here to account settings oh, not account settings. My battle snakes. I'm gonna go ready set battlesnake, and we're gonna leave a JavaScript, and we're gonna have this on nothing, no platform today, and then we're gonna change our server URL. Yes. Like that.\u003C/p>\u003Cp>And now if I go in and add ready set set, Battlesnake to a game, create game. And ready to set Battlesnake.\u003C/p>\u003Cp>Speaker 1: Remove the Octa thing in the top right? It's very annoying.\u003C/p>\u003Cp>Speaker 0: My goodness. All of the prompts. And then we are going to see if this runs. Okay. Good.\u003C/p>\u003Cp>Basic logic, not running into himself, not running into walls. Good. So he's working. Alright. But I haven't implemented the logic for dev cycle yet.\u003C/p>\u003Cp>So let's go look at what's going on. So we've got the moves that are feeding through there. That's awesome. That's what we want. I'm gonna actually turn this off for a second, and then turn it back on.\u003C/p>\u003Cp>No. I'm not gonna turn it back on because it's gonna constantly need to be caching. Okay. So, that's our basic code. Right?\u003C/p>\u003Cp>We're good. We're there. We're not here for basic code today. We are here for confusing broken code that will cause many problems and will make our heads hurt.\u003C/p>\u003Cp>Speaker 1: You're really teeing this up, and I'm horrified before we've started.\u003C/p>\u003Cp>Speaker 0: Don't worry. You and me both. So let's look at the new logic that I have in here, which is not great logic, but, I'll explain it. So, what we're doing is every time the move endpoint is called, this move function is called. Yes?\u003C/p>\u003Cp>Everybody should track that so far. So what I'm doing here is I am calling a, this get cache direction function, which is basically every second or millisecond. I'm not sure. I think it might be millisecond. It's calling the dev cycle, platform and asking what move should I be getting for whatever user is on the platform right now.\u003C/p>\u003Cp>This will all make sense when you kinda see the logic, but, basically, it's it's pulling the dev cycle platform to ask it what move you should be making as a snake. Does that make sense? Yeah. I think your face\u003C/p>\u003Cp>Speaker 1: Unfortunately, this isn't even remotely the direction I thought we could go in.\u003C/p>\u003Cp>Speaker 0: No. Don't worry. We're not gonna we're not gonna manually we're not gonna manually do this. We're I just wanna demonstrate the, like, how it actually functions. And so this is good.\u003C/p>\u003Cp>Speaker 1: Mhmm.\u003C/p>\u003Cp>Speaker 0: And I actually you can do it mid game too as long as your your click game is is on point. Oh, man. Which we can do today because there's 2 of us here. So Oh my god. We're gonna go and actually look in this cache dotjs file.\u003C/p>\u003Cp>So here's our cache.js file. Couple things happening here. First thing, we're importing the server SDK that this dev cycle from there. Then we're initializing our dev cycle, client in here, despite it being a server application, we're calling it a dev cycle client. This stuff is That's fine.\u003C/p>\u003Cp>That makes sense. Yeah. This stuff isn't super important, the cloud bucketing and enable EdgeDB. It is and isn't, but really the important thing here is that we're initializing the dev cycle client. We're creating this cached direction, which is setting the default move for our snake to go down.\u003C/p>\u003Cp>So, basically, if, the first time, if there's been no caching, if this has never run before, it's gonna go down. And then, yeah, within this function, we're feeding in the user variable. So you have to feed this in every single time that you, that you do anything with the external platform. You have to feed to the user. You can feed in custom properties, which we may try and do today, where you can, like, base it on different information that you may have.\u003C/p>\u003Cp>But this is the idea here. And then once we've got this dev cycle, client established, we're then going to look for a specific variable that exists in the Dev cycle platform. Think of a variable as, like, the feature flag that you're looking to pull. So whether you're wanting to see on or off, we're actually pulling a string. So we're pulling for the direction for this user.\u003C/p>\u003Cp>What should this user be seeing if we're looking for the direction variable that's in there? And then we've got if we do end up having a preferred direction. Yeah. Because where's my preferred direction defined? I think it was defined over here.\u003C/p>\u003Cp>Right? Yes. There we go. So, preferred direction. So, basically, it's saying that if there is the DevSecLE client being established and it finds that that direction variable exists, then we're gonna look for that preferred direction variable that we had defined over an index.js.\u003C/p>\u003Cp>And if it returns anything but none, it's going to put a new cache direction value in there, and then it's gonna log that it's updated the cache direction. Otherwise, it's gonna give you an error. And then if we go down here, yeah. We're basically updating this every 10 it's not ten seconds. This is, like, every 10 milliseconds.\u003C/p>\u003Cp>Speaker 1: That's very, very often. Very often. So a1000 is one second.\u003C/p>\u003Cp>Speaker 0: Yep. And then I gotcha. Yeah. So this is our code that we're doing here. Basically, we're just constantly pulling the dev cycle platform to, like, get the latest updated stage.\u003C/p>\u003Cp>So there's a little bit of a delay here, but it works pretty well.\u003C/p>\u003Cp>Speaker 1: I will believe it when I see it. Gonna be honest, mate. Okay.\u003C/p>\u003Cp>Speaker 0: Alright. You're like, this is garbage spaghetti code. What are you doing, Andrew? It's not like it's not the code.\u003C/p>\u003Cp>Speaker 1: It's just this isn't how I would have. Can I give you maybe an idea of how else\u003C/p>\u003Cp>Speaker 0: we could have implemented this sort of code? Yeah. Let's yeah. Let's go.\u003C/p>\u003Cp>Speaker 1: We literally just have, like, branching logic in the flow. And based on, like, there's the snake gets an ID for every game. So you can enroll them and then, like, 10% of the time or whatever, they get thrown into, like, strategy 2. And strategy 2 could be it become it just goes left all the time. Like, it doesn't matter.\u003C/p>\u003Cp>Yeah. But you could implement branching logic. Right?\u003C/p>\u003Cp>Speaker 0: So we are and that is what we are gonna do. So you're not wrong with that. I just wanna show how this works.\u003C/p>\u003Cp>Speaker 1: That's fine. Okay.\u003C/p>\u003Cp>Speaker 0: Then we can get into the logic. So Okay. That's our logic here. So, basically, we're calling this every 10 seconds, and then it's gonna if it's updating, it's gonna show us this using cache direction, and then it's gonna do that.\u003C/p>\u003Cp>Speaker 1: And just to clarify, the whole reason you've created this notion of a cache direction is so we're not gonna go to dev cycle every single move. We will go a 100 times a second instead.\u003C/p>\u003Cp>Speaker 0: So what's what's interesting is because we're basically running an async method here, there's a delay and devs battle sync doesn't like there being any sort of a delay. So I had to I completely got it. So you\u003C/p>\u003Cp>Speaker 1: have to have some I got it.\u003C/p>\u003Cp>Speaker 0: Yeah. You've gotta do the polling yourself. I think you probably if I was a better programmer, I could probably figure it out, but this was like No.\u003C/p>\u003Cp>Speaker 1: No. I I I get it now because you could call dev cycle every time, but you're not gonna be able to respond within 500 milliseconds confidently. Yes. So for that reason, instead, we will catch the last direction it gave you. Exactly.\u003C/p>\u003Cp>I got it. I got it. That makes sense. Fine. You're I'm with you.\u003C/p>\u003Cp>And\u003C/p>\u003Cp>Speaker 0: it's interesting. The reason I figured out that this was working is so if you notice here, in the logs, so we actually it returns move 117 right. What I was seeing in my logs was it would be like move 01746328. And so it was taking time to actually do the the the calculation. So anyways\u003C/p>\u003Cp>Speaker 1: Which is no good for the snake. It just won't work. Yeah. And so\u003C/p>\u003Cp>Speaker 0: I'm gonna leave this I'm gonna leave this at, at 10 milliseconds for right now, now only because I'm running on my own device, and I think your end grunt won't get upset at me. And because I know that it will demonstrate how this works. The downside here is I actually, Kevin, will need you to be the one that is starting no. Because nobody's gonna be able to see it. Okay.\u003C/p>\u003Cp>We're gonna see how fast Andrew can click things is what we're actually gonna see. So we're gonna start this again. So if everything's working properly over here, I've uncom oh, I've gotta uncomment this. Let me cancel that again. Let's uncomment that import statement.\u003C/p>\u003Cp>I think all the rest of this logic has already been commented. Awesome. So now if we run this yeah. So we're basically checking this, like, every 10 milliseconds. It's kind of crazy.\u003C/p>\u003Cp>I don't fully know why I don't think it's running every time it shouldn't be.\u003C/p>\u003Cp>Speaker 1: I'm unsure logging every time it's making your terminal choke.\u003C/p>\u003Cp>Speaker 0: Here's my question though, is we're not calling move all the time. So I'm confused why\u003C/p>\u003Cp>Speaker 1: That's a good point.\u003C/p>\u003Cp>Speaker 0: Get cache direction is being called every single time because it shouldn't be. It should just, like, literally only be called when moved unless I've got a game running somewhere. Do I have a game running somewhere?\u003C/p>\u003Cp>Speaker 1: You shouldn't be. No. I don't even know how you would check that.\u003C/p>\u003Cp>Speaker 0: Yeah. I don't know either. But, like, if I look at this okay. Request made.\u003C/p>\u003Cp>Speaker 1: Oh, are you the squiggly brackets? Yes. The destructuring.\u003C/p>\u003Cp>Speaker 0: I shouldn't have done that. Alright. So, yeah, it should not be running. It should be running every time. What is going on here?\u003C/p>\u003Cp>It must be something in this actual cache file. Let's see what's going on here. Import dev cycle, initialize dev cycle, let cash direction go down, update cash direction, import dev cycle.\u003C/p>\u003Cp>Speaker 1: Yeah. Because you're set into it here on line 33. So that's happening regardless. That's happening the moment it's imported. That's not linked to that function running.\u003C/p>\u003Cp>I don't think it's that much of an issue.\u003C/p>\u003Cp>Speaker 0: I'm gonna change this to, like, a 100 because what's that?\u003C/p>\u003Cp>Speaker 1: That would've that was gonna be my only suggestion is maybe just knock it knock it down a bit. Okay.\u003C/p>\u003Cp>Speaker 0: Yeah. Anyways, we're gonna do this. We're not gonna do a lot of this, because it's gonna be less important. But, we're gonna set this running, and then we're gonna go and actually take a look at the game. So here we go.\u003C/p>\u003Cp>So we're basically changing this direction, and I'll actually actually, let me cancel that for a second. And I'll go to the dev cycle platform so I can show you. I already set this up.\u003C/p>\u003Cp>Speaker 1: Yeah. Yeah. Yeah. That'd be good.\u003C/p>\u003Cp>Speaker 0: Here are the dev cycle form. Once I log in once it logs in come on, dev cycle. What are you doing? Oh, there we go. Logged into the wrong one.\u003C/p>\u003Cp>So we actually just launched a, a bunch of new example apps, and so I've been playing around with those. But there's no way to log out without, getting rid of the the demo mode. So, that's how we're gonna log out.\u003C/p>\u003Cp>Speaker 1: I feel like it's like a user retention is great if the user can ever log out, get a life hack.\u003C/p>\u003Cp>Speaker 0: All right. Let's close these again, see if I close this. And let's try app.devcycle.com again. And I think this is gonna load. Yeah.\u003C/p>\u003Cp>There we go. Awesome. Log in with my work count. It's gonna bring us over to the dev cycle platform, all of our production stuff. We're not gonna mess with our production stuff today.\u003C/p>\u003Cp>Speaker 1: Do it. Do it. Let your intrusive thoughts win.\u003C/p>\u003Cp>Speaker 0: So I did it at, at KubeCon. I actually we made a bunch of live changes while we were doing demos, and our entire engineering team got very unhappy with us. And so I think we're ready to set Battlesnake. And I've got this features area here. So I've got a feature that I've set up called my choose move feature.\u003C/p>\u003Cp>And this is Could you,\u003C/p>\u003Cp>Speaker 1: zoom in, sorry, 1 or 2 times? No. That's okay. The small text is quite small. We're good.\u003C/p>\u003Cp>Nice. Thank\u003C/p>\u003Cp>Speaker 0: you. Perfect. Yeah. So we've got our choose move feature. This isn't super important for us right now because I've only got one feature.\u003C/p>\u003Cp>And then I've got this direction variable that I have there, and I've defined 4 different variations, left, right, up, and down. These are string variables that are in there. And then in my targeting logic, I'm basically saying who to serve what or what to serve to what users that are feeding into that SDK. So here, I'm basically saying serve all of the users down, but that's also my default. So I actually want to be serving to see if this is working and actually talking right.\u003C/p>\u003Cp>I'm going to change this to serve everything right. And if this is working now, when I turn on that Battlesake server, I should be seeing everything in this updated cache direction except for the first one showing as right. So let's see if that works. There we go. And even the first one did.\u003C/p>\u003Cp>So we've got the changes happening here. And now if I go back over to the platform, change this to up and save and then take a look at my logs. And so it's like real time changes that are happening in there that you're able to kind of differentiate what's going on. So the interesting thing here is that, technically, platform to control your snake in real time. It's a terrible idea.\u003C/p>\u003Cp>Speaker 1: That is literally the like, like, we've seen people play Battlesnake live using, like, games controllers. And even that, you're like, well, there are some questionable choices here. This is like drop down and then save.\u003C/p>\u003Cp>Speaker 0: So but I'll show you something inter I'll see if I can get this to work, and I'll just do a I started using, there we go. So I started using, rectangle, and\u003C/p>\u003Cp>Speaker 1: Sure.\u003C/p>\u003Cp>Speaker 0: I can't believe that I've never used it, anything like that. Oh, yeah.\u003C/p>\u003Cp>Speaker 1: I use Raycast for it, and I have keyboard shortcuts. Oh, look at you. Which is really, really nice.\u003C/p>\u003Cp>Speaker 0: So let's grab ready set battle sneak in here. And we're gonna go start gaming. Just ready set battle in here. And so you'll see it's not gonna work right now because it's not running. So he's going up.\u003C/p>\u003Cp>So we know it's not down. There's no conversations that are happening right there. So since we know that we've set our game mode to, let's change it to left so we know that something's working here, and then I'm gonna start my server. And now if I create a rematch, should go left. Awesome.\u003C/p>\u003Cp>So we know that it's working. Sure. Alright. So now I'm gonna do the thing that is, like, the test of Andrew's ability to click things really fast. I'm gonna create a rematch.\u003C/p>\u003Cp>And then in, like, real time, I'm gonna click save. And there should be a switch if the board is big enough. But, actually, I need a bigger board because that will give me more time for things to go wrong. Let's go 19 by 19. Add, ready, set, Battlesnake.\u003C/p>\u003Cp>Start game. Oh, I shouldn't have done that. Anyways, it's fine.\u003C/p>\u003Cp>Speaker 1: You've done that. You you moved moved.\u003C/p>\u003Cp>Speaker 0: Do do do do do. No. It's too late. The game already runs as soon as you click create rematch, so I gotta be a super fast. Alright.\u003C/p>\u003Cp>Here we go. So right now, he's set to go left. I wanna change it so he goes\u003C/p>\u003Cp>Speaker 1: Don't worry about hitting play. Just hit create rematch, hit save, and we can see it in the playback that it's happened.\u003C/p>\u003Cp>Speaker 0: Alright. Here we go. There we go. Oh, and he's going left first. So literally, the worst example\u003C/p>\u003Cp>Speaker 1: that ain't gonna work. Before you create rematch before, you wanna yeah. Prime. Prime. Oh, yeah.\u003C/p>\u003Cp>Change it.\u003C/p>\u003Cp>Speaker 0: So right now, we're going down. So we're gonna get it. So we're gonna go first, we'll be going down, and then we should go right as long as we know where it, as we long as we know where it spawns. Okay. This should work, actually.\u003C/p>\u003Cp>This should be good. So here we go. Should go down first, and then at a certain point, go right. Oh, not fast enough. We're gonna try this again.\u003C/p>\u003Cp>I tell you, it did it does work. You just gotta have the the right movement.\u003C/p>\u003Cp>Speaker 1: Andrew, I full on believe you. You you don't have you're not proving anything. Don't worry.\u003C/p>\u003Cp>Speaker 0: Come on. Really?\u003C/p>\u003Cp>Speaker 1: Your your taste.\u003C/p>\u003Cp>Speaker 0: Oh, did we see that? We did it. We did it. So here's the thing. Right?\u003C/p>\u003Cp>So we changed it from right to up. So we're going right. We're going right. We're going right. And then suddenly, we start going up.\u003C/p>\u003Cp>And that's there's no logic in here that says, dearest, dearest ready set battlesnake, avoid that wall. This is all just, Andrew changing that logic in real time. And you can see if we go to the logs there, which are gonna be, like, super overrun now, not that logs, these logs. But you can see here in our terminal there we go. Yeah.\u003C/p>\u003Cp>So we're updating our cached app, updated cache direction app. And so you can see that there's, like, the change that happens in here. Yeah. Oh, and this is the interesting thing too here. Right?\u003C/p>\u003Cp>Is you actually see so most of the time, it's updating cash Kevin, are you impressed? Are you blown away by my amazing implementation of this?\u003C/p>\u003Cp>Speaker 1: I am so blown away. Thank you so much. I feel like my life has been genuinely enriched in the last 39 minutes of recording. Thank you, Andrew. I don't\u003C/p>\u003Cp>Speaker 0: know what I would do without you as\u003C/p>\u003Cp>Speaker 1: a friend, a mentor, a colleague.\u003C/p>\u003Cp>Speaker 0: Thank you. Thank you. Good. Yeah. And that's it.\u003C/p>\u003Cp>Episode over. We're done. Episode wrapped. Thanks. So, that was just like this is I feel like in every good episode, in every good coding experience, you should do something that's totally useless and makes absolutely no sense so you have the knowledge and skills to do something that actually makes sense.\u003C/p>\u003Cp>Speaker 1: But there are some things already set up. Right? So we've got the dev cycle, like, prod forgive my terminology if I use the wrong terminology. But we've got the project set up, we've got the variable, we've got the options, we've got the ability to change it and hit save. We have a client, you know, we have like an ID for this specific feature.\u003C/p>\u003Cp>So, you know, we have all the parts, and we can just apply it in\u003C/p>\u003Cp>Speaker 0: Exactly. Different ways. So what we're gonna need to do here is I'm going to so we're gonna forget that all of this ever happened. We're gonna go shut off ngrok, for a second, and then we are going to go back to our direct us instance, and we're gonna start direct us up again so we can start to have some fun. And we've got all of our code here.\u003C/p>\u003Cp>Why\u003C/p>\u003Cp>Speaker 1: We do. Are you It's it's it's the other it's the other Visual Studio code that's in the back. Yeah. Are you\u003C/p>\u003Cp>Speaker 0: talking about? What? Hold on. Alright. We'll doc, and then we'll go back over here to engrok, and let's get this running.\u003C/p>\u003Cp>Oh, I'm running the wrong one. There we go. Nice. Wonderful. And let's go over to here, which I should actually have open in my window.\u003C/p>\u003Cp>Oh, and we don't need this for right now. So let's open that and make that bigger. And we should be able to go to here. Wonderful. I am gonna need to log in again, I think.\u003C/p>\u003Cp>Speaker 1: No. No. No. I think it'll be fine.\u003C/p>\u003Cp>Speaker 0: No. I need to log in again.\u003C/p>\u003Cp>Speaker 1: Oh, you're gonna need to log in again. Battlesnake@lws.iohunter2. Glasses us what I set this up with. There you go.\u003C/p>\u003Cp>Speaker 0: Okay. So here is our logic. We removed a bunch of stuff from in there. Great. Our snake is working again.\u003C/p>\u003Cp>Should be working again. Logs are all there. I feel less bad about all the logging that I was doing of every time that we were calling Dev cycle now that I see these Exactly.\u003C/p>\u003Cp>Speaker 1: Thousands of We actually you know, this was I mean, all the dates, like, visible elsewhere. Just today, we actually recorded, or we we did a live request review, which is our show where we or it's our live event, which then becomes a show on director's TV a week later, where we go through feature requests to talk about them, and today's was all about flows improvements. And one of the big things is the ability to change the retention of those logs. I like that. Because, yes, they get they get chunky.\u003C/p>\u003Cp>Speaker 0: They do. So, what I think we are going to do, and I liked the idea that you were talking about before, Kevin. I think let's do 2 pieces of logic, and we're gonna we're not gonna delete all of this stuff. We're just gonna kinda remove it for right now, and then we'll reconnect it. And I think we'll have just right now 2 different blocks.\u003C/p>\u003Cp>1 of them that returns right, one of them that returns left for moves, and we'll have some branching logic in there. How does that sound to you?\u003C/p>\u003Cp>Speaker 1: Let's create a new flow for this, and then we could just hook it up to the extension, rebuild it. Like, I think that might be a good a good shout.\u003C/p>\u003Cp>Speaker 0: Let's do that. So let's call this snake, cycle. Alright. And Great. We're just gonna leave that.\u003C/p>\u003Cp>Speaker 1: All of that's good. Just next.\u003C/p>\u003Cp>Speaker 0: And webhook or webhook. Yeah. Okay. And then get, I think.\u003C/p>\u003Cp>Speaker 1: Host.\u003C/p>\u003Cp>Speaker 0: Not the get. Not I had a 5050 shot there, and I got it wrong. There we go. No async\u003C/p>\u003Cp>Speaker 1: calls either. Because because we'll get because we'll get a post request from the Battlesnake platform. Yeah, data of last operation safe. And then what we wanna do here is grab that URL. Yeah.\u003C/p>\u003Cp>I think yeah. Perfect. Go go to the code editor. Go to the extension called snake. Yeah.\u003C/p>\u003Cp>Speaker 0: I think so. And then in our source index dot JS, and we just wanna update this. Right?\u003C/p>\u003Cp>Speaker 1: For move for move. The move one. And just to not have to do the round trip, we'll change the for local host 8055. But hit paste. That'll give us the ID\u003C/p>\u003Cp>Speaker 0: of the trigger and everything.\u003C/p>\u003Cp>Speaker 1: Yep. And then, yeah, we'll just change that for HTTP, not HTTPS, localhost\u003C/p>\u003Cp>Speaker 0: secure my how to secure my URLs. Kevin, who who are won't work. Phone's bloody work, man. Actually, it does. No.\u003C/p>\u003Cp>No. It does. I'm pretty sure. I'm pretty sure ngrok automatically anyways, I don't I don't need to\u003C/p>\u003Cp>Speaker 1: Not not on not on this one. Yeah. Yeah. But yeah. Yeah.\u003C/p>\u003Cp>Yeah. But not on the local not on local host. If you were doing it via ngrok, but then we're gonna have to do another round trip to ngrok for what? It runs locally.\u003C/p>\u003Cp>Speaker 0: Smart. Okay. So we've got our trigger there. This is our move. So now this is all feeding through to the place that\u003C/p>\u003Cp>Speaker 1: we want. Now we've got to rebuild the extension and restart directives.\u003C/p>\u003Cp>Speaker 0: Npm run build?\u003C/p>\u003Cp>Speaker 1: Yeah. From the from that extensions directory. So let's create a new terminal in here.\u003C/p>\u003Cp>Speaker 0: Yeah. CD extensions.\u003C/p>\u003Cp>Speaker 1: Yeah. You got it.\u003C/p>\u003Cp>Speaker 0: And CD directives Extension.\u003C/p>\u003Cp>Speaker 1: Extension snake. Jake and m You got it. Build. You got it.\u003C/p>\u003Cp>Speaker 0: And then restart And then we just Oh, because cannot.\u003C/p>\u003Cp>Speaker 1: Okay. This is fine. This is like macOS going overboard. Open up your open up your settings on your Mac. Security, I think it is.\u003C/p>\u003Cp>Speaker 0: Yeah. We may not be able to do that just because of the security settings. Security\u003C/p>\u003Cp>Speaker 1: No. It was there. It said privacy and security.\u003C/p>\u003Cp>Speaker 0: Security settings.\u003C/p>\u003Cp>Speaker 1: No. Just yeah. There you go. Allow anyway. It's right there.\u003C/p>\u003Cp>It's right there. Fsevents.net. Yeah. Yeah. Cool.\u003C/p>\u003Cp>Yeah.\u003C/p>\u003Cp>Speaker 0: Great. Alright. Let's try this again.\u003C/p>\u003Cp>Speaker 1: You got it.\u003C/p>\u003Cp>Speaker 0: Beautiful. Okay.\u003C/p>\u003Cp>Speaker 1: Lovely. And then restart and then restart the Docker container. Fixed in directory version 10.9, which we have not upgraded to right now. There you go. Hooray.\u003C/p>\u003Cp>And now you're good.\u003C/p>\u003Cp>Speaker 0: Okay. So let's head back over to Directus, which is Yeah. Somewhere. It exists. It is in the world on this device.\u003C/p>\u003Cp>Too many windows. Directus. There we go. Okay. So here we go.\u003C/p>\u003Cp>So this should be talking here. I'm actually gonna go start a game just to make sure this is working. So let's go, play.battlesync.com. Let's go create game. And I think yeah.\u003C/p>\u003Cp>Does it still save recently used? It doesn't. That's so sad. Used to do recently saved escape. There we go.\u003C/p>\u003Cp>And if this is working, we should see a log showing up here. Don't look. Happen. Just no. That's fine.\u003C/p>\u003Cp>We don't it's probably not gonna work work, but it should show a log here. We have 10 logs. I love it.\u003C/p>\u003Cp>Speaker 1: Awesome.\u003C/p>\u003Cp>Speaker 0: Yeah. Okay. Method post. Yes. So that's 10 moves that it took to pass away.\u003C/p>\u003Cp>Perfect. Logic is coming through there. Accountability. Awesome. Okay.\u003C/p>\u003Cp>It's working. So now we're gonna do some branching logic in here. So we're gonna go and condition. And we're gonna worry about the condition afterwards, but let's call this dev cycle response.\u003C/p>\u003Cp>Speaker 1: Oh, it's\u003C/p>\u003Cp>Speaker 0: not here.\u003C/p>\u003Cp>Speaker 1: Well, hang on. Not in not in a condition. 1st, we need to go get data and then we run conditions on the results. So I'm assuming we can just make I'm assuming with DevCycle, just an API, we can make an API request, right, just a raw API request. So you want the webhook request URL, one there.\u003C/p>\u003Cp>Perfect. And first, we need to go get the data, then we'll do the conditional logic. So this might be a moment to look at the dev cycle docs.\u003C/p>\u003Cp>Speaker 0: Yeah, that would make sense. We should probably Yeah.\u003C/p>\u003Cp>Speaker 1: And there will be a moment here where we'll we'll redact it for for the recording, but you're gonna have to authenticate yourself. So you're probably gonna need to put in, like, an API key or token. Can you create multiple inside of your dev cycle?\u003C/p>\u003Cp>Speaker 0: That's a good question. We're gonna experience this together. Yeah. I haven't played around with the yeah. So we're gonna do a little bit of this together, and then we're gonna not do a little bit of this together.\u003C/p>\u003Cp>So let's head over there. So jumping into the dev cycle docs, APIs, management API. This is to create features and variables. I don't think it returns anything. We actually want the bucketing API.\u003C/p>\u003Cp>So this is used to fetch on HTTP. Yes. Yes. Yes. Unique identify the user.\u003C/p>\u003Cp>Definitely, this bucketing API. Get all the variables. Get all the features. Post events. Get variable by key.\u003C/p>\u003Cp>Okay. This is what we're looking for. So let's head over to bucketing API, and we are going to have to get our key Wait. What what my key?\u003C/p>\u003Cp>Speaker 1: Yeah. Sorry. What's the endpoint we wanna hit?\u003C/p>\u003Cp>Speaker 0: So we are going to do get variable by key for user data, I think. Let me look here. Private platform SDK type. Missing SDK. Get all variables.\u003C/p>\u003Cp>What is that gonna return? Is that gonna return the status?\u003C/p>\u003Cp>Speaker 1: What's our what's our end goal here? Our end goal is to\u003C/p>\u003Cp>Speaker 0: We wanna just get the value for the variable. So it's very similar to what we're dealing with in our SDKs.\u003C/p>\u003Cp>Speaker 1: To the user ID to start.\u003C/p>\u003Cp>Speaker 0: Yeah. But everything is hidden behind our bearer token. So I'm just gonna find where all of this is hidden. So key type variation, variation in variation key, response examples, get all features by key post events. No.\u003C/p>\u003Cp>Fetch\u003C/p>\u003Cp>Speaker 1: No. I think get all fee I think I think you were right. Get all features by key for user or get all variables by key for user data. And this will no. Because this will\u003C/p>\u003Cp>Speaker 0: return Here it is. Yeah. Here it is. The value. Fantastic.\u003C/p>\u003Cp>That's what we're that's what we're after is the value. So, we're gonna go offline for one second as I go and get all of my authentication stuff sorted out, and, then we will be back with our API stuff.\u003C/p>\u003Cp>Speaker 1: Sounds good. Okay. So For what for what it for that's worth, we could totally have kept it going, and we could just redact it, adjust that slither slither\u003C/p>\u003Cp>Speaker 0: and time. Keep it going. Yeah. Let's do that. Alright.\u003C/p>\u003Cp>We're back. Yeah. We haven't gone anywhere. We thought we were gonna go somewhere. This is interesting too because we if an so, technically, our management and bucketing API are actually using the same stuff.\u003C/p>\u003Cp>I need to update our docs because we should actually have this curl command in, both, and they're not both there. I guess most people are just assuming we're gonna be using that. So, I'm gonna go and, in a different window, actually, open up, my OAuth token using the client ID. Okay. So I need to go over and what do I need here?\u003C/p>\u003Cp>Client ID and client secret in my dashboard. Alright. So let's go over here and yeah. I don't think\u003C/p>\u003Cp>Speaker 1: Yeah.\u003C/p>\u003Cp>Speaker 0: Showed anything.\u003C/p>\u003Cp>Speaker 1: I'm a I'm a little bit fuzzy on how you authenticate.\u003C/p>\u003Cp>Speaker 0: Let me show you. Okay. So what we do here is alright. You're seeing my screen now. Hey?\u003C/p>\u003Cp>Speaker 1: Yeah.\u003C/p>\u003Cp>Speaker 0: So and, again, I will fully admit that I have only messed around with our API in a very limited way. So, basically, we are doing a curl request with our client ID and client secret. We can actually obviously do this same post request in Directus, and we're just using our client ID and client c. We can't do it directly and directly.\u003C/p>\u003Cp>Speaker 1: I've just spotted it. The type the encoding type for this, for this request is a URL encoded form, but that request URL, you know, operation that's built in only sends JSON. And they're just you don't work around this. Like, you can't do it. However, I'm not too too sad because you can, of course, do it using a custom endpoint.\u003C/p>\u003Cp>It's not quite what we wanna do, but could we do or building a little custom operation. So maybe that's what we do in order to to do that round trip. It's not the ideal, like you know, it means we're gonna have to spend some time doing a little bit of extension development. Like, just spotted that. Is that is that the only way to do it?\u003C/p>\u003Cp>Speaker 0: Yep. Yeah. We have no real public API stuff, which is interesting, but also so what's interesting so we are having so we're working right now on some webhook stuff. So you can technically get when, certain changes have been made, like an audit log. You can read that through a webhook, but you can't actually read what people's values are.\u003C/p>\u003Cp>Speaker 1: Because that would that would be so good because on a webhook, you could trigger a separate flow, store indirect just like your cache Yeah. And then do stuff based on that. But that's completely fine. So we could do this or if we're building a a little custom, operation, we could just straight up use the SDK.\u003C/p>\u003Cp>Speaker 0: Yeah. So let's do that. And then we've already got the code there. So, yeah. Okay.\u003C/p>\u003Cp>Let's, are we gonna do this here inside of our code, or are we gonna do this over on the platform to get started? Where are we gonna\u003C/p>\u003Cp>Speaker 1: I don't under let let's let's build an operation for flows as an extension. And the goal of that operation is to, right now, just get a fixed, you know, a fixed response from from the API. So, no, we don't do it like this. We actually use the extensions SDK CLI, which will boil the plate a whole extension for us.\u003C/p>\u003Cp>Speaker 0: Alright. We're gonna delete that bad boy. Alright. Let's open\u003C/p>\u003Cp>Speaker 1: a new terminal here. Open up a new terminal. You got it. And we'll go into the extensions folder.\u003C/p>\u003Cp>Speaker 0: Alright. Oh, into the extensions folder. Extensions folder. Yeah. Yeah.\u003C/p>\u003Cp>Speaker 1: Yeah. Sorry. Yeah. Yeah. Exactly.\u003C/p>\u003Cp>Exactly.\u003C/p>\u003Cp>Speaker 0: And then how do I pull up the docs? Or are you just gonna Yeah. Docs. I mean,\u003C/p>\u003Cp>Speaker 1: I could tell I could tell you this one, but let let's let's do the docs. Let's let's have the authentic experience with someone who doesn't live in this every day.\u003C/p>\u003Cp>Speaker 0: There we go. Alright. Let's head over. And we're gonna see this is gonna be my challenge. How long does it take Andrew to find out what I'm looking for?\u003C/p>\u003Cp>Alright. So when direct to stocks, we're in extensions. We're in device extensions.\u003C/p>\u003Cp>Speaker 1: Zoom in.\u003C/p>\u003Cp>Speaker 0: We're going to zoom in. We're going to go extensions. We're going to go, developing extensions and we're gonna go extension services and introduction. No. That doesn't look like what I'm looking for.\u003C/p>\u003Cp>Speaker 1: Maybe Very good. Very very good little piece of feedback there. Go into the fundamental section, the one you haven't opened out of the 3, the last one, and creating extensions.\u003C/p>\u003Cp>Speaker 0: Perfect. We're just gonna use this. Alright. Let's go back over here and run this.\u003C/p>\u003Cp>Speaker 1: But I I do see that. I do see that path you took. I'm glad to know that. Discussed it with one of our colleagues just yesterday. So yeah.\u003C/p>\u003Cp>Speaker 0: Like, when things work oh, oh, I need to change my note version. It's upset with me. Wait. What? Oh, it's just warnings.\u003C/p>\u003Cp>Really? Oh, yeah. Whatever. Sure.\u003C/p>\u003Cp>Speaker 1: Me. That looks\u003C/p>\u003Cp>Speaker 0: what do\u003C/p>\u003Cp>Speaker 1: you wanna create? Operation, please.\u003C/p>\u003Cp>Speaker 0: Oh, there it is. Hidden down in that list. Choose a name.\u003C/p>\u003Cp>Speaker 1: And they so they must start so they must start as of this release. I think it might be gone in 10.9 or it'll be gone in a soon release in a upcoming release. Directus dash extension dash whatever you want. Dev cycle is fine.\u003C/p>\u003Cp>Speaker 0: JavaScript because I don't play with TypeScript.\u003C/p>\u003Cp>Speaker 1: I respect that.\u003C/p>\u003Cp>Speaker 0: Dependencies. Yes. Scaffolding it. I love this. This is so smooth.\u003C/p>\u003Cp>I like a I like a good CLI.\u003C/p>\u003Cp>Speaker 1: Good. Great. So now we have if you go into the extensions drop down, you have a new extension called dev cycle inside of source. We have API dot JS. We have App JS.\u003C/p>\u003Cp>App JS is for all of the configuration. So it's all the UI part. It's all of the options when you create a new one, you have that little pane that pops out. It's the information that will show on the on the card in the overview where you connect to all the nodes. That's the overview there.\u003C/p>\u003Cp>And then the API dot JS is the node code that will actually be executed in the background. Right?\u003C/p>\u003Cp>Speaker 0: So we're gonna go and I think right now what we wanna do is actually grab, just so we're not having to worry about this later. We're gonna grab our code from here. So not going back and forth, because this is basically all the stuff that I need.\u003C/p>\u003Cp>Speaker 1: Yeah. Great.\u003C/p>\u003Cp>Speaker 0: And we're just gonna put you down there and comment you out so that things don't get upset with us.\u003C/p>\u003Cp>Speaker 1: Sounds good.\u003C/p>\u003Cp>Speaker 0: Alright. Perfect. So let's save that, and let's do an install. So I do have to have to go into this folder to install, slash extensions. Directus extension CD.\u003C/p>\u003Cp>Extension. CD. Cycle. Not we're not we're gonna put it at the end and see what happens. No.\u003C/p>\u003Cp>Start. Start. Start. Start.\u003C/p>\u003Cp>Speaker 1: For a moment, I was like, am I about to learn something?\u003C/p>\u003Cp>Speaker 0: No. There's there's very little learning that will be\u003C/p>\u003Cp>Speaker 1: There's very little learning. I got it. I got it.\u003C/p>\u003Cp>Speaker 0: And then we gotta go over to because we're gonna install the, the SDK. We're gonna go over to the dev cycle docs. So we'll move back over to docs, and let's head back over to the dev cycle docs, docs.devcycle.com. And we're gonna head over to our SDK section, our node JS SDK\u003C/p>\u003Cp>Speaker 1: You got it.\u003C/p>\u003Cp>Speaker 0: Installation. And let's grab this because who uses yarn, NPM or bust? I've become so opinionated in my coding Alright. So that means that our import statement should work now. Actually, is this import or is this require?\u003C/p>\u003Cp>I This is import. Yeah. I thought so. Alright. Let's move you to the top.\u003C/p>\u003Cp>Alright. Perfect. So step 1 complete. We're done. Time to go home, everybody.\u003C/p>\u003Cp>End of episode.\u003C/p>\u003Cp>Speaker 1: So a couple of things that are just important before we continue. There is an ID here called custom. Let's rename that, and then we have to reflect that ID in the App JS and the corresponding App JS. I think dev cycle is a perfect ID. So we just want those 2 to match, first of all.\u003C/p>\u003Cp>Very good. And let's, while we're here, give this a name. Dev cycle, this is the nice friendly name that shows up when you pick your operation type. Sure. Yeah.\u003C/p>\u003Cp>Then are we gonna ask the user for any configuration up front? And I'm gonna say that maybe we do. Maybe we wanna collect the snake eye like, the the the ID. Right? Are we gonna do it?\u003C/p>\u003Cp>Are we gonna have time to do that? I mean, can we give it just an arbitrary ID, or does do you have to register users inside of the dev cycle system first? Like, how does that work?\u003C/p>\u003Cp>Speaker 0: So you would need to feed a specific user's information. Yeah. Let's call a snake name. Yes. I think that's a great idea.\u003C/p>\u003Cp>Yeah.\u003C/p>\u003Cp>Speaker 1: I was a snake ID. Snake ID. So let's do that. And at first, we'll just hard code it, but later, you can put dynamic values in here in flows. So instead of text, let's just change text to snake.\u003C/p>\u003Cp>So there's a friendly name. Yeah. Yeah. Perfect. There's a friendly name.\u003C/p>\u003Cp>Speaker 0: Yes. Is that correct? Is it? I changed this from tests from is this yeah?\u003C/p>\u003Cp>Speaker 1: Yes. That's all good. The options need to change too. That's the part. So that that's the overview that will show on the card.\u003C/p>\u003Cp>Cool. Whatever. It's the options we care about. That's the pain that comes out and you select all the options. So in here, the field, the field will be called snake.\u003C/p>\u003Cp>And that's what corresponds with the snake in the overview. That's the friendly name. It will still be a string. It'll be full of input. Great.\u003C/p>\u003Cp>Save. Now we'll go over to API dot JS, and there's text here. We'll change text for snake. So that says taking in the snake value and now we're going to execute some code. But before we do this, I think that's everything on the UI side done.\u003C/p>\u003Cp>We want to initialize this client and we'll want to initialize this client between lines 13. So everything in your yeah.\u003C/p>\u003Cp>Speaker 0: Great. So, we're going to ignore this because we're not actually going to I'm actually I'm interested to see how this works. Once we have done this, we're going to change some things up eventually. But we're not gonna worry about that right now. So let's grab\u003C/p>\u003Cp>Speaker 1: Oh, which was straight upon commenting everything. That's that's crazy.\u003C/p>\u003Cp>Speaker 0: I mean, nothing could go wrong because nothing's really running yet. So this is good. This server is gonna change. I'm gonna leave these. I don't actually know if we need these, but I'm not gonna question it.\u003C/p>\u003Cp>Speaker 1: If it works before, our goal is to take what worked and apply it here. So we're not gonna make any changes to the logic here.\u003C/p>\u003Cp>Speaker 0: Yeah. Exactly. So we are initialized there now, and now we need to pull all of this stuff up above. And I think we're not gonna need that get cached direction elsewhere.\u003C/p>\u003Cp>Speaker 1: I don't think we wanna necessarily play with that right now. And at the very least, we wanna make sure that we can get data from dev cycle in a flow Exactly. And then pass it on. But if you were having an issue where it's taking a little while to do that round trip, there's a pretty good chance that we're gonna hit that here too.\u003C/p>\u003Cp>Speaker 0: Okay. So let's go here. Awesome. Alright. So here we go, dev cycle clients.\u003C/p>\u003Cp>So we're established here. We've got this cash direction. Again, I don't actually think we need this anymore because we're gonna be calling it sort of once to determine what's gonna change. We're not gonna be calling this again and again and again. Right?\u003C/p>\u003Cp>We're not gonna be calling this every move. Is that our that's our focus. Right?\u003C/p>\u003Cp>Speaker 1: I mean, we were. Yeah.\u003C/p>\u003Cp>Speaker 0: Do we we were gonna call it every move? Oh,\u003C/p>\u003Cp>Speaker 1: this is all in the wrong endpoint. This actually wants to go in the start game, doesn't it? Once you're in the start game and then for the game, we determine the strategy and then we execute on it. This is okay. Let's keep rolling now.\u003C/p>\u003Cp>And then before we've done it with yeah, exactly. Precisely. So let's really let's let's keep this light. In fact, I think doing everything in a separate function may not even be what we Exactly. Want too much here.\u003C/p>\u003Cp>Speaker 0: So I'm gonna pull all of this out of this update cache directory.\u003C/p>\u003Cp>Speaker 1: Hang on. Hang on. I think the only bit we care about is this dev cycle client variable.\u003C/p>\u003Cp>Speaker 0: I think\u003C/p>\u003Cp>Speaker 1: that's the only bit we want.\u003C/p>\u003Cp>Speaker 0: We also care about this user thing. So that's\u003C/p>\u003Cp>Speaker 1: where that's going to snake. Yeah. But that's going to that's already that's coming in from the snake value above. So we're gonna get to feed that in.\u003C/p>\u003Cp>Speaker 0: Yes. Yes. Yep. I guess it has to feed a very specific way. It has to be a very specific object that's feeding in, but maybe you're right.\u003C/p>\u003Cp>Let's let's see. Let's see. I think I think\u003C/p>\u003Cp>Speaker 1: it'll be okay. So so if we if we go down to where the actual flow handler is, which I think is down. So inside of the handler, instead of the console log, snake is a string. So what we want to do here is we want to make on line 41, we want to make this an async function. Right?\u003C/p>\u003Cp>Yep. No. As in as in we wanna change just before the the snake. Oh, I see. We wanna make it async, then we'll just use a sync yeah.\u003C/p>\u003Cp>One more to the left. One more to the left.\u003C/p>\u003Cp>Speaker 0: Goodness gracious. And we're gonna get rid of you. You don't need to be there.\u003C/p>\u003Cp>Speaker 1: And then and then inside, what we wanna do is is run that run that SDK method, but we can do it with a wait instead of then just to clean it up in this context. So if you scroll just very slightly up oh, yeah. We'll ditch something small. Yeah.\u003C/p>\u003Cp>Speaker 0: We're just gonna do this. We're not gonna need to do this call. Perfect. Let's just work the day.\u003C/p>\u003Cp>Speaker 1: Grabbing this. Yeah. But only 17 18 to start.\u003C/p>\u003Cp>Speaker 0: Oh, yeah. You're right. Yep.\u003C/p>\u003Cp>Speaker 1: Because we're doing a sync await.\u003C/p>\u003Cp>Speaker 0: Yep. Yep. Absolutely.\u003C/p>\u003Cp>Speaker 1: So we want that. That goes straight in there, within within a wait at the beginning of line 33 and a store this in a variable. Right?\u003C/p>\u003Cp>Speaker 0: Yeah. Let's call this strategy.\u003C/p>\u003Cp>Speaker 1: Beautiful. Love that. And then user is now gonna be I mean, if you wanna grab lines 13 to 15 just to get the structure, but really it's just an object with the user ID and snake. Yeah. Yeah.\u003C/p>\u003Cp>Exactly.\u003C/p>\u003Cp>Speaker 0: Let's see what happens. And then yeah. So we're gonna Other way. We're gonna define this above. Yep.\u003C/p>\u003Cp>We can assign this above. Awesome. And we're actually gonna feed this in. User ID here is gonna be snake. So we're gonna feed in snake here.\u003C/p>\u003Cp>Speaker 1: Snake? Yeah.\u003C/p>\u003Cp>Speaker 0: I think that should work.\u003C/p>\u003Cp>Speaker 1: I think that should work. But we don't know what comes back in strategy yet, so we're gonna log it. Perfect. And then we're going to return strategy.\u003C/p>\u003Cp>Speaker 0: Beautiful. And that's actually add some comments there so we know it's being logged. Strategy.\u003C/p>\u003Cp>Speaker 1: Oh, can I show you can I show you a quick tip for this, which I think you'll\u003C/p>\u003Cp>Speaker 0: really like? Love a quick tip.\u003C/p>\u003Cp>Speaker 1: So remove that remove that string in the comma from the console log. So it's just the word strategy again. Yep. And then highlight all of the word strategy, just the word strategy, and then surround them with squiggly brackets. And now that is an object where the key is strategy and the value is strategy.\u003C/p>\u003Cp>So when it logs, you get strategy, colon. Yeah. It will be an object. So that is just a real shorthand if you if you just want to quickly tell what something is and you have just a variable key.\u003C/p>\u003Cp>Speaker 0: You know, sometimes I enjoy JavaScript, but only when people that enjoy JavaScript are doing JavaScript with me. Okay. So technically, this should this should do all of the things that we want it to do, I think.\u003C/p>\u003Cp>Speaker 1: Yeah. And\u003C/p>\u003Cp>Speaker 0: so this is wanna change this to hold on. Oh, sorry. Go ahead, Kevin.\u003C/p>\u003Cp>Speaker 1: No. No. No. Go ahead.\u003C/p>\u003Cp>Speaker 0: So I'm just saying here so here, we're actually gonna go and create an so this is a direction variable. We're gonna create a strategy variable and kind of put 2 strategies. We're gonna do, like, hungry and tailchase or something like that.\u003C/p>\u003Cp>Speaker 1: I mean, we we're not gonna implement those. So why don't we do left or\u003C/p>\u003Cp>Speaker 0: right? That is a very smart decision, Kevin. So let's head back over to dev cycle here, and we're gonna get out of there, go into our features again. Into our choose move, it doesn't really matter again what this feature is called. We're gonna create a new variable.\u003C/p>\u003Cp>We're gonna call this strategy. We're gonna set this as a strict technically, we could just do Boolean, but we'll do strategy. And because of the way that we have this set up with, like, these 4 different options of left, right, up, down, we're gonna actually go ahead and kind of move this around. So we're gonna call it, this one's gonna be left, and this one's gonna be right. Actually, we'll just leave it all exactly the same.\u003C/p>\u003Cp>Down, up.\u003C/p>\u003Cp>Speaker 1: But it's just called strategy this time.\u003C/p>\u003Cp>Speaker 0: It's called strategy now. Yeah. Sure. Alright. Amazing.\u003C/p>\u003Cp>Look at that. We changed literally nothing. I love that I did a thing that was completely unnecessary. We could\u003C/p>\u003Cp>Speaker 1: have just kept the stream.\u003C/p>\u003Cp>Speaker 0: Just kept the same.\u003C/p>\u003Cp>Speaker 1: That's fine. That's fine. We we okay. So we're logging this and we I think I think this works, but what we want to do here is is\u003C/p>\u003Cp>Speaker 0: what do we\u003C/p>\u003Cp>Speaker 1: wanna do here? We now wanna hook this up to a start.\u003C/p>\u003Cp>Speaker 0: Yes. So we need to do we need to do a new end.\u003C/p>\u003Cp>Speaker 1: And we need to change the data model to, have this extra, like, strategy string, which I think is amazing because then even in our insights dashboard, we can be like, when using this strategy, this is the win rate. Like, it's actually really lovely.\u003C/p>\u003Cp>Speaker 0: Now we're done in code for right now, though. Right? So I think that we can No. We're not?\u003C/p>\u003Cp>Speaker 1: Build this one. Build this extension. I think we're gonna need to change which flow is being hit on start. I think we need to create a new flow. We need to create a hang on.\u003C/p>\u003Cp>Speaker 0: Oh, metadata.\u003C/p>\u003Cp>Speaker 1: Hang on. Hang on. Is this are these errors or are these suggestions? I think this is all about and has been rewritten. I have a sneaking suspicion this is inside of the SDK.\u003C/p>\u003Cp>There\u003C/p>\u003Cp>Speaker 0: might be no module in\u003C/p>\u003Cp>Speaker 1: But it said done.\u003C/p>\u003Cp>Speaker 0: Yeah. This may\u003C/p>\u003Cp>Speaker 1: And it says and has been rewritten. All of these have resolutions. I've not seen the error before. I have a sneaking suspicion it's in the dev cycle and the way we're rolling up and bundling code, not a problem. If it works, it works.\u003C/p>\u003Cp>Not sure if it works. We'll figure that out. So what we actually wanna do is create now another\u003C/p>\u003Cp>Speaker 0: Flow. Flow. Do we need to create another item? No.\u003C/p>\u003Cp>Speaker 1: No. We don't. We can alter our existing start endpoint. Yeah. So yeah.\u003C/p>\u003Cp>But you've built this. You need to restart Directus.\u003C/p>\u003Cp>Speaker 0: Yeah. Okay. There we go. We're gonna restart Directus. Oh, I need\u003C/p>\u003Cp>Speaker 1: there we\u003C/p>\u003Cp>Speaker 0: go. Let's restart here. Oh, wrong one. Just ignore the fact that we're rebuilding it again. Ignore all of those errors, everybody, and go to the right ones.\u003C/p>\u003Cp>Speaker 1: To me to me, they read as warnings. That's the spirit.\u003C/p>\u003Cp>Speaker 0: Alright. And that should be running again, and we're gonna close that down. We're gonna get the right thing open now. And I think we were here. Let's mark\u003C/p>\u003Cp>Speaker 1: this out. Absolute chaos. I literally can't get behind your window management.\u003C/p>\u003Cp>Speaker 0: There is no there is no window management that is occurring. There is nothing. So,\u003C/p>\u003Cp>Speaker 1: there is one other thing we want to do just before we hook all this up, which is we want to go into the data model. And for a gain, we want to, just add a string strategy.\u003C/p>\u003Cp>Speaker 0: Right?\u003C/p>\u003Cp>Speaker 1: Yep. Yeah. Lovely. And then just because it makes can you make it half width, please? Sure.\u003C/p>\u003Cp>You use you you could do it with the little 3 dot things on the side come out of this pane, the little 3 dot thing, and then half Got it.\u003C/p>\u003Cp>Speaker 0: Got it. We got there. Alright. So that's in there now. Awesome.\u003C/p>\u003Cp>Let's head back into flows. Oh, that's not the right spot. Back into flows, and we're gonna change this one. I wanna change the name here before I forget. Can I change that?\u003C/p>\u003Cp>Yeah. I can.\u003C/p>\u003Cp>Speaker 1: Yeah. Yeah. Back here. Yeah. Yeah.\u003C/p>\u003Cp>Yeah.\u003C/p>\u003Cp>Speaker 0: Sneak strategy. Awesome. Nice. Perfect. And\u003C/p>\u003Cp>Speaker 1: then, yes, start. And now we want to see if this new thing can so we extract the snake count, and then we create data. And we basically want to create one there in the middle, which hopefully won't pose too many issues for us.\u003C/p>\u003Cp>Speaker 0: Let's build\u003C/p>\u003Cp>Speaker 1: So no. No.\u003C/p>\u003Cp>Speaker 0: Not on\u003C/p>\u003Cp>Speaker 1: the on the success path.\u003C/p>\u003Cp>Speaker 0: Great. And what do we do in our custom operation? Right?\u003C/p>\u003Cp>Speaker 1: Yes. There is at the bottom.\u003C/p>\u003Cp>Speaker 0: Look at that. It even says dev cycle. I think that's a good name to keep for it. I like that. I also like that it converts camel case into, what's what's this?\u003C/p>\u003Cp>What's the\u003C/p>\u003Cp>Speaker 1: that is called I wanna say hang on. I will I will tell you this because I actually have it inside of my raycast case. That is called that is called, coming up, camel case.\u003C/p>\u003Cp>Speaker 0: That's camel case? This is camel case.\u003C/p>\u003Cp>Speaker 1: Oh, no. Sorry. Sorry. That is I'm I'm I've picked a ridiculous string to test against. So it had, like, it had, like, hang on.\u003C/p>\u003Cp>That is called, scrolling through, Pascal. Is it snake or is it Pascal case? Snake case. It's called snake case.\u003C/p>\u003Cp>Speaker 0: What is snake? Enough. That's a case. There we go. That is\u003C/p>\u003Cp>Speaker 1: appropriate.\u003C/p>\u003Cp>Speaker 0: It's almost like I knew this, and I wanted to bring it up. Okay. And for a sneak ID, we can actually put in anything. We're just\u003C/p>\u003Cp>Speaker 1: Oh, encoded.\u003C/p>\u003Cp>Speaker 0: Yeah. We're just gonna put, like, a really basic actually, no. Let's call this ready, set, Battlesnake because there's some cool stuff you can do with your targeting rules, including include. So let's just set that.\u003C/p>\u003Cp>Speaker 1: I mean, remember, that can be a dynamic value from the first step.\u003C/p>\u003Cp>Speaker 0: It can. But for now, we'll But\u003C/p>\u003Cp>Speaker 1: we can we can yeah. Absolutely agree. So inside of the dev cycle step now sorry. Can we just go in? That was the only option.\u003C/p>\u003Cp>And so dev cycle is gonna return some data. Yeah. All of that happens in the background. So we don't know whether it works yet. So now we wanna redo the nodules.\u003C/p>\u003Cp>Speaker 0: Yeah. Oh, yeah. We just wanna move this to here. Right?\u003C/p>\u003Cp>Speaker 1: Yeah. And this is where we seem to keep having a bad time.\u003C/p>\u003Cp>Speaker 0: Awesome. Thank you, Directus, for doing exactly what we were expecting you to do.\u003C/p>\u003Cp>Speaker 1: On behalf of the core team, you are very welcome.\u003C/p>\u003Cp>Speaker 0: So what is our issue in here? What is our issue?\u003C/p>\u003Cp>Speaker 1: But remember, we had this all the way from the first episode, and we just kind of wrote like, there was a specific set of moves we did, and it worked.\u003C/p>\u003Cp>Speaker 0: Okay. That works. I think it\u003C/p>\u003Cp>Speaker 1: might have been this. I hit edit again.\u003C/p>\u003Cp>Speaker 0: Yeah. And then bring it back and then bring it back. No. What if I just disconnect that altogether? K.\u003C/p>\u003Cp>That works.\u003C/p>\u003Cp>Speaker 1: We're getting there. And then and then do it again now? Edit and just do that last one?\u003C/p>\u003Cp>Speaker 0: Come on. There we go. There we go. We got it. 2, we're gonna\u003C/p>\u003Cp>Speaker 1: set of actions. There you go.\u003C/p>\u003Cp>Speaker 0: It's 1 at a time. Yeah.\u003C/p>\u003Cp>Speaker 1: Okay. So that Now we want to start a game and just see if it works. And there's a we're also going to want to look at our directors logs too because we did console log just data. But let's we need to start the game.\u003C/p>\u003Cp>Speaker 0: Let's start Then we can first. And let's grab create new gate. Oh, not create new battle sync, create game, and let's grab escape. Oops. Escape.\u003C/p>\u003Cp>Escape.\u003C/p>\u003Cp>Speaker 1: Which I now regret.\u003C/p>\u003Cp>Speaker 0: K. Add game. Is it in there? There we go. Beautiful.\u003C/p>\u003Cp>Okay. Let's see. Game is running. Something's happening. Not what we want to happen.\u003C/p>\u003Cp>Sure. That's okay. Let's head back over to Directus and see what our logs are saying.\u003C/p>\u003Cp>Speaker 1: Scroll up because, obviously, all the turns happen. Right. Strategy. Boom. We\u003C/p>\u003Cp>Speaker 0: just need to do dot value.\u003C/p>\u003Cp>Speaker 1: That's why. Okay.\u003C/p>\u003Cp>Speaker 0: It's it's returning this. It's the yeah. Request to get variable strategy failed with the response variable not found for key strategy. Hold on. Did I not save?\u003C/p>\u003Cp>I feel like I might not have saved something over on the cycle, which is a necessary step here is to actually save it. Okay.\u003C/p>\u003Cp>Speaker 1: That does sound necessary.\u003C/p>\u003Cp>Speaker 0: Oh, hold on. Maybe this is not that window. Ah, see this? Save. It doesn't actually know that it's there.\u003C/p>\u003Cp>It's my own darn fault. I got too many windows open. Darn you, Andrew. Honestly, I'm pretty sure\u003C/p>\u003Cp>Speaker 1: it's the curse of academics. Every academic I've ever seen or a covering academic. I think you are though current. Correct. Yeah.\u003C/p>\u003Cp>It's it is that. So while we're here, maybe we just straight because this is a DVC variable. Let inside of the extension itself return strategy return dot value. Yeah. And then rebuild, restart.\u003C/p>\u003Cp>Speaker 0: Yep. So we're gonna return\u003C/p>\u003Cp>Speaker 1: This is good.\u003C/p>\u003Cp>Speaker 0: Yep. Dot value. Awesome. There we go. So that should work.\u003C/p>\u003Cp>That should do what we want it to do. Let's rebuild here.\u003C/p>\u003Cp>Speaker 1: You got it.\u003C/p>\u003Cp>Speaker 0: Yeah. We're in the right oh, that's snake. We wanna be dev cycle and not CD. Let's go npm run build. And now we're going to need to restart again.\u003C/p>\u003Cp>Speaker 1: Yeah. Once again, not the case now, but I'm too I'm too nervous just just in case. The upgrade is right in this moment.\u003C/p>\u003Cp>Speaker 0: Okay. And I need to oh, why did I do\u003C/p>\u003Cp>Speaker 1: that? Why did you do that? I\u003C/p>\u003Cp>Speaker 0: don't know. Questions questions have been asked. Okay. So let's see if we can create a rematch. Should work this time.\u003C/p>\u003Cp>Nope. Not working.\u003C/p>\u003Cp>Speaker 1: Well, it's not so much that. That's just the bit we care about because it's our new snake. What we care about is if we go back to the logs\u003C/p>\u003Cp>Speaker 0: Are these the new\u003C/p>\u003Cp>Speaker 1: No. No. No. No. The the log the logs won't tell us anything.\u003C/p>\u003Cp>Go see if the strategy has been saved against the latest game.\u003C/p>\u003Cp>Speaker 0: Oh, that's true. Yes.\u003C/p>\u003Cp>Speaker 1: That's what we're actually testing here. Oh, no. No. No. We're not doing that.\u003C/p>\u003Cp>Sorry. We check the flow logs, the flow logs for start. This is what we're doing. And we check the latest log. We check the dev cycle payload.\u003C/p>\u003Cp>Speaker 0: Ready, set, battle, snake is the snake we're feeding in. Payload up. That's good. I should be feeding everybody up right now. Up, up, up, up, up, up, up.\u003C/p>\u003Cp>Yes. Hey. We did it. That's awesome.\u003C/p>\u003Cp>Speaker 1: Now so now we wanna store the strategy. And then in the move logic, we want to grab this next this game strategy. We want to act on it.\u003C/p>\u003Cp>Speaker 0: I love this. Okay. So we have this here. Now we need to store it in here, right? We're actually Yeah.\u003C/p>\u003Cp>Speaker 1: We just wanna edit the create data.\u003C/p>\u003Cp>Speaker 0: Edit the create data. Oh, in here. Gotcha. Yeah. Because we're already creating it.\u003C/p>\u003Cp>Speaker 1: We just need to add\u003C/p>\u003Cp>Speaker 0: strategy.\u003C/p>\u003Cp>Speaker 1: You're missing a comma on line 3.\u003C/p>\u003Cp>Speaker 0: But I laugh at commas.\u003C/p>\u003Cp>Speaker 1: Okay. Do you\u003C/p>\u003Cp>Speaker 0: wanna hear do you wanna hear a fun do you wanna hear a fun, little story while we're doing this? I'm ready. So I, am teaching at at the university this this term. And, I was talking to my students who are all future teachers about using proper grammar in the posts that they're doing on the WordPress blogs they create. And I misspelled grammar.\u003C/p>\u003Cp>Beautiful.\u003C/p>\u003Cp>Speaker 1: Well, you can't have it all. You could have good grammar or good spelling. So so remember, the value was no not trigger. The returned value from the dev cycle step. And remember, the key was dev underscore cycle or lowercase, so not the dollar sign, was the string.\u003C/p>\u003Cp>So it is just dev underscore cycle, and the value of that will be the string.\u003C/p>\u003Cp>Speaker 0: All right. Let's see if this works.\u003C/p>\u003Cp>Speaker 1: Because that's what was returned out of that step to save. And so let's start one more game. Let's make sure that's being being stored.\u003C/p>\u003Cp>Speaker 0: Oh, cut out there, Kevin.\u003C/p>\u003Cp>Speaker 1: Oh, I actually just stopped talking.\u003C/p>\u003Cp>Speaker 0: I'm not sure. Oh. You you definitely froze.\u003C/p>\u003Cp>Speaker 1: Oh, okay. Fair fair enough. Yeah?\u003C/p>\u003Cp>Speaker 0: Okay. Good. Okay. Perfect. So we ran a game.\u003C/p>\u003Cp>Yeah. That's fine. And then let's head back over to our logs here. And the I mean,\u003C/p>\u003Cp>Speaker 1: the proof is gonna be in the pudding here.\u003C/p>\u003Cp>Speaker 0: No. So But then no\u003C/p>\u003Cp>Speaker 1: no no the options. Strategy up. So if we now go look\u003C/p>\u003Cp>Speaker 0: at the latest Oh, there we go. Yeah. We're there.\u003C/p>\u003Cp>Speaker 1: Yeah. Yeah. So if so if we go just check the content module in the sidebar here in the, module bar far left, let's go look at the latest game and make sure our strategy was saved. That's the top one. Top one.\u003C/p>\u003Cp>Speaker 0: What is Games.\u003C/p>\u003Cp>Speaker 1: What what an easy quick way to do this is if you just hit the plus in the top. Like, if you add a if you add a field, perfect strategy, boom. Nice. Amazing. So now we're gonna go into our move, our new move, which does nothing, which is why our snake is doing nothing, and we wanna respond to that strategy.\u003C/p>\u003Cp>Alright. So So not this one. We we we we we we we Oh, that's right.\u003C/p>\u003Cp>Speaker 0: Yeah. Yeah. We did a strategy one. That's right. Okay.\u003C/p>\u003Cp>Awesome.\u003C/p>\u003Cp>Speaker 1: Snake strategy.\u003C/p>\u003Cp>Speaker 0: And let's do this as a we're just gonna return. Right? So we just need to do\u003C/p>\u003Cp>Speaker 1: No. Because there's a few steps here. So this takes in a move, right? And that move has a game ID. So the first thing we want to do is we want to look up the game to find out the strategy, right?\u003C/p>\u003Cp>So we want to read data first and my confidence has just gone through the floss. So let's close out this for a moment. Can we just look at the logs here and just understand the shape of the data again?\u003C/p>\u003Cp>Speaker 0: All right.\u003C/p>\u003Cp>Speaker 1: So So the payload, body, game, ID. And that should match the ID of the game in our collection that has been created by the start step.\u003C/p>\u003Cp>Speaker 0: So let's see. 4ff ending in 70. Let's see if that is in fact the case.\u003C/p>\u003Cp>Speaker 1: Sure. I I think it should be. Yep. There we go. Perfect.\u003C/p>\u003Cp>So what we want to get out is that strategy. So, so we'll create a new step here, and we can call this get game or something.\u003C/p>\u003Cp>Speaker 0: Yeah. Get game strategy. Let's call it.\u003C/p>\u003Cp>Speaker 1: I'll just get this is gonna get the whole game. So let's just get game. And then permissions full access because I can't be bothered to deal with permissions, collection, games, IDs. Now this is important. We want in squiggly brackets, double squiggly brackets here, trick, dollar sign trigger dot body\u003C/p>\u003Cp>Speaker 0: Body. Yeah. Dot game\u003C/p>\u003Cp>Speaker 1: ID. Game. Yeah. You got it. Dot ID.\u003C/p>\u003Cp>Yeah. And hit enter. And hitting enter just slightly, you know, you have to enter. And just like you're hitting save over there in dev cycle, that's one that gets me.\u003C/p>\u003Cp>Speaker 0: There we go.\u003C/p>\u003Cp>Speaker 1: And this should get the game. So hit save. Let's see. And let's just do this very sequentially. So, yes, let's let's test this again.\u003C/p>\u003Cp>Once again, the value should absolutely be up.\u003C/p>\u003Cp>Speaker 0: Perfect. Options.\u003C/p>\u003Cp>Speaker 1: Permission to pull\u003C/p>\u003Cp>Speaker 0: the games ID. Wonderful. Wonderful. And we get our strategy.\u003C/p>\u003Cp>Speaker 1: Lovely. And the strategy now is what we're gonna check. So now we're gonna do some branching logic. So what we want is, I think, a conditional.\u003C/p>\u003Cp>Speaker 0: Yep. Right? Yep. And we're going to call this strategy.\u003C/p>\u003Cp>Speaker 1: Strategy. Well, let's be more specific because we're gonna check if it is one strategy or the other. So Oh, that's true. Is, you know, strategy, yeah, is up. Although, was was up the value yeah.\u003C/p>\u003Cp>Yeah. Off was the value.\u003C/p>\u003Cp>Speaker 0: Yeah. It's up the value.\u003C/p>\u003Cp>Speaker 1: It's up. Yeah. Perfect. So let's fill in the so I don't think we do wanna fill in the default. Yeah.\u003C/p>\u003Cp>So squiggly like, this is JSON now. So squiggly brackets on the outside.\u003C/p>\u003Cp>Speaker 0: There we go. I love this, by the way. This is such a smart little\u003C/p>\u003Cp>Speaker 1: Except we are gonna have to go edit it. So I know. It's all it's. So trigger change for last because we wanna grab stuff from the last step. Oh, sorry.\u003C/p>\u003Cp>A dollar sign. Yeah. Last. Perfect. Yeah.\u003C/p>\u003Cp>Correct. And we're gonna be checking the strategy. So not category, strategy. Yeah. And when you see whether it is equal to up and it's case sensitive.\u003C/p>\u003Cp>So yeah. Perfect. Wonderful. And hit save.\u003C/p>\u003Cp>Speaker 0: Now, honestly, this is where this is where\u003C/p>\u003Cp>Speaker 1: I mean, nothing would oh, yeah. Suppose we can check. We can check that.\u003C/p>\u003Cp>Speaker 0: Kevin, let's follow, strategy every time we do this, but, no, we won't follow the strategy. Let's see.\u003C/p>\u003Cp>Speaker 1: Oh, wait. Wait. Wait. Nothing it didn't get saved.\u003C/p>\u003Cp>Speaker 0: What?\u003C/p>\u003Cp>Speaker 1: Didn't save the flow. You just refreshed.\u003C/p>\u003Cp>Speaker 0: Oh, did I really?\u003C/p>\u003Cp>Speaker 1: No. Womp. Womp. It's okay. Come on, Andrew.\u003C/p>\u003Cp>Speaker 0: Come on. I mean, to be fair to\u003C/p>\u003Cp>Speaker 1: be fair, there is a little bit of allowing you to do that without prompts. Anyway, anyway, is up Yep. Was the name of the condition, and it's gonna be lost. Last. Yeah.\u003C/p>\u003Cp>Speaker 0: And you call them strategy.\u003C/p>\u003Cp>Speaker 1: You call it.\u003C/p>\u003Cp>Speaker 0: And oh, strategy, and up, and save and save. Up. It's the double save.\u003C/p>\u003Cp>Speaker 1: I get it. I get it.\u003C/p>\u003Cp>Speaker 0: Let's set out. Let's finish this game. And so I figured out the thing that it is here. You actually have to finish the game before it'll let you do a rematch. You have to play the whole game.\u003C/p>\u003Cp>That was the issue we were facing.\u003C/p>\u003Cp>Speaker 1: Good tonight.\u003C/p>\u003Cp>Speaker 0: So we should have it showing up now. Yes. He's up. Payload. Yep.\u003C/p>\u003Cp>Awesome. Is\u003C/p>\u003Cp>Speaker 1: up. Now, this basically will fail if it isn't up. It will it will, like, it will have a validation error, and the whole flow will fail. And this is correct.\u003C/p>\u003Cp>Speaker 0: Yeah. Let's see. Look at you go. All right. Here we go.\u003C/p>\u003Cp>And amazing. Alright. And let's go back over to directors refresh. Look at our logs. Shut up a bunch more.\u003C/p>\u003Cp>Let's go. Oh, oh, something's happening. Oh, I need to actually press the button. Alright. Here we go.\u003C/p>\u003Cp>Oh, option payload validation error.\u003C/p>\u003Cp>Speaker 1: Validation error. Wonderful. And so this is where, we have to be creative with flows and work within some of the limitations, to be frank. So because all all conditions, there is no, like, case statement where you can be like a, b, or c. It is true or it is false.\u003C/p>\u003Cp>It is resolved or it is reject. Right now, our flow simply halts because it goes out that reject path and fails. Right? But what we're gonna do now is we're just going to put, you know, we're going to just put one thing on the reject path, but it isn't failed. It's just the else.\u003C/p>\u003Cp>Right? So it's just an interesting terminology thing there. So we don't, we don't we don't even need this now.\u003C/p>\u003Cp>Speaker 0: Oh, I guess Unless you wanna do can be Well, why don't you wanna do it? Yeah. Let's just do all 4. There's only 4 to do. So\u003C/p>\u003Cp>Speaker 1: So hang on. Hang on a moment. Have you put you've put this on the reject path. Right? Yes.\u003C/p>\u003Cp>Perfect.\u003C/p>\u003Cp>Speaker 0: Yep. Okay. Last strategy down, and we're gonna call this is down. Perfect. Yes.\u003C/p>\u003Cp>And then we're gonna create another.\u003C/p>\u003Cp>Speaker 1: Off the reject path. Off the reject path. So it gets a little bit unwieldly here. So it's not up. It's not down.\u003C/p>\u003Cp>Speaker 0: Strategy. Let's call this last.\u003C/p>\u003Cp>Speaker 1: Copy it out this time before you hit save.\u003C/p>\u003Cp>Speaker 0: Look at you, left. Perfect. Copy. And then one more.\u003C/p>\u003Cp>Speaker 1: So you so you see here how these kind of more convoluted case statements can get a little bit messy in here?\u003C/p>\u003Cp>Speaker 0: Yep. I definitely do. But, is right. Okay. So let's go there.\u003C/p>\u003Cp>Save this. And go to the game. And let's finish this game. Shouldn't take too long.\u003C/p>\u003Cp>Speaker 1: And this one should do the same thing. It should have a validation error after the first one.\u003C/p>\u003Cp>Speaker 0: Yeah. Alright. Oh, yeah. That's true. Oh, no.\u003C/p>\u003Cp>Speaker 1: See if\u003C/p>\u003Cp>Speaker 0: it does. No. No. No. No.\u003C/p>\u003Cp>Speaker 1: That's a lie. Sorry. It will it will go until it fails. Just ignore me. That was incorrect.\u003C/p>\u003Cp>Sorry.\u003C/p>\u003Cp>Speaker 0: Is up. So that was our first one. Is up failed. Must be up, and then it dot stopped.\u003C/p>\u003Cp>Speaker 1: That's not correct.\u003C/p>\u003Cp>Speaker 0: Did I do is up twice? Is left, is up, is down.\u003C/p>\u003Cp>Speaker 1: Oh, no. No. It's connected to read data. It needs to be connected to the reject path of is up.\u003C/p>\u003Cp>Speaker 0: Oh, there we go.\u003C/p>\u003Cp>Speaker 1: Not that one. There we go.\u003C/p>\u003Cp>Speaker 0: Yeah. Yeah. Yeah. There we go. Oh, did too much stuff.\u003C/p>\u003Cp>Disconnect, save, edit, reconnect.\u003C/p>\u003Cp>Speaker 1: Oops. I'm glad. I'm no. No. No.\u003C/p>\u003Cp>Reject. Reject. Yeah. I'm glad we finally got back to that point of just finding that little that little set of actions. I can't believe it got us so, so much.\u003C/p>\u003Cp>But, yeah, I've submitted\u003C/p>\u003Cp>Speaker 0: that as a bug report. Awesome. Alright. Let's refresh this. And we should be now we should be seeing the process that you were hoping for.\u003C/p>\u003Cp>Speaker 1: Yeah.\u003C/p>\u003Cp>Speaker 0: Lots more moves there. So we should be seeing is oh, yeah. Here we go. Awesome. Yeah.\u003C/p>\u003Cp>It's up. Validation error. Validation error, validation error, validation error.\u003C/p>\u003Cp>Speaker 1: Why is there a validation error on all 4? It has to be one of them.\u003C/p>\u003Cp>Speaker 0: Oh, last must be of type object? I wonder if that is not Oh,\u003C/p>\u003Cp>Speaker 1: of course. Last is the last step. We've foot gummed by using last, which I actually spoke about in a previous episode. What we wanna check is, can you click into read data? The read data Yeah.\u003C/p>\u003Cp>Key is called get game. Right? So let's maybe rename this game. So if you go up to the key in the top right of this whole pane, scroll up. Yeah.\u003C/p>\u003Cp>Yeah. And the last will always be the one that came before it. But in this case, we're chaining a bunch. So, like, changes. So we actually wanna change.\u003C/p>\u003Cp>So if we change this to just game, let's keep it nice and short.\u003C/p>\u003Cp>Speaker 0: Perfect.\u003C/p>\u003Cp>Speaker 1: And and, yeah, save. And now we could do it in is up. The is up last is correct, right? But in all the others, it isn't lost anymore.\u003C/p>\u003Cp>Speaker 0: And then we're just removing this, and it's actually just gonna be game. Right? No Correct.\u003C/p>\u003Cp>Speaker 1: Yeah. Correct.\u003C/p>\u003Cp>Speaker 0: Okay. So let's go No,\u003C/p>\u003Cp>Speaker 1: dollar sign.\u003C/p>\u003Cp>Speaker 0: Yeah. Or no dollar sign. Yeah. There we go. And let's call this one game.\u003C/p>\u003Cp>Oh, game. And copy that this time. And I'm quite impressed with where we've gotten here. I feel like episode 4 finally figured things out.\u003C/p>\u003Cp>Speaker 1: Yeah. Alright. Here we go. So Yeah. So now so so let's test that once more.\u003C/p>\u003Cp>And while we're doing that, let's talk about what's next. Because all we're gonna do is execute the most basic strategy, which is to just return, move up, down, left, right. And we're not gonna do anything more fancy here. Right?\u003C/p>\u003Cp>Speaker 0: You would implement\u003C/p>\u003Cp>Speaker 1: is up, not correct. Is down though, is correct, which Awesome. Great. So now out of each of these success paths, now we need to run the strategy, which of course could be a lot more convoluted. Another thing that's worth noting is there is a flow operation, which is to run another flow.\u003C/p>\u003Cp>So you could you could kind of modularize your strategies into separate flows, go off and call those those come back with the response. And then so, you know, there are ways of organizing your flows. It's not just one big mega flow. But it's I think for what we're doing, it's beyond the scope, but that that would kind of be how you organize game logic, I think.\u003C/p>\u003Cp>Speaker 0: Great. Okay. So what are we gonna do here? What are we we're sending this\u003C/p>\u003Cp>Speaker 1: to We are literally gonna return. So run script. So sorry. I run script was near the top. And the reason we're doing run\u003C/p>\u003Cp>Speaker 0: script just to move and then up and down and left. You got it.\u003C/p>\u003Cp>Speaker 1: That's awesome. You got it. Because in the trigger, we said respond with the last operation. Yeah. I love that.\u003C/p>\u003Cp>Speaker 0: All right. So let's just grab that, save, and let's do oh, yeah.\u003C/p>\u003Cp>Speaker 1: Then that's correct. Yep. That's correct. So that's the is up success path. The names and the keys no longer matter, because If\u003C/p>\u003Cp>Speaker 0: we unless we forget which one where it is down, so this one's gonna be down. Save that, and then we're gonna go here. This is left.\u003C/p>\u003Cp>Speaker 1: I'm glad you you've come with me on the up, down, left, right rather than the clockwise.\u003C/p>\u003Cp>Speaker 0: We got there. We got there eventually. We got there. Alright. And then our final one is gonna be right here.\u003C/p>\u003Cp>And then this one's gonna be run script and\u003C/p>\u003Cp>Speaker 1: return You got it.\u003C/p>\u003Cp>Speaker 0: Move right. And let's see if this works. So if this works, our move right now is down. So snake should go down if everything is done the way it's supposed to be. So we've been going up because it's been failing.\u003C/p>\u003Cp>Now we should go down. Alright. This doesn't necessarily mean it's working yet because let's see if we go right. Save. Did we just actually implement this in, like, an effective way?\u003C/p>\u003Cp>This is wild. I'm, like, kind of\u003C/p>\u003Cp>Speaker 1: Hang on. Hang on. Hit play first.\u003C/p>\u003Cp>Speaker 0: We don't know yet. Yeah. What is up?\u003C/p>\u003Cp>Speaker 1: Snake went right straight off the board and died.\u003C/p>\u003Cp>Speaker 0: This is fantastic. I have never been so happy to see a snake die. I mean, last episode, I was really happy because we really wanted our snake to die. But, like, I'm\u003C/p>\u003Cp>Speaker 1: Oh, yeah.\u003C/p>\u003Cp>Speaker 0: I'm far more happy. That's pretty freaking cool.\u003C/p>\u003Cp>Speaker 1: That is cool. But there was one final part, and then I think we're we we can we can call it on ReadySet Battlesnake, at least season 1 of ReadySet Battlesnake, who knows, which is right now we are saying all users that there is no segmentation. There are no different audiences. It's just everyone gets one response. But in the flow creation, in this start game, you know, flow, we can put in a dynamic value there.\u003C/p>\u003Cp>Now, I do not know how this works in dev cycle. Is this something that's viable?\u003C/p>\u003Cp>Speaker 0: Yep. Yeah. Yeah. So hold on. Let's go back over and actually look at this.\u003C/p>\u003Cp>Because you said words and I heard the words, but then I stopped hearing the words. And so let's, let's go and shift this in that flow. And so we could do it in our in our dashboard. Right? We could actually\u003C/p>\u003Cp>Speaker 1: We we we wanna do it in both. So here in the start, right, in the dev cycle operation that we created, if you go in and edit it, you see we put in our as fixed snake. So the question here is right now we're getting I think there's a step missing here, which is we want to register users.\u003C/p>\u003Cp>Speaker 0: No. No. You don't actually so you don't technically need to register them there. Oh, I've gone all blurry. Hold on.\u003C/p>\u003Cp>Hold the phone. Why have I gone all blurry? What's happening? There we go.\u003C/p>\u003Cp>Speaker 1: Alright. I'm back.\u003C/p>\u003Cp>Speaker 0: I'm back. Okay. So what we can do here is this is all just stuff used for targeting rules. So let's say, okay. So you know how if it doesn't see anything, it goes up.\u003C/p>\u003Cp>Right? Correct? Not right. I shouldn't say right. If if it Yeah.\u003C/p>\u003Cp>If it's not seeing anything, it's gonna do that. So let's leave this as ready, set, Battlesnake and go over to the platform here Yes. And say Yes. Go, let's say go left, but only if the user ID contains ready.\u003C/p>\u003Cp>Speaker 1: But but what I'm wondering is, can we get this to a spot? And, like, we can assume the outcome here, like, we'll we'll we'll do this. But what I'm wondering specifically is can we, in 10% of games, maybe this is about the game ID and not the snake ID. So maybe the the name of the property isn't quite right. But can we say in 10% of games or 10% of users, I suppose, can we change it?\u003C/p>\u003Cp>So in that case, when we first feed it the snake ID, which will make the game ID, is that can we do that?\u003C/p>\u003Cp>Speaker 0: Yeah. It's just this. You literally set it to random distribution, and we say that we wanna serve 25% each of these distributions, and it will automatically do this for all users.\u003C/p>\u003Cp>Speaker 1: So we don't need to do anything with this passing a random name or anything? No. I mean, you could do it within that. You could say only the snakes that have ready in it. Yeah.\u003C/p>\u003Cp>Exactly. Do this, you know, so you can further branch that logic down and get a real small selection of your audience. Should we remove that, the first set, the first conditional where you put ready? Yeah. Should we remove that,\u003C/p>\u003Cp>Speaker 0: I guess? Because it's kind of just do all users. Yeah. And now we're just saying that all users random distribution. A random distribution.\u003C/p>\u003Cp>Speaker 1: So if\u003C/p>\u003Cp>Speaker 0: I save this, we should see if we run, say, 10 games, we should see something similar to that. So let's make sure this works. That's good.\u003C/p>\u003Cp>Speaker 1: Oh, that was remarkably easy.\u003C/p>\u003Cp>Speaker 0: It is very smooth.\u003C/p>\u003Cp>Speaker 1: But but there is that other thing still where, like, if we if we register, can we say, no, ignore me. That makes part of that same mistake.\u003C/p>\u003Cp>Speaker 0: All of these things are possible. If you can feed information into the platform, then you can you can do lots of stuff with it.\u003C/p>\u003Cp>Speaker 1: And we've only discussed all of these ways of feeding data in, so we don't necessarily need to go too granular. But, yeah, let's create a ton of games.\u003C/p>\u003Cp>Speaker 0: Okay. So here we go. So let's go first game. So we went left first game.\u003C/p>\u003Cp>Speaker 1: Sure.\u003C/p>\u003Cp>Speaker 0: Let's go create rematch. So we're going left. So that's 2 for left. Let's create a rematch. We should start going a different direction, and we're not.\u003C/p>\u003Cp>Maybe I didn't save. Hold on.\u003C/p>\u003Cp>Speaker 1: Yeah. I was gonna say, did you hit that save button?\u003C/p>\u003Cp>Speaker 0: All users, random distribution, schedule, none. No random distribution. We should be seeing that. That. All users feeding that in.\u003C/p>\u003Cp>25%. K. Let me change this. I just wanna see if something happens. A 100%,\u003C/p>\u003Cp>Speaker 1: 0. Oh, you you you have to make it worth what happens if it exceeds a 100 there?\u003C/p>\u003Cp>Speaker 0: I don't I don't know. I'm curious. Yeah. Yeah. So we should see this.\u003C/p>\u003Cp>Like, all users should ever run a 100% should be there. Random distribution might require something else, but let's see.\u003C/p>\u003Cp>Speaker 1: Yeah. Maybe.\u003C/p>\u003Cp>Speaker 0: No. No. That's right. Yeah. I guess\u003C/p>\u003Cp>Speaker 1: if I may.\u003C/p>\u003Cp>Speaker 0: It must just be the logic that's being used in there. So let's do 5050, and that might be a little bit easier. 50 right, 50 down, and see if that Sure. Does it. That's there.\u003C/p>\u003Cp>It also does say a couple minutes to update. So let's see.\u003C/p>\u003Cp>Speaker 1: Yeah. Maybe that's it. Maybe there's a little cache. Which is fine.\u003C/p>\u003Cp>Speaker 0: Right.\u003C/p>\u003Cp>Speaker 1: As I say, our snakes aren't spawning in particularly in particularly good spots to live. They're not? This isn't feeling unless it is really that thing because you you don't need feature flags to be literally like sub second. Know, there can be a little bit of a of a moment there.\u003C/p>\u003Cp>Speaker 0: Yeah. So this is over, like, a longer period of time. So that might be part of it, but we should see a down eventually,\u003C/p>\u003Cp>Speaker 1: because\u003C/p>\u003Cp>Speaker 0: the logic that's there is technically correct. Oh, you know what it is? No. I'm wrong. Here's the thing.\u003C/p>\u003Cp>I I totally forgot about this. So because it feeds in user ID and we're feeding in the same user ID every time. So if we wanted to change this, it's actually not that bad. So that So this is\u003C/p>\u003Cp>Speaker 1: actually what I wanted. Yeah. Yeah. So users and that makes sense because in the real world, you have a feature flag. You don't want that user getting a random thing every time they reload.\u003C/p>\u003Cp>Speaker 0: Yeah. So ready, set, battle, snake was getting right after Oh, no.\u003C/p>\u003Cp>Speaker 1: No. No. No. Hang on. Hang on.\u003C/p>\u003Cp>Go back. There's a there's a better value to put in here. Let's put in the game ID. Let's put in the because that's random. That's in every new game is a new is a new That's true.\u003C/p>\u003Cp>User in this context. So actually\u003C/p>\u003Cp>Speaker 0: grab game.\u003C/p>\u003Cp>Speaker 1: Okay. Double double, double brackets first, and it will be trigger dot body dot Game\u003C/p>\u003Cp>Speaker 0: dot ID.\u003C/p>\u003Cp>Speaker 1: Game dot ID because that's a random value each time. Yeah. It is. That's good. Yeah.\u003C/p>\u003Cp>Yeah. Yeah.\u003C/p>\u003Cp>Speaker 0: That might that might do it. So we should now see 5050 if it works, which it may not.\u003C/p>\u003Cp>Speaker 1: Mhmm. Mhmm.\u003C/p>\u003Cp>Speaker 0: K? Good. So right on the first one, right on the second one. It's not looking good so far.\u003C/p>\u003Cp>Speaker 1: It's not looking good so far, is it?\u003C/p>\u003Cp>Speaker 0: Oh, there we go. Hey. Hey. There we go. So So\u003C/p>\u003Cp>Speaker 1: that logic that I think that's Andrew, I I I'm I'm both really happy that we got this to work, But I'm also kind of sad because I think I think that might bring us. What do you think?\u003C/p>\u003Cp>Speaker 0: I think I think we have we have eaten into to your evenings for many, many dates.\u003C/p>\u003Cp>Speaker 1: Not for that reason. Not for that reason, but just I think that's I think anything more now is us just in hot like, doing things we've already done, but in this slightly altered context, but that's awesome. So you can really, like,\u003C/p>\u003Cp>Speaker 0: yeah. So smooth. Yeah. I gotta say, like, I when we set out to do this, I knew that we might be able I knew Directus would work. Like, that made sense.\u003C/p>\u003Cp>But when we decided that I was gonna take the lead for the final show and we were gonna do the dev cycle, I was like, I don't know if this is gonna actually work because I tried to implement dev cycle with Directus a lot of ways. So I'm over the moon that this works. And, like, what a cool piece. And it's so fast too. Right?\u003C/p>\u003Cp>You're not having to worry about direct us doing anything. It's all managed externally. Like\u003C/p>\u003Cp>Speaker 1: Yeah. And and part of this is an approach that we chose. And this is a very battle snake kind of thing. It is an approach we chose to make sure that we are we're not combating that 500 millisecond return require return requirement. And that is because we determined a strategy at the beginning of a game, not every move.\u003C/p>\u003Cp>So there is a couple more round trips within directors. We're having every move to go and figure out the game strategy, but this is all internal. These are just little database operations. That's awesome. And then, of course, going back to the last episode, we could now enrich our insights dashboards and saying when this was the strategy, this was the outcome.\u003C/p>\u003Cp>We could use the little global variable drop down to to pick. We could even go off to dev cycle, populate directors with all viable strategies, That was awesome. That was fun. Happy?\u003C/p>\u003Cp>Speaker 0: This was a fun day. I'm I'm so Kevin, I was so it's been a couple episodes since I've been, like, on the keyboard. And, like, you were walking away so pumped after every and I was happy. I was definitely feeling it. But, like, I'm having a good this was a good It's good.\u003C/p>\u003Cp>This was a good day. We got we got things working, and our snake does the things, and other people can now go and use this to meld the world's all the d's, Directus, Devcycle.\u003C/p>\u003Cp>Speaker 1: Yeah. What what do you say, as for as for Directus as a Battlesnake engine?\u003C/p>\u003Cp>Speaker 0: I love it. I think it's super, super smooth. And I love the fact that there's actually, some code that exists out there for building a dev cycle management setup within the Directus platform. So, like, like, use Directus and then implement dev cycle and then play Battlesnake. That's the real that's the real goal here.\u003C/p>\u003Cp>Do Everybody wins. Everybody wins.\u003C/p>\u003Cp>Speaker 1: Everybody wins. Everybody wins. Everyone, thank you so much for joining us. Andrew, thank you for getting on board with this idea to to, you know, have a Battlesnake video, you know, series after after a little while. Thank you audience for joining us for this limited series of Ready Set Battlesnake.\u003C/p>\u003Cp>If you want to learn more about Battlesnake as with all of these episodes down in the resources, you'll find a link to the docs for Battlesnake. It is such a satisfying and fun hobby project for developers at all stages of their career, whether you're just getting started or you are really pushing, you know, your very, very advanced knowledge and it becomes an optimization game. There's something in it for everyone. I'm glad they all worked. Honestly, there were so many points in this where we might have discovered this doesn't work irreparably and the whole thing's ruined.\u003C/p>\u003Cp>And every barrier we came against, there was a solution primarily actually through the ability to build extensions. Yeah. So that is wonderful. Oh, lovely. And a melding of my world as a big time and long time battlesnake lover and running dev rel, at, director.\u003C/p>\u003Cp>So Andrew, once again, thank you so much.\u003C/p>\u003Cp>Speaker 0: You're welcome. And should we do it our one last try? This is our last opportunity? So\u003C/p>\u003Cp>Speaker 1: here we go.\u003C/p>\u003Cp>Speaker 0: What do you mean? What do you mean? You have little faith? This is it. You have a So here we go.\u003C/p>\u003Cp>What do\u003C/p>\u003Cp>Speaker 1: you mean? What do you mean? You have little faith. This is it. You ready?\u003C/p>\u003Cp>Speaker 0: Alright. Here we go. Alright. Do you want to count it down? Should we count it down first?\u003C/p>\u003Cp>No. Hang on.\u003C/p>\u003Cp>Speaker 1: Hang on. Hang on. Hang on. I've got it. Uh-uh.\u003C/p>\u003Cp>Alright. This has been\u003C/p>\u003Cp>Speaker 0: ready. Ready. Set. Set. Battlesnake.\u003C/p>\u003Cp>Battlesnake. Bye for now. Bye.\u003C/p>","Hello, everybody. Hello. I'm sorry, Kevin. Ready yet. You are ready. Alright. Let's try this again. Alright. 3, 2, 1. Hello, everybody, and welcome to ready no. I didn't know where to do that. We're gonna do it. Ready. Ready. Set. Set. Battlesnake. I don't think we're gonna get it, Kevin. I don't think we're gonna say the final episode of Alright. We're gonna try this again. I feel like this is I feel like this is good for the final episode. Let's do this. For the final episode. Let's get this right. Welcome to the final episode of Ready set, set, battle mistake. Mistake. We're close enough. We got there. Close enough. We got there. I'm gonna count it. Alright. So welcome, everyone. Episode 4 of Ready, Set, Battlesnape. I'm Andrew. This person either down below or to my right or left. I don't know where he's he is right now. Direction. Is Kevin, and we are your your snake charmers, your code, your code coaches, your, your fun fans. I don't even know. But we are here today. You are fully overestimating our entertainment value. I I don't know what you're talking about. I feel like our entertainment value can never be underestimated. We are we are more entertaining than we even think. Thank you so much for coming back and checking this out, Kevin. Thank you so much for for coming back again after I kinda threw you, a little bit of a, a little bit of a challenge at the end of our our last episode together. It was tough. But we got there. I'm sure you'll return the favor to me today. Yeah. So if you haven't caught episodes 1, 2, and 3, you should probably go back and check those out. We, kind of we're gonna talk a little bit more about exactly what we've been doing, But, in episode 1, we built a Battlesnake, and we'll talk a little bit about Battlesnake kind of as we go through. Obviously, in episode 2, we implemented, that same logic from our 1st JavaScript starter snake in, Directus. In episode 3, we added a whole bunch more logic to our snake but mostly just to visualize the games that were coming through the platform. And today Kevin, do you know what we're doing today? I I do, but I will let you I will let you share. I think it's your turn. I think it is. I feel like you've been leading the show for the entire time. So it's probably my turn. Also, I feel like should I be let me see. I'm, like, wanting to be more centered. Oh, where are we? There we go. Now I'm feeling good. Okay. Good. Alright. I thought that, like, make make the choice to change where your camera is as you're as you're on on camera. Yeah. Screw it. Why not? Good vibes. Good vibes. So, on today's episode, we are going to be, implementing a new technology that we haven't really looked at, called Devcycle. And so, you now know from the last few episodes about what Battlesnake is. You know what Directus is because you're here on Directus TV. And so now is the time to introduce you to the technology that I work with on a daily basis as a developer advocate at Devcycle, which is a feature flag management platform. So our plan today is to try and add some logic to our, Directus snake to get this, working is maybe a relative term. Getting the the dev cycle platform yourself a lot of scope there. A lot of scope. Working is a relative term. But we're gonna use the dev cycle platform to, add a little bit of, add a little bit of flavor to our snake and give it a little bit of, give it a little bit of control. And that will make a lot more sense in a minute. But Kevin, you look like you have something to say. I I mean, I'm gonna ask the question which I think you're probably gonna work towards, which is like, can we just talk for a moment about what feature flags are and then maybe what you had in mind, and then we launch straight in. I love it. So, a feature flag, if you've never heard of them before, condition conditional statement in your code, that allows for you to, turn features on and off depending on a bunch of targeting criteria. So let's say you are working on a new feature on your platform, or a new feature maybe for your Battlesnake, and you're not quite ready to to roll that out in all of the games, you could add a feature flag. Just wrap it around the code and then through a feature management platform like DevCycle, you can say, for these kind of games, I want you to use kind of this logic. And for these kind of games, I want you to use these this logic. It's a really big part of things like trunk based development. So if you're moving from, like, branch based development where you're sort of, like, having features in branches that are long lived, and then we all had to deal with sort of, like, long lived branches and merging and dealing with merge conflicts. Mhmm. Feature flags are kind of a way to avoid those things just by constantly having your new features in code, and you can kind of decouple the code release from the feature release process. Interesting. Okay. And just to embellish this with my understanding, and you can tell me if I'm wrong, they basically work. So you put these conditional statements in your code, and what triggers those is this feature management platform. And typically, you would do that with some form of either like AB testing where people get allotted into these random buckets or you can be a bit more pragmatic and say 5% of users are gonna have this conditional turned on and therefore get a new feature. And then we will also, like, we'll analyze their behavior as a result and decide whether it works, if people get it, and so on, rather than going it's an all or nothing kind of deal. Right? You got it. You got it. Got it. That's it. Alright. Money. So Great. That is a very ambitious plan that I just laid out, by the way. I I feel as though may we get to a stage where we're able to, like, just determine, what kind of gameplay we're gonna have? That's possible. Maybe not in a 2 hour stream, but, we are gonna get Directus and Devcycle working together. How do I know they work together? Because I've already written a blog post on this separately from Battlesnake, so I got to explore. And so now is the time to use my knowledge for for good and for evil. We'll link the blog post, by the way. We'll link the blog post. There are 2. There's 1 on our blog, that Esther wrote, which uses dev cycle, and 1 on the dev cycle blog, which you wrote, which is direct us. And I'll put a link to both of them in the resources section that accompany this video. Yes. I love it. So, y'all are seeing my screen right now. And so up here, you'll notice that this looks very similar, to, 1, mister Kevin Lewis's screen, although not in the Arc browser. I'm not apparently a strong enough, software developer to use Arc. Not there yet. Once it comes to Windows, I'll start using it. It's it's it's happening. I know it's coming. I'm in a month of this. And then people will full on get this, but we're clearly recording this a day after the last one because they these are the games from the last episode they created about 23 3 hours ago, which is completely legit. We did something a little cheeky before this stream. We in a completely low rim fashion, you're running a director's to project. And I literally was like, here's a sequel database file and here's the extensions. Go run them and here's the creds I used to go log in. We may have to reconcile with that at some point when things break. So there is a chance things won't behave and we'll have to fix that on the fly, but should be okay. I love it. So we have our snake our direct to snake here. It's alive. It works. Not yet. We haven't determined if it works yet, which we probably will have to do. I also have our snake that was running on Replit. So the original, ready set battle snake that we created from the JavaScript starter snake. So Mhmm. I have that snake, but Replit was getting real mad at me today because I was using too much RAM and and compute. So I pulled that down, and put it into this wonderful, repo here. Yes, sir. And you're gonna be bumping your font size up about 5 times. No. We're gonna expect everyone to to zoom in. Exactly. Exactly. That's the look of the look at my spectacles. Everyone has. And so, yeah, let's let's zoom in here a little bit. Alright. So this is the the kind of the original snake that our code is based off. So you will notice here that not all the logic that we implemented over the past couple of episodes are in here. That's fine. This is more just to, like, show us how it's gonna work once we get there, and then we're gonna implement this indirect disk. We're gonna try and implement it in direct disk. But I think maybe the first thing we should do, Kevin, is actually get our Directus snake working. What do you think? I feel like that's a logical first step. And what we're gonna do to make that happen is we're gonna set up ngrok. And so do you pay for ngrok? I don't, but I have ngrok. So, like, I can I can set it up right now, but it'll be ephemeral? Incredibly heavily, like, rate limit to you. Let's pause here. Let's get NGROC set up and using temporarily my auth token, and then we will come back. Great. So this bit, we won't we won't publish. But, yeah, it was actually the one thing we forgot before we started. So let me just figure that out. Yeah. Throw me the key and then I can, Indeed. Alright. And let me just go to engrok now because I was actually logged in earlier. It was working for me in the games that I was playing, but, it but then it gets mad. That's the whole problem here. So what we want here is your auth token. So, here is the engrok command you are going to want to run here in the chat. Yep. Sorry. I'm just then because I'm on, like, old, the command looks slightly different, and that's there. Where are you hiding? Hold on. My windows have all disappeared. Where are you, Kevin? There you are, in chat here. Alright. Wonderful. There's a chat. Here's a command. We're gonna add this auth token. Beautiful. And we're gonna head back over here to our terminal and oh, nice. There we go. Paste. Beautiful. Auth token saved, and let's run Nice. This. It's good. I set up ng croc earlier. I knew Yeah. Yeah. Absolutely. Beautiful. Alright. Good. So I think we can actually snap back now, and Yep. It's up to you what you want on the screen. We could be here if you want. Yeah. I mean, I mean, if you've never used ngrok before, I mean, we talked about this in episode, I guess, 2. We were looking at this. I have the free version. Kevin's got one that's less rate limited, so we're using that one. But it's super easy to install. Like, just homebrew it, and then you add your auth token to ensure things are happening. But, anyways, we've got it running right now. And then my direct to snake over here is should technically be working. Now, Kevin, I'm really curious. You should technically be able to go and run a game on yours, and see if it works. And I'm interested I think Are you running directors? Apparently, I am not. I think I might have closed it. Nope. I'm running it. Yep. We're all good. Where is it running though? That's the real oh, you know it's running in another one. Do you have another I do. Versus code do. Window. There it is. Awesome. So we're gonna watch these logs here. We're gonna bump Shall we whack the font size up there as well? So I'll add ready set battlesnake and hungry bot once again to an 11 by 11 board. I'll hit start game. Yeah. And there we go. It's coming through. Awesome. We're working. And you're like, but Andrew and Kevin, we can't see the games, and therefore, this isn't fun and enjoyable for us. Us. Fear not. Because I think actually an easy way to do this so we can keep ready, set, battlesnake in your repo. Can you make ready, set, battles cake public so that I can add him to my Yeah. I can. Yeah. My battlesnakes. Ready set battles cake. We named it that. So it had a k instead of an n because it was the Kevin version of the snake as an FYI, and it is now public. Awesome. And so if you're ever in the Battlesnake platform, really easy. All you gotta do is just search for snake. Ready, set. Should find him skate. There we go. That's what we want it to look like. And so now we've got them in there. And now we're gonna see this game going on, and it should be all of our logic and direct us. Something's not happening. Something's unhappy here. Let's see what it is. Womp womp. I love that we tried and then we failed. Could you remove the what the old one password, pop up? I certainly can. Okay. There we go. Oh, no. Nope. Same thing happened again, actually. Create Rematch. So let's think it through. What is going wrong here? It could be that our flow isn't running correctly, but it should be. Yeah. Like, it's going off. It's triggering the flows. It's getting a 200, which means it's getting a response, and it's returning. So what is going what is going on? What is going on? We haven't gotten Because it was randomly breaking last time too. At the end of session 2, at the end of the second episode, our snake was, like, overpowered. Like, it was so good, and then it started to crumble. It started to grumble, last time. Let's take a look at our logs. We have got some logs in here. Holy moly. We do. Let's look here. So is there anything going on in here? We've got move now. Original. Yeah. So I think we've got something going on there. Some so what do we have here? Yes. Feeding a lot of things there. False, false, false, false. Oh, no safe moves. Avoid head to head. I think it might be in there. False, false, false, true, true. Yeah. I think the issue is in Which we've already determined that we think is the case. So you know what we'll do to keep ourselves moving? If you close the pane, why don't we just avoid that entire operation and just take avoid body straight to determine move? Avoid head to head is a, you have to just hit the little edit in the top right of the Oh, of course, we do see. Yeah. And hopefully yeah. If we just do that and hit save, yeah, just yeah. Oh, we're back. We are back. We're back. It's alright. We're there. I have a belief that if you just hit the save button enough times, we're gonna be able to resolve. I'm pretty sure that's the definition of insanity. I think it is too. We're gonna switch things up for just a minute. Yeah. And save this, and that didn't work. And then we're going to go back over here. And then we're going to go back here. And we're going to see if that worked. Oh, disk. It was a bug. It was a bug, by the way. And it had an issue has been opened on this bug. So there you go. Maybe just discard the changes and just we can have Alright. Let's see if we can create another game, see if this will do it. I mean Okay. The oh, nope. Still doing the same thing. Still so moving out of bounds, logic is there. It's definitely happening in 2 minutes ago. Let's get You have to refresh. Sorry. Alright. So let's go here, and let's see again. So determine move is still where things are, yeah, getting hung up. Oh, and you're saying avoid head to head is where everything went to force when they're logically, it should not been happening. I think so. Maybe that's what it is. Let's go avoid head to head options. There we go. False, false, false, false. Payload. Avoid bodies. Okay. So so you know what we're gonna do? We're gonna jump into avoid head to head, and we're just gonna return the inbound date. Like, we're not gonna do anything. Alright. Let's go in there and do that. So here we go. Right. Because that's clearly where it were. Yeah. We're gonna literally delete everything apart from line 2 and 30. So everything in the middle there, ditch it off. Doesn't matter. Can we not just oh, we can't comment. Really? I think no. So just but it's fine. We don't need it. This is this is the last episode. There we go. I also have a copy of it, so it's fine. Ah, success. Alright. So let's save this and see if it works. There we go. And now let's go and try and recreate a game again. Because if that's the step that was causing grief. It was. Yep. Do you remember when I wrote all that really elegant code and it worked fantastically? Turns out not so much. Well, it's alright. It worked fantastically until it didn't. And that is the key to all the programming. It's all good until, you crash production. Okay. That makes me feel better that we've identified the issue and removed it for now. Okay. So ready, set, battlescape is working, and this is really the key here. It's still doing the job that it needs to do. So we're gonna make, we're gonna do something a little bit different now. We are going to actually be, having we're gonna bring ready set battlesnake back from the dead, in a new world. So let's, let's kinda go over here. So this is good. Directus is working, and now we're gonna we're gonna ignore that Directus even exists for the next little while. And we're actually gonna head back over to Who needs to pay rent? Who needs to pay rent? Not me today. And I wanna look at, wanna look at our code here. And so is this okay for you, Kevin, or is it still too small? Yeah. Maybe take up another yeah. Maybe that maybe that's good, I think, for people watching. Awesome. So in here, not a lot has changed from when we were dealing in replit. So we still have our server dotjs, which is just an express server. We've got the 4 endpoints, the sort of root endpoint, start, move, end, and then we've got a bunch of stuff in here that's kind of, yeah, talking about what it's returning. We've got a read me here, which explains just how this works, which we don't really care about right now. And then we've got our package. Json. I haven't added anything new to here except for this new dependency, which is the dev cycle, SDK. And so this is necessary for us to implement dev cycle. If we want to do it this way, technically, we could do all of this via our management and bucketing APIs, but I think it's cleaner through the through the SDK. And then, there's some small changes. There's another file that's here, and we'll maybe call this in just a second. And I'll explain how I got to this file, which was not fun this morning when I was prepping for the show. So, originally, in here, we had our run server. We had our info endpoint. We had our start and end endpoints. And then we had this move endpoint, which actually had some really good logic inside, that if we go and ignore all of this stuff, here was our original logic. And I'm gonna uncomment all of this stuff. Oh, I'm gonna try and uncomment all of this stuff if I actually uncomment the right section. There we go. So this was our original logic. And I'm actually think just to make sure that this is working because, yeah, I've changed this so it wasn't async now, which was part of my issue earlier. I'm gonna save this. So this was sort of our dumb snake that we first started with. So Not dumb. Yeah. But, like, dumber. And so you can see here all of our steps have kind of been implemented here. The base steps here, same thing that's going on over in Directus. Disk. So let's see if this is working. I'm gonna run this express server. I think it's node index dotjs. So this is gonna run How are you gonna expose this as a Battlesnake if we're already running ngrok for directors? Oh my good guy. Also, updated cache direction to down. It is constantly running that caching. Interesting. That's fun. So the caching wasn't originally there, Andrew. So Wasn't. And please tell us about the cursed file. So we're gonna ignore the cursed file for a minute, and then we'll get to the cursed file. But let's see if we run this right now. Technically, I should be able to run 2, right, through engronk? I'm not convinced, but we'll we'll find out. Okay. What port does Directus run on? Not that one. K. Well, let's see if this works. No. It works. It's there. No. No. No. No. No. No. No. No. No. No. No. Locally, but you still have to expose it. Yes. So can you see if one shows up in your, is it list it'll show up on your ngrok dashboard on your end if it's running. I didn't even know there was an ngrok dash I didn't even know there was an ngrok dashboard. We'll see. But yeah. Let's take a look. So behind the scenes, I'll actually pull this up just so people can see what this looks like. So when you go to the ngrok dashboard and you're logged in, if I am logged in, so you have, like, this authentication and set up stuff. And then you also have this tunnel section. And in the tunnels, I think it's tunnels where it actually shows you, yeah, what are currently online in your account. Account. And so you should see you should see I've got one. You've got one? K. So this is not doing what we wanted to do. Wait. Wait. Wait. Wait. No. No. Yeah. And the one is you. Oh, it is? Yeah. Started 10 minutes ago. I'm not running anything locally. That's that's Directus, though. That's why. That's directives. Okay. So here's what we're gonna do. And now we need to try and run it a second time, but I'm not convinced. We can shut down directives for right now because we don't need it as we're just kinda demonstrating how this works in the index dot JS. So we're gonna shut down Directus for a second, and then we're gonna run it over on our other one. Alright. So we've shut down Directus, and let's go back over to index dot j s. Let's cancel this out and awesome. Restarted that. What is the address that I'm wanting to go to, Kevin? Can you paste it somewhere for me? I don't understand what you're asking. Never mind. I But, also yeah. I've But you're not running ngrok yet. Right? Oh, that's right. I have to rerun. No. I am running it. You need to rerun it. Exactly. Rerun ngrok. Yeah. Oh, there we go. Got it. Bad things happening. Okay. Let's go But this time, not 8,055. Yeah. Yeah. 8000. Alright. Here we go. Beautiful. Alright. Alright. So let's go over here and see if this is working. Beautiful. Alright. So this is running now. So if I go back over here to account settings oh, not account settings. My battle snakes. I'm gonna go ready set battlesnake, and we're gonna leave a JavaScript, and we're gonna have this on nothing, no platform today, and then we're gonna change our server URL. Yes. Like that. And now if I go in and add ready set set, Battlesnake to a game, create game. And ready to set Battlesnake. Remove the Octa thing in the top right? It's very annoying. My goodness. All of the prompts. And then we are going to see if this runs. Okay. Good. Basic logic, not running into himself, not running into walls. Good. So he's working. Alright. But I haven't implemented the logic for dev cycle yet. So let's go look at what's going on. So we've got the moves that are feeding through there. That's awesome. That's what we want. I'm gonna actually turn this off for a second, and then turn it back on. No. I'm not gonna turn it back on because it's gonna constantly need to be caching. Okay. So, that's our basic code. Right? We're good. We're there. We're not here for basic code today. We are here for confusing broken code that will cause many problems and will make our heads hurt. You're really teeing this up, and I'm horrified before we've started. Don't worry. You and me both. So let's look at the new logic that I have in here, which is not great logic, but, I'll explain it. So, what we're doing is every time the move endpoint is called, this move function is called. Yes? Everybody should track that so far. So what I'm doing here is I am calling a, this get cache direction function, which is basically every second or millisecond. I'm not sure. I think it might be millisecond. It's calling the dev cycle, platform and asking what move should I be getting for whatever user is on the platform right now. This will all make sense when you kinda see the logic, but, basically, it's it's pulling the dev cycle platform to ask it what move you should be making as a snake. Does that make sense? Yeah. I think your face Unfortunately, this isn't even remotely the direction I thought we could go in. No. Don't worry. We're not gonna we're not gonna manually we're not gonna manually do this. We're I just wanna demonstrate the, like, how it actually functions. And so this is good. Mhmm. And I actually you can do it mid game too as long as your your click game is is on point. Oh, man. Which we can do today because there's 2 of us here. So Oh my god. We're gonna go and actually look in this cache dotjs file. So here's our cache.js file. Couple things happening here. First thing, we're importing the server SDK that this dev cycle from there. Then we're initializing our dev cycle, client in here, despite it being a server application, we're calling it a dev cycle client. This stuff is That's fine. That makes sense. Yeah. This stuff isn't super important, the cloud bucketing and enable EdgeDB. It is and isn't, but really the important thing here is that we're initializing the dev cycle client. We're creating this cached direction, which is setting the default move for our snake to go down. So, basically, if, the first time, if there's been no caching, if this has never run before, it's gonna go down. And then, yeah, within this function, we're feeding in the user variable. So you have to feed this in every single time that you, that you do anything with the external platform. You have to feed to the user. You can feed in custom properties, which we may try and do today, where you can, like, base it on different information that you may have. But this is the idea here. And then once we've got this dev cycle, client established, we're then going to look for a specific variable that exists in the Dev cycle platform. Think of a variable as, like, the feature flag that you're looking to pull. So whether you're wanting to see on or off, we're actually pulling a string. So we're pulling for the direction for this user. What should this user be seeing if we're looking for the direction variable that's in there? And then we've got if we do end up having a preferred direction. Yeah. Because where's my preferred direction defined? I think it was defined over here. Right? Yes. There we go. So, preferred direction. So, basically, it's saying that if there is the DevSecLE client being established and it finds that that direction variable exists, then we're gonna look for that preferred direction variable that we had defined over an index.js. And if it returns anything but none, it's going to put a new cache direction value in there, and then it's gonna log that it's updated the cache direction. Otherwise, it's gonna give you an error. And then if we go down here, yeah. We're basically updating this every 10 it's not ten seconds. This is, like, every 10 milliseconds. That's very, very often. Very often. So a1000 is one second. Yep. And then I gotcha. Yeah. So this is our code that we're doing here. Basically, we're just constantly pulling the dev cycle platform to, like, get the latest updated stage. So there's a little bit of a delay here, but it works pretty well. I will believe it when I see it. Gonna be honest, mate. Okay. Alright. You're like, this is garbage spaghetti code. What are you doing, Andrew? It's not like it's not the code. It's just this isn't how I would have. Can I give you maybe an idea of how else we could have implemented this sort of code? Yeah. Let's yeah. Let's go. We literally just have, like, branching logic in the flow. And based on, like, there's the snake gets an ID for every game. So you can enroll them and then, like, 10% of the time or whatever, they get thrown into, like, strategy 2. And strategy 2 could be it become it just goes left all the time. Like, it doesn't matter. Yeah. But you could implement branching logic. Right? So we are and that is what we are gonna do. So you're not wrong with that. I just wanna show how this works. That's fine. Okay. Then we can get into the logic. So Okay. That's our logic here. So, basically, we're calling this every 10 seconds, and then it's gonna if it's updating, it's gonna show us this using cache direction, and then it's gonna do that. And just to clarify, the whole reason you've created this notion of a cache direction is so we're not gonna go to dev cycle every single move. We will go a 100 times a second instead. So what's what's interesting is because we're basically running an async method here, there's a delay and devs battle sync doesn't like there being any sort of a delay. So I had to I completely got it. So you have to have some I got it. Yeah. You've gotta do the polling yourself. I think you probably if I was a better programmer, I could probably figure it out, but this was like No. No. I I I get it now because you could call dev cycle every time, but you're not gonna be able to respond within 500 milliseconds confidently. Yes. So for that reason, instead, we will catch the last direction it gave you. Exactly. I got it. I got it. That makes sense. Fine. You're I'm with you. And it's interesting. The reason I figured out that this was working is so if you notice here, in the logs, so we actually it returns move 117 right. What I was seeing in my logs was it would be like move 01746328. And so it was taking time to actually do the the the calculation. So anyways Which is no good for the snake. It just won't work. Yeah. And so I'm gonna leave this I'm gonna leave this at, at 10 milliseconds for right now, now only because I'm running on my own device, and I think your end grunt won't get upset at me. And because I know that it will demonstrate how this works. The downside here is I actually, Kevin, will need you to be the one that is starting no. Because nobody's gonna be able to see it. Okay. We're gonna see how fast Andrew can click things is what we're actually gonna see. So we're gonna start this again. So if everything's working properly over here, I've uncom oh, I've gotta uncomment this. Let me cancel that again. Let's uncomment that import statement. I think all the rest of this logic has already been commented. Awesome. So now if we run this yeah. So we're basically checking this, like, every 10 milliseconds. It's kind of crazy. I don't fully know why I don't think it's running every time it shouldn't be. I'm unsure logging every time it's making your terminal choke. Here's my question though, is we're not calling move all the time. So I'm confused why That's a good point. Get cache direction is being called every single time because it shouldn't be. It should just, like, literally only be called when moved unless I've got a game running somewhere. Do I have a game running somewhere? You shouldn't be. No. I don't even know how you would check that. Yeah. I don't know either. But, like, if I look at this okay. Request made. Oh, are you the squiggly brackets? Yes. The destructuring. I shouldn't have done that. Alright. So, yeah, it should not be running. It should be running every time. What is going on here? It must be something in this actual cache file. Let's see what's going on here. Import dev cycle, initialize dev cycle, let cash direction go down, update cash direction, import dev cycle. Yeah. Because you're set into it here on line 33. So that's happening regardless. That's happening the moment it's imported. That's not linked to that function running. I don't think it's that much of an issue. I'm gonna change this to, like, a 100 because what's that? That would've that was gonna be my only suggestion is maybe just knock it knock it down a bit. Okay. Yeah. Anyways, we're gonna do this. We're not gonna do a lot of this, because it's gonna be less important. But, we're gonna set this running, and then we're gonna go and actually take a look at the game. So here we go. So we're basically changing this direction, and I'll actually actually, let me cancel that for a second. And I'll go to the dev cycle platform so I can show you. I already set this up. Yeah. Yeah. Yeah. That'd be good. Here are the dev cycle form. Once I log in once it logs in come on, dev cycle. What are you doing? Oh, there we go. Logged into the wrong one. So we actually just launched a, a bunch of new example apps, and so I've been playing around with those. But there's no way to log out without, getting rid of the the demo mode. So, that's how we're gonna log out. I feel like it's like a user retention is great if the user can ever log out, get a life hack. All right. Let's close these again, see if I close this. And let's try app.devcycle.com again. And I think this is gonna load. Yeah. There we go. Awesome. Log in with my work count. It's gonna bring us over to the dev cycle platform, all of our production stuff. We're not gonna mess with our production stuff today. Do it. Do it. Let your intrusive thoughts win. So I did it at, at KubeCon. I actually we made a bunch of live changes while we were doing demos, and our entire engineering team got very unhappy with us. And so I think we're ready to set Battlesnake. And I've got this features area here. So I've got a feature that I've set up called my choose move feature. And this is Could you, zoom in, sorry, 1 or 2 times? No. That's okay. The small text is quite small. We're good. Nice. Thank you. Perfect. Yeah. So we've got our choose move feature. This isn't super important for us right now because I've only got one feature. And then I've got this direction variable that I have there, and I've defined 4 different variations, left, right, up, and down. These are string variables that are in there. And then in my targeting logic, I'm basically saying who to serve what or what to serve to what users that are feeding into that SDK. So here, I'm basically saying serve all of the users down, but that's also my default. So I actually want to be serving to see if this is working and actually talking right. I'm going to change this to serve everything right. And if this is working now, when I turn on that Battlesake server, I should be seeing everything in this updated cache direction except for the first one showing as right. So let's see if that works. There we go. And even the first one did. So we've got the changes happening here. And now if I go back over to the platform, change this to up and save and then take a look at my logs. And so it's like real time changes that are happening in there that you're able to kind of differentiate what's going on. So the interesting thing here is that, technically, platform to control your snake in real time. It's a terrible idea. That is literally the like, like, we've seen people play Battlesnake live using, like, games controllers. And even that, you're like, well, there are some questionable choices here. This is like drop down and then save. So but I'll show you something inter I'll see if I can get this to work, and I'll just do a I started using, there we go. So I started using, rectangle, and Sure. I can't believe that I've never used it, anything like that. Oh, yeah. I use Raycast for it, and I have keyboard shortcuts. Oh, look at you. Which is really, really nice. So let's grab ready set battle sneak in here. And we're gonna go start gaming. Just ready set battle in here. And so you'll see it's not gonna work right now because it's not running. So he's going up. So we know it's not down. There's no conversations that are happening right there. So since we know that we've set our game mode to, let's change it to left so we know that something's working here, and then I'm gonna start my server. And now if I create a rematch, should go left. Awesome. So we know that it's working. Sure. Alright. So now I'm gonna do the thing that is, like, the test of Andrew's ability to click things really fast. I'm gonna create a rematch. And then in, like, real time, I'm gonna click save. And there should be a switch if the board is big enough. But, actually, I need a bigger board because that will give me more time for things to go wrong. Let's go 19 by 19. Add, ready, set, Battlesnake. Start game. Oh, I shouldn't have done that. Anyways, it's fine. You've done that. You you moved moved. Do do do do do. No. It's too late. The game already runs as soon as you click create rematch, so I gotta be a super fast. Alright. Here we go. So right now, he's set to go left. I wanna change it so he goes Don't worry about hitting play. Just hit create rematch, hit save, and we can see it in the playback that it's happened. Alright. Here we go. There we go. Oh, and he's going left first. So literally, the worst example that ain't gonna work. Before you create rematch before, you wanna yeah. Prime. Prime. Oh, yeah. Change it. So right now, we're going down. So we're gonna get it. So we're gonna go first, we'll be going down, and then we should go right as long as we know where it, as we long as we know where it spawns. Okay. This should work, actually. This should be good. So here we go. Should go down first, and then at a certain point, go right. Oh, not fast enough. We're gonna try this again. I tell you, it did it does work. You just gotta have the the right movement. Andrew, I full on believe you. You you don't have you're not proving anything. Don't worry. Come on. Really? Your your taste. Oh, did we see that? We did it. We did it. So here's the thing. Right? So we changed it from right to up. So we're going right. We're going right. We're going right. And then suddenly, we start going up. And that's there's no logic in here that says, dearest, dearest ready set battlesnake, avoid that wall. This is all just, Andrew changing that logic in real time. And you can see if we go to the logs there, which are gonna be, like, super overrun now, not that logs, these logs. But you can see here in our terminal there we go. Yeah. So we're updating our cached app, updated cache direction app. And so you can see that there's, like, the change that happens in here. Yeah. Oh, and this is the interesting thing too here. Right? Is you actually see so most of the time, it's updating cash Kevin, are you impressed? Are you blown away by my amazing implementation of this? I am so blown away. Thank you so much. I feel like my life has been genuinely enriched in the last 39 minutes of recording. Thank you, Andrew. I don't know what I would do without you as a friend, a mentor, a colleague. Thank you. Thank you. Good. Yeah. And that's it. Episode over. We're done. Episode wrapped. Thanks. So, that was just like this is I feel like in every good episode, in every good coding experience, you should do something that's totally useless and makes absolutely no sense so you have the knowledge and skills to do something that actually makes sense. But there are some things already set up. Right? So we've got the dev cycle, like, prod forgive my terminology if I use the wrong terminology. But we've got the project set up, we've got the variable, we've got the options, we've got the ability to change it and hit save. We have a client, you know, we have like an ID for this specific feature. So, you know, we have all the parts, and we can just apply it in Exactly. Different ways. So what we're gonna need to do here is I'm going to so we're gonna forget that all of this ever happened. We're gonna go shut off ngrok, for a second, and then we are going to go back to our direct us instance, and we're gonna start direct us up again so we can start to have some fun. And we've got all of our code here. Why We do. Are you It's it's it's the other it's the other Visual Studio code that's in the back. Yeah. Are you talking about? What? Hold on. Alright. We'll doc, and then we'll go back over here to engrok, and let's get this running. Oh, I'm running the wrong one. There we go. Nice. Wonderful. And let's go over to here, which I should actually have open in my window. Oh, and we don't need this for right now. So let's open that and make that bigger. And we should be able to go to here. Wonderful. I am gonna need to log in again, I think. No. No. No. I think it'll be fine. No. I need to log in again. Oh, you're gonna need to log in again. Battlesnake@lws.iohunter2. Glasses us what I set this up with. There you go. Okay. So here is our logic. We removed a bunch of stuff from in there. Great. Our snake is working again. Should be working again. Logs are all there. I feel less bad about all the logging that I was doing of every time that we were calling Dev cycle now that I see these Exactly. Thousands of We actually you know, this was I mean, all the dates, like, visible elsewhere. Just today, we actually recorded, or we we did a live request review, which is our show where we or it's our live event, which then becomes a show on director's TV a week later, where we go through feature requests to talk about them, and today's was all about flows improvements. And one of the big things is the ability to change the retention of those logs. I like that. Because, yes, they get they get chunky. They do. So, what I think we are going to do, and I liked the idea that you were talking about before, Kevin. I think let's do 2 pieces of logic, and we're gonna we're not gonna delete all of this stuff. We're just gonna kinda remove it for right now, and then we'll reconnect it. And I think we'll have just right now 2 different blocks. 1 of them that returns right, one of them that returns left for moves, and we'll have some branching logic in there. How does that sound to you? Let's create a new flow for this, and then we could just hook it up to the extension, rebuild it. Like, I think that might be a good a good shout. Let's do that. So let's call this snake, cycle. Alright. And Great. We're just gonna leave that. All of that's good. Just next. And webhook or webhook. Yeah. Okay. And then get, I think. Host. Not the get. Not I had a 5050 shot there, and I got it wrong. There we go. No async calls either. Because because we'll get because we'll get a post request from the Battlesnake platform. Yeah, data of last operation safe. And then what we wanna do here is grab that URL. Yeah. I think yeah. Perfect. Go go to the code editor. Go to the extension called snake. Yeah. I think so. And then in our source index dot JS, and we just wanna update this. Right? For move for move. The move one. And just to not have to do the round trip, we'll change the for local host 8055. But hit paste. That'll give us the ID of the trigger and everything. Yep. And then, yeah, we'll just change that for HTTP, not HTTPS, localhost secure my how to secure my URLs. Kevin, who who are won't work. Phone's bloody work, man. Actually, it does. No. No. It does. I'm pretty sure. I'm pretty sure ngrok automatically anyways, I don't I don't need to Not not on not on this one. Yeah. Yeah. But yeah. Yeah. Yeah. But not on the local not on local host. If you were doing it via ngrok, but then we're gonna have to do another round trip to ngrok for what? It runs locally. Smart. Okay. So we've got our trigger there. This is our move. So now this is all feeding through to the place that we want. Now we've got to rebuild the extension and restart directives. Npm run build? Yeah. From the from that extensions directory. So let's create a new terminal in here. Yeah. CD extensions. Yeah. You got it. And CD directives Extension. Extension snake. Jake and m You got it. Build. You got it. And then restart And then we just Oh, because cannot. Okay. This is fine. This is like macOS going overboard. Open up your open up your settings on your Mac. Security, I think it is. Yeah. We may not be able to do that just because of the security settings. Security No. It was there. It said privacy and security. Security settings. No. Just yeah. There you go. Allow anyway. It's right there. It's right there. Fsevents.net. Yeah. Yeah. Cool. Yeah. Great. Alright. Let's try this again. You got it. Beautiful. Okay. Lovely. And then restart and then restart the Docker container. Fixed in directory version 10.9, which we have not upgraded to right now. There you go. Hooray. And now you're good. Okay. So let's head back over to Directus, which is Yeah. Somewhere. It exists. It is in the world on this device. Too many windows. Directus. There we go. Okay. So here we go. So this should be talking here. I'm actually gonna go start a game just to make sure this is working. So let's go, play.battlesync.com. Let's go create game. And I think yeah. Does it still save recently used? It doesn't. That's so sad. Used to do recently saved escape. There we go. And if this is working, we should see a log showing up here. Don't look. Happen. Just no. That's fine. We don't it's probably not gonna work work, but it should show a log here. We have 10 logs. I love it. Awesome. Yeah. Okay. Method post. Yes. So that's 10 moves that it took to pass away. Perfect. Logic is coming through there. Accountability. Awesome. Okay. It's working. So now we're gonna do some branching logic in here. So we're gonna go and condition. And we're gonna worry about the condition afterwards, but let's call this dev cycle response. Oh, it's not here. Well, hang on. Not in not in a condition. 1st, we need to go get data and then we run conditions on the results. So I'm assuming we can just make I'm assuming with DevCycle, just an API, we can make an API request, right, just a raw API request. So you want the webhook request URL, one there. Perfect. And first, we need to go get the data, then we'll do the conditional logic. So this might be a moment to look at the dev cycle docs. Yeah, that would make sense. We should probably Yeah. And there will be a moment here where we'll we'll redact it for for the recording, but you're gonna have to authenticate yourself. So you're probably gonna need to put in, like, an API key or token. Can you create multiple inside of your dev cycle? That's a good question. We're gonna experience this together. Yeah. I haven't played around with the yeah. So we're gonna do a little bit of this together, and then we're gonna not do a little bit of this together. So let's head over there. So jumping into the dev cycle docs, APIs, management API. This is to create features and variables. I don't think it returns anything. We actually want the bucketing API. So this is used to fetch on HTTP. Yes. Yes. Yes. Unique identify the user. Definitely, this bucketing API. Get all the variables. Get all the features. Post events. Get variable by key. Okay. This is what we're looking for. So let's head over to bucketing API, and we are going to have to get our key Wait. What what my key? Yeah. Sorry. What's the endpoint we wanna hit? So we are going to do get variable by key for user data, I think. Let me look here. Private platform SDK type. Missing SDK. Get all variables. What is that gonna return? Is that gonna return the status? What's our what's our end goal here? Our end goal is to We wanna just get the value for the variable. So it's very similar to what we're dealing with in our SDKs. To the user ID to start. Yeah. But everything is hidden behind our bearer token. So I'm just gonna find where all of this is hidden. So key type variation, variation in variation key, response examples, get all features by key post events. No. Fetch No. I think get all fee I think I think you were right. Get all features by key for user or get all variables by key for user data. And this will no. Because this will return Here it is. Yeah. Here it is. The value. Fantastic. That's what we're that's what we're after is the value. So, we're gonna go offline for one second as I go and get all of my authentication stuff sorted out, and, then we will be back with our API stuff. Sounds good. Okay. So For what for what it for that's worth, we could totally have kept it going, and we could just redact it, adjust that slither slither and time. Keep it going. Yeah. Let's do that. Alright. We're back. Yeah. We haven't gone anywhere. We thought we were gonna go somewhere. This is interesting too because we if an so, technically, our management and bucketing API are actually using the same stuff. I need to update our docs because we should actually have this curl command in, both, and they're not both there. I guess most people are just assuming we're gonna be using that. So, I'm gonna go and, in a different window, actually, open up, my OAuth token using the client ID. Okay. So I need to go over and what do I need here? Client ID and client secret in my dashboard. Alright. So let's go over here and yeah. I don't think Yeah. Showed anything. I'm a I'm a little bit fuzzy on how you authenticate. Let me show you. Okay. So what we do here is alright. You're seeing my screen now. Hey? Yeah. So and, again, I will fully admit that I have only messed around with our API in a very limited way. So, basically, we are doing a curl request with our client ID and client secret. We can actually obviously do this same post request in Directus, and we're just using our client ID and client c. We can't do it directly and directly. I've just spotted it. The type the encoding type for this, for this request is a URL encoded form, but that request URL, you know, operation that's built in only sends JSON. And they're just you don't work around this. Like, you can't do it. However, I'm not too too sad because you can, of course, do it using a custom endpoint. It's not quite what we wanna do, but could we do or building a little custom operation. So maybe that's what we do in order to to do that round trip. It's not the ideal, like you know, it means we're gonna have to spend some time doing a little bit of extension development. Like, just spotted that. Is that is that the only way to do it? Yep. Yeah. We have no real public API stuff, which is interesting, but also so what's interesting so we are having so we're working right now on some webhook stuff. So you can technically get when, certain changes have been made, like an audit log. You can read that through a webhook, but you can't actually read what people's values are. Because that would that would be so good because on a webhook, you could trigger a separate flow, store indirect just like your cache Yeah. And then do stuff based on that. But that's completely fine. So we could do this or if we're building a a little custom, operation, we could just straight up use the SDK. Yeah. So let's do that. And then we've already got the code there. So, yeah. Okay. Let's, are we gonna do this here inside of our code, or are we gonna do this over on the platform to get started? Where are we gonna I don't under let let's let's build an operation for flows as an extension. And the goal of that operation is to, right now, just get a fixed, you know, a fixed response from from the API. So, no, we don't do it like this. We actually use the extensions SDK CLI, which will boil the plate a whole extension for us. Alright. We're gonna delete that bad boy. Alright. Let's open a new terminal here. Open up a new terminal. You got it. And we'll go into the extensions folder. Alright. Oh, into the extensions folder. Extensions folder. Yeah. Yeah. Yeah. Sorry. Yeah. Yeah. Exactly. Exactly. And then how do I pull up the docs? Or are you just gonna Yeah. Docs. I mean, I could tell I could tell you this one, but let let's let's do the docs. Let's let's have the authentic experience with someone who doesn't live in this every day. There we go. Alright. Let's head over. And we're gonna see this is gonna be my challenge. How long does it take Andrew to find out what I'm looking for? Alright. So when direct to stocks, we're in extensions. We're in device extensions. Zoom in. We're going to zoom in. We're going to go extensions. We're going to go, developing extensions and we're gonna go extension services and introduction. No. That doesn't look like what I'm looking for. Maybe Very good. Very very good little piece of feedback there. Go into the fundamental section, the one you haven't opened out of the 3, the last one, and creating extensions. Perfect. We're just gonna use this. Alright. Let's go back over here and run this. But I I do see that. I do see that path you took. I'm glad to know that. Discussed it with one of our colleagues just yesterday. So yeah. Like, when things work oh, oh, I need to change my note version. It's upset with me. Wait. What? Oh, it's just warnings. Really? Oh, yeah. Whatever. Sure. Me. That looks what do you wanna create? Operation, please. Oh, there it is. Hidden down in that list. Choose a name. And they so they must start so they must start as of this release. I think it might be gone in 10.9 or it'll be gone in a soon release in a upcoming release. Directus dash extension dash whatever you want. Dev cycle is fine. JavaScript because I don't play with TypeScript. I respect that. Dependencies. Yes. Scaffolding it. I love this. This is so smooth. I like a I like a good CLI. Good. Great. So now we have if you go into the extensions drop down, you have a new extension called dev cycle inside of source. We have API dot JS. We have App JS. App JS is for all of the configuration. So it's all the UI part. It's all of the options when you create a new one, you have that little pane that pops out. It's the information that will show on the on the card in the overview where you connect to all the nodes. That's the overview there. And then the API dot JS is the node code that will actually be executed in the background. Right? So we're gonna go and I think right now what we wanna do is actually grab, just so we're not having to worry about this later. We're gonna grab our code from here. So not going back and forth, because this is basically all the stuff that I need. Yeah. Great. And we're just gonna put you down there and comment you out so that things don't get upset with us. Sounds good. Alright. Perfect. So let's save that, and let's do an install. So I do have to have to go into this folder to install, slash extensions. Directus extension CD. Extension. CD. Cycle. Not we're not we're gonna put it at the end and see what happens. No. Start. Start. Start. Start. For a moment, I was like, am I about to learn something? No. There's there's very little learning that will be There's very little learning. I got it. I got it. And then we gotta go over to because we're gonna install the, the SDK. We're gonna go over to the dev cycle docs. So we'll move back over to docs, and let's head back over to the dev cycle docs, docs.devcycle.com. And we're gonna head over to our SDK section, our node JS SDK You got it. Installation. And let's grab this because who uses yarn, NPM or bust? I've become so opinionated in my coding Alright. So that means that our import statement should work now. Actually, is this import or is this require? I This is import. Yeah. I thought so. Alright. Let's move you to the top. Alright. Perfect. So step 1 complete. We're done. Time to go home, everybody. End of episode. So a couple of things that are just important before we continue. There is an ID here called custom. Let's rename that, and then we have to reflect that ID in the App JS and the corresponding App JS. I think dev cycle is a perfect ID. So we just want those 2 to match, first of all. Very good. And let's, while we're here, give this a name. Dev cycle, this is the nice friendly name that shows up when you pick your operation type. Sure. Yeah. Then are we gonna ask the user for any configuration up front? And I'm gonna say that maybe we do. Maybe we wanna collect the snake eye like, the the the ID. Right? Are we gonna do it? Are we gonna have time to do that? I mean, can we give it just an arbitrary ID, or does do you have to register users inside of the dev cycle system first? Like, how does that work? So you would need to feed a specific user's information. Yeah. Let's call a snake name. Yes. I think that's a great idea. Yeah. I was a snake ID. Snake ID. So let's do that. And at first, we'll just hard code it, but later, you can put dynamic values in here in flows. So instead of text, let's just change text to snake. So there's a friendly name. Yeah. Yeah. Perfect. There's a friendly name. Yes. Is that correct? Is it? I changed this from tests from is this yeah? Yes. That's all good. The options need to change too. That's the part. So that that's the overview that will show on the card. Cool. Whatever. It's the options we care about. That's the pain that comes out and you select all the options. So in here, the field, the field will be called snake. And that's what corresponds with the snake in the overview. That's the friendly name. It will still be a string. It'll be full of input. Great. Save. Now we'll go over to API dot JS, and there's text here. We'll change text for snake. So that says taking in the snake value and now we're going to execute some code. But before we do this, I think that's everything on the UI side done. We want to initialize this client and we'll want to initialize this client between lines 13. So everything in your yeah. Great. So, we're going to ignore this because we're not actually going to I'm actually I'm interested to see how this works. Once we have done this, we're going to change some things up eventually. But we're not gonna worry about that right now. So let's grab Oh, which was straight upon commenting everything. That's that's crazy. I mean, nothing could go wrong because nothing's really running yet. So this is good. This server is gonna change. I'm gonna leave these. I don't actually know if we need these, but I'm not gonna question it. If it works before, our goal is to take what worked and apply it here. So we're not gonna make any changes to the logic here. Yeah. Exactly. So we are initialized there now, and now we need to pull all of this stuff up above. And I think we're not gonna need that get cached direction elsewhere. I don't think we wanna necessarily play with that right now. And at the very least, we wanna make sure that we can get data from dev cycle in a flow Exactly. And then pass it on. But if you were having an issue where it's taking a little while to do that round trip, there's a pretty good chance that we're gonna hit that here too. Okay. So let's go here. Awesome. Alright. So here we go, dev cycle clients. So we're established here. We've got this cash direction. Again, I don't actually think we need this anymore because we're gonna be calling it sort of once to determine what's gonna change. We're not gonna be calling this again and again and again. Right? We're not gonna be calling this every move. Is that our that's our focus. Right? I mean, we were. Yeah. Do we we were gonna call it every move? Oh, this is all in the wrong endpoint. This actually wants to go in the start game, doesn't it? Once you're in the start game and then for the game, we determine the strategy and then we execute on it. This is okay. Let's keep rolling now. And then before we've done it with yeah, exactly. Precisely. So let's really let's let's keep this light. In fact, I think doing everything in a separate function may not even be what we Exactly. Want too much here. So I'm gonna pull all of this out of this update cache directory. Hang on. Hang on. I think the only bit we care about is this dev cycle client variable. I think that's the only bit we want. We also care about this user thing. So that's where that's going to snake. Yeah. But that's going to that's already that's coming in from the snake value above. So we're gonna get to feed that in. Yes. Yes. Yep. I guess it has to feed a very specific way. It has to be a very specific object that's feeding in, but maybe you're right. Let's let's see. Let's see. I think I think it'll be okay. So so if we if we go down to where the actual flow handler is, which I think is down. So inside of the handler, instead of the console log, snake is a string. So what we want to do here is we want to make on line 41, we want to make this an async function. Right? Yep. No. As in as in we wanna change just before the the snake. Oh, I see. We wanna make it async, then we'll just use a sync yeah. One more to the left. One more to the left. Goodness gracious. And we're gonna get rid of you. You don't need to be there. And then and then inside, what we wanna do is is run that run that SDK method, but we can do it with a wait instead of then just to clean it up in this context. So if you scroll just very slightly up oh, yeah. We'll ditch something small. Yeah. We're just gonna do this. We're not gonna need to do this call. Perfect. Let's just work the day. Grabbing this. Yeah. But only 17 18 to start. Oh, yeah. You're right. Yep. Because we're doing a sync await. Yep. Yep. Absolutely. So we want that. That goes straight in there, within within a wait at the beginning of line 33 and a store this in a variable. Right? Yeah. Let's call this strategy. Beautiful. Love that. And then user is now gonna be I mean, if you wanna grab lines 13 to 15 just to get the structure, but really it's just an object with the user ID and snake. Yeah. Yeah. Exactly. Let's see what happens. And then yeah. So we're gonna Other way. We're gonna define this above. Yep. We can assign this above. Awesome. And we're actually gonna feed this in. User ID here is gonna be snake. So we're gonna feed in snake here. Snake? Yeah. I think that should work. I think that should work. But we don't know what comes back in strategy yet, so we're gonna log it. Perfect. And then we're going to return strategy. Beautiful. And that's actually add some comments there so we know it's being logged. Strategy. Oh, can I show you can I show you a quick tip for this, which I think you'll really like? Love a quick tip. So remove that remove that string in the comma from the console log. So it's just the word strategy again. Yep. And then highlight all of the word strategy, just the word strategy, and then surround them with squiggly brackets. And now that is an object where the key is strategy and the value is strategy. So when it logs, you get strategy, colon. Yeah. It will be an object. So that is just a real shorthand if you if you just want to quickly tell what something is and you have just a variable key. You know, sometimes I enjoy JavaScript, but only when people that enjoy JavaScript are doing JavaScript with me. Okay. So technically, this should this should do all of the things that we want it to do, I think. Yeah. And so this is wanna change this to hold on. Oh, sorry. Go ahead, Kevin. No. No. No. Go ahead. So I'm just saying here so here, we're actually gonna go and create an so this is a direction variable. We're gonna create a strategy variable and kind of put 2 strategies. We're gonna do, like, hungry and tailchase or something like that. I mean, we we're not gonna implement those. So why don't we do left or right? That is a very smart decision, Kevin. So let's head back over to dev cycle here, and we're gonna get out of there, go into our features again. Into our choose move, it doesn't really matter again what this feature is called. We're gonna create a new variable. We're gonna call this strategy. We're gonna set this as a strict technically, we could just do Boolean, but we'll do strategy. And because of the way that we have this set up with, like, these 4 different options of left, right, up, down, we're gonna actually go ahead and kind of move this around. So we're gonna call it, this one's gonna be left, and this one's gonna be right. Actually, we'll just leave it all exactly the same. Down, up. But it's just called strategy this time. It's called strategy now. Yeah. Sure. Alright. Amazing. Look at that. We changed literally nothing. I love that I did a thing that was completely unnecessary. We could have just kept the stream. Just kept the same. That's fine. That's fine. We we okay. So we're logging this and we I think I think this works, but what we want to do here is is what do we wanna do here? We now wanna hook this up to a start. Yes. So we need to do we need to do a new end. And we need to change the data model to, have this extra, like, strategy string, which I think is amazing because then even in our insights dashboard, we can be like, when using this strategy, this is the win rate. Like, it's actually really lovely. Now we're done in code for right now, though. Right? So I think that we can No. We're not? Build this one. Build this extension. I think we're gonna need to change which flow is being hit on start. I think we need to create a new flow. We need to create a hang on. Oh, metadata. Hang on. Hang on. Is this are these errors or are these suggestions? I think this is all about and has been rewritten. I have a sneaking suspicion this is inside of the SDK. There might be no module in But it said done. Yeah. This may And it says and has been rewritten. All of these have resolutions. I've not seen the error before. I have a sneaking suspicion it's in the dev cycle and the way we're rolling up and bundling code, not a problem. If it works, it works. Not sure if it works. We'll figure that out. So what we actually wanna do is create now another Flow. Flow. Do we need to create another item? No. No. We don't. We can alter our existing start endpoint. Yeah. So yeah. But you've built this. You need to restart Directus. Yeah. Okay. There we go. We're gonna restart Directus. Oh, I need there we go. Let's restart here. Oh, wrong one. Just ignore the fact that we're rebuilding it again. Ignore all of those errors, everybody, and go to the right ones. To me to me, they read as warnings. That's the spirit. Alright. And that should be running again, and we're gonna close that down. We're gonna get the right thing open now. And I think we were here. Let's mark this out. Absolute chaos. I literally can't get behind your window management. There is no there is no window management that is occurring. There is nothing. So, there is one other thing we want to do just before we hook all this up, which is we want to go into the data model. And for a gain, we want to, just add a string strategy. Right? Yep. Yeah. Lovely. And then just because it makes can you make it half width, please? Sure. You use you you could do it with the little 3 dot things on the side come out of this pane, the little 3 dot thing, and then half Got it. Got it. We got there. Alright. So that's in there now. Awesome. Let's head back into flows. Oh, that's not the right spot. Back into flows, and we're gonna change this one. I wanna change the name here before I forget. Can I change that? Yeah. I can. Yeah. Yeah. Back here. Yeah. Yeah. Yeah. Sneak strategy. Awesome. Nice. Perfect. And then, yes, start. And now we want to see if this new thing can so we extract the snake count, and then we create data. And we basically want to create one there in the middle, which hopefully won't pose too many issues for us. Let's build So no. No. Not on the on the success path. Great. And what do we do in our custom operation? Right? Yes. There is at the bottom. Look at that. It even says dev cycle. I think that's a good name to keep for it. I like that. I also like that it converts camel case into, what's what's this? What's the that is called I wanna say hang on. I will I will tell you this because I actually have it inside of my raycast case. That is called that is called, coming up, camel case. That's camel case? This is camel case. Oh, no. Sorry. Sorry. That is I'm I'm I've picked a ridiculous string to test against. So it had, like, it had, like, hang on. That is called, scrolling through, Pascal. Is it snake or is it Pascal case? Snake case. It's called snake case. What is snake? Enough. That's a case. There we go. That is appropriate. It's almost like I knew this, and I wanted to bring it up. Okay. And for a sneak ID, we can actually put in anything. We're just Oh, encoded. Yeah. We're just gonna put, like, a really basic actually, no. Let's call this ready, set, Battlesnake because there's some cool stuff you can do with your targeting rules, including include. So let's just set that. I mean, remember, that can be a dynamic value from the first step. It can. But for now, we'll But we can we can yeah. Absolutely agree. So inside of the dev cycle step now sorry. Can we just go in? That was the only option. And so dev cycle is gonna return some data. Yeah. All of that happens in the background. So we don't know whether it works yet. So now we wanna redo the nodules. Yeah. Oh, yeah. We just wanna move this to here. Right? Yeah. And this is where we seem to keep having a bad time. Awesome. Thank you, Directus, for doing exactly what we were expecting you to do. On behalf of the core team, you are very welcome. So what is our issue in here? What is our issue? But remember, we had this all the way from the first episode, and we just kind of wrote like, there was a specific set of moves we did, and it worked. Okay. That works. I think it might have been this. I hit edit again. Yeah. And then bring it back and then bring it back. No. What if I just disconnect that altogether? K. That works. We're getting there. And then and then do it again now? Edit and just do that last one? Come on. There we go. There we go. We got it. 2, we're gonna set of actions. There you go. It's 1 at a time. Yeah. Okay. So that Now we want to start a game and just see if it works. And there's a we're also going to want to look at our directors logs too because we did console log just data. But let's we need to start the game. Let's start Then we can first. And let's grab create new gate. Oh, not create new battle sync, create game, and let's grab escape. Oops. Escape. Escape. Which I now regret. K. Add game. Is it in there? There we go. Beautiful. Okay. Let's see. Game is running. Something's happening. Not what we want to happen. Sure. That's okay. Let's head back over to Directus and see what our logs are saying. Scroll up because, obviously, all the turns happen. Right. Strategy. Boom. We just need to do dot value. That's why. Okay. It's it's returning this. It's the yeah. Request to get variable strategy failed with the response variable not found for key strategy. Hold on. Did I not save? I feel like I might not have saved something over on the cycle, which is a necessary step here is to actually save it. Okay. That does sound necessary. Oh, hold on. Maybe this is not that window. Ah, see this? Save. It doesn't actually know that it's there. It's my own darn fault. I got too many windows open. Darn you, Andrew. Honestly, I'm pretty sure it's the curse of academics. Every academic I've ever seen or a covering academic. I think you are though current. Correct. Yeah. It's it is that. So while we're here, maybe we just straight because this is a DVC variable. Let inside of the extension itself return strategy return dot value. Yeah. And then rebuild, restart. Yep. So we're gonna return This is good. Yep. Dot value. Awesome. There we go. So that should work. That should do what we want it to do. Let's rebuild here. You got it. Yeah. We're in the right oh, that's snake. We wanna be dev cycle and not CD. Let's go npm run build. And now we're going to need to restart again. Yeah. Once again, not the case now, but I'm too I'm too nervous just just in case. The upgrade is right in this moment. Okay. And I need to oh, why did I do that? Why did you do that? I don't know. Questions questions have been asked. Okay. So let's see if we can create a rematch. Should work this time. Nope. Not working. Well, it's not so much that. That's just the bit we care about because it's our new snake. What we care about is if we go back to the logs Are these the new No. No. No. No. The the log the logs won't tell us anything. Go see if the strategy has been saved against the latest game. Oh, that's true. Yes. That's what we're actually testing here. Oh, no. No. No. We're not doing that. Sorry. We check the flow logs, the flow logs for start. This is what we're doing. And we check the latest log. We check the dev cycle payload. Ready, set, battle, snake is the snake we're feeding in. Payload up. That's good. I should be feeding everybody up right now. Up, up, up, up, up, up, up. Yes. Hey. We did it. That's awesome. Now so now we wanna store the strategy. And then in the move logic, we want to grab this next this game strategy. We want to act on it. I love this. Okay. So we have this here. Now we need to store it in here, right? We're actually Yeah. We just wanna edit the create data. Edit the create data. Oh, in here. Gotcha. Yeah. Because we're already creating it. We just need to add strategy. You're missing a comma on line 3. But I laugh at commas. Okay. Do you wanna hear do you wanna hear a fun do you wanna hear a fun, little story while we're doing this? I'm ready. So I, am teaching at at the university this this term. And, I was talking to my students who are all future teachers about using proper grammar in the posts that they're doing on the WordPress blogs they create. And I misspelled grammar. Beautiful. Well, you can't have it all. You could have good grammar or good spelling. So so remember, the value was no not trigger. The returned value from the dev cycle step. And remember, the key was dev underscore cycle or lowercase, so not the dollar sign, was the string. So it is just dev underscore cycle, and the value of that will be the string. All right. Let's see if this works. Because that's what was returned out of that step to save. And so let's start one more game. Let's make sure that's being being stored. Oh, cut out there, Kevin. Oh, I actually just stopped talking. I'm not sure. Oh. You you definitely froze. Oh, okay. Fair fair enough. Yeah? Okay. Good. Okay. Perfect. So we ran a game. Yeah. That's fine. And then let's head back over to our logs here. And the I mean, the proof is gonna be in the pudding here. No. So But then no no no the options. Strategy up. So if we now go look at the latest Oh, there we go. Yeah. We're there. Yeah. Yeah. So if so if we go just check the content module in the sidebar here in the, module bar far left, let's go look at the latest game and make sure our strategy was saved. That's the top one. Top one. What is Games. What what an easy quick way to do this is if you just hit the plus in the top. Like, if you add a if you add a field, perfect strategy, boom. Nice. Amazing. So now we're gonna go into our move, our new move, which does nothing, which is why our snake is doing nothing, and we wanna respond to that strategy. Alright. So So not this one. We we we we we we we Oh, that's right. Yeah. Yeah. We did a strategy one. That's right. Okay. Awesome. Snake strategy. And let's do this as a we're just gonna return. Right? So we just need to do No. Because there's a few steps here. So this takes in a move, right? And that move has a game ID. So the first thing we want to do is we want to look up the game to find out the strategy, right? So we want to read data first and my confidence has just gone through the floss. So let's close out this for a moment. Can we just look at the logs here and just understand the shape of the data again? All right. So So the payload, body, game, ID. And that should match the ID of the game in our collection that has been created by the start step. So let's see. 4ff ending in 70. Let's see if that is in fact the case. Sure. I I think it should be. Yep. There we go. Perfect. So what we want to get out is that strategy. So, so we'll create a new step here, and we can call this get game or something. Yeah. Get game strategy. Let's call it. I'll just get this is gonna get the whole game. So let's just get game. And then permissions full access because I can't be bothered to deal with permissions, collection, games, IDs. Now this is important. We want in squiggly brackets, double squiggly brackets here, trick, dollar sign trigger dot body Body. Yeah. Dot game ID. Game. Yeah. You got it. Dot ID. Yeah. And hit enter. And hitting enter just slightly, you know, you have to enter. And just like you're hitting save over there in dev cycle, that's one that gets me. There we go. And this should get the game. So hit save. Let's see. And let's just do this very sequentially. So, yes, let's let's test this again. Once again, the value should absolutely be up. Perfect. Options. Permission to pull the games ID. Wonderful. Wonderful. And we get our strategy. Lovely. And the strategy now is what we're gonna check. So now we're gonna do some branching logic. So what we want is, I think, a conditional. Yep. Right? Yep. And we're going to call this strategy. Strategy. Well, let's be more specific because we're gonna check if it is one strategy or the other. So Oh, that's true. Is, you know, strategy, yeah, is up. Although, was was up the value yeah. Yeah. Off was the value. Yeah. It's up the value. It's up. Yeah. Perfect. So let's fill in the so I don't think we do wanna fill in the default. Yeah. So squiggly like, this is JSON now. So squiggly brackets on the outside. There we go. I love this, by the way. This is such a smart little Except we are gonna have to go edit it. So I know. It's all it's. So trigger change for last because we wanna grab stuff from the last step. Oh, sorry. A dollar sign. Yeah. Last. Perfect. Yeah. Correct. And we're gonna be checking the strategy. So not category, strategy. Yeah. And when you see whether it is equal to up and it's case sensitive. So yeah. Perfect. Wonderful. And hit save. Now, honestly, this is where this is where I mean, nothing would oh, yeah. Suppose we can check. We can check that. Kevin, let's follow, strategy every time we do this, but, no, we won't follow the strategy. Let's see. Oh, wait. Wait. Wait. Nothing it didn't get saved. What? Didn't save the flow. You just refreshed. Oh, did I really? No. Womp. Womp. It's okay. Come on, Andrew. Come on. I mean, to be fair to be fair, there is a little bit of allowing you to do that without prompts. Anyway, anyway, is up Yep. Was the name of the condition, and it's gonna be lost. Last. Yeah. And you call them strategy. You call it. And oh, strategy, and up, and save and save. Up. It's the double save. I get it. I get it. Let's set out. Let's finish this game. And so I figured out the thing that it is here. You actually have to finish the game before it'll let you do a rematch. You have to play the whole game. That was the issue we were facing. Good tonight. So we should have it showing up now. Yes. He's up. Payload. Yep. Awesome. Is up. Now, this basically will fail if it isn't up. It will it will, like, it will have a validation error, and the whole flow will fail. And this is correct. Yeah. Let's see. Look at you go. All right. Here we go. And amazing. Alright. And let's go back over to directors refresh. Look at our logs. Shut up a bunch more. Let's go. Oh, oh, something's happening. Oh, I need to actually press the button. Alright. Here we go. Oh, option payload validation error. Validation error. Wonderful. And so this is where, we have to be creative with flows and work within some of the limitations, to be frank. So because all all conditions, there is no, like, case statement where you can be like a, b, or c. It is true or it is false. It is resolved or it is reject. Right now, our flow simply halts because it goes out that reject path and fails. Right? But what we're gonna do now is we're just going to put, you know, we're going to just put one thing on the reject path, but it isn't failed. It's just the else. Right? So it's just an interesting terminology thing there. So we don't, we don't we don't even need this now. Oh, I guess Unless you wanna do can be Well, why don't you wanna do it? Yeah. Let's just do all 4. There's only 4 to do. So So hang on. Hang on a moment. Have you put you've put this on the reject path. Right? Yes. Perfect. Yep. Okay. Last strategy down, and we're gonna call this is down. Perfect. Yes. And then we're gonna create another. Off the reject path. Off the reject path. So it gets a little bit unwieldly here. So it's not up. It's not down. Strategy. Let's call this last. Copy it out this time before you hit save. Look at you, left. Perfect. Copy. And then one more. So you so you see here how these kind of more convoluted case statements can get a little bit messy in here? Yep. I definitely do. But, is right. Okay. So let's go there. Save this. And go to the game. And let's finish this game. Shouldn't take too long. And this one should do the same thing. It should have a validation error after the first one. Yeah. Alright. Oh, yeah. That's true. Oh, no. See if it does. No. No. No. No. That's a lie. Sorry. It will it will go until it fails. Just ignore me. That was incorrect. Sorry. Is up. So that was our first one. Is up failed. Must be up, and then it dot stopped. That's not correct. Did I do is up twice? Is left, is up, is down. Oh, no. No. It's connected to read data. It needs to be connected to the reject path of is up. Oh, there we go. Not that one. There we go. Yeah. Yeah. Yeah. There we go. Oh, did too much stuff. Disconnect, save, edit, reconnect. Oops. I'm glad. I'm no. No. No. Reject. Reject. Yeah. I'm glad we finally got back to that point of just finding that little that little set of actions. I can't believe it got us so, so much. But, yeah, I've submitted that as a bug report. Awesome. Alright. Let's refresh this. And we should be now we should be seeing the process that you were hoping for. Yeah. Lots more moves there. So we should be seeing is oh, yeah. Here we go. Awesome. Yeah. It's up. Validation error. Validation error, validation error, validation error. Why is there a validation error on all 4? It has to be one of them. Oh, last must be of type object? I wonder if that is not Oh, of course. Last is the last step. We've foot gummed by using last, which I actually spoke about in a previous episode. What we wanna check is, can you click into read data? The read data Yeah. Key is called get game. Right? So let's maybe rename this game. So if you go up to the key in the top right of this whole pane, scroll up. Yeah. Yeah. And the last will always be the one that came before it. But in this case, we're chaining a bunch. So, like, changes. So we actually wanna change. So if we change this to just game, let's keep it nice and short. Perfect. And and, yeah, save. And now we could do it in is up. The is up last is correct, right? But in all the others, it isn't lost anymore. And then we're just removing this, and it's actually just gonna be game. Right? No Correct. Yeah. Correct. Okay. So let's go No, dollar sign. Yeah. Or no dollar sign. Yeah. There we go. And let's call this one game. Oh, game. And copy that this time. And I'm quite impressed with where we've gotten here. I feel like episode 4 finally figured things out. Yeah. Alright. Here we go. So Yeah. So now so so let's test that once more. And while we're doing that, let's talk about what's next. Because all we're gonna do is execute the most basic strategy, which is to just return, move up, down, left, right. And we're not gonna do anything more fancy here. Right? You would implement is up, not correct. Is down though, is correct, which Awesome. Great. So now out of each of these success paths, now we need to run the strategy, which of course could be a lot more convoluted. Another thing that's worth noting is there is a flow operation, which is to run another flow. So you could you could kind of modularize your strategies into separate flows, go off and call those those come back with the response. And then so, you know, there are ways of organizing your flows. It's not just one big mega flow. But it's I think for what we're doing, it's beyond the scope, but that that would kind of be how you organize game logic, I think. Great. Okay. So what are we gonna do here? What are we we're sending this to We are literally gonna return. So run script. So sorry. I run script was near the top. And the reason we're doing run script just to move and then up and down and left. You got it. That's awesome. You got it. Because in the trigger, we said respond with the last operation. Yeah. I love that. All right. So let's just grab that, save, and let's do oh, yeah. Then that's correct. Yep. That's correct. So that's the is up success path. The names and the keys no longer matter, because If we unless we forget which one where it is down, so this one's gonna be down. Save that, and then we're gonna go here. This is left. I'm glad you you've come with me on the up, down, left, right rather than the clockwise. We got there. We got there eventually. We got there. Alright. And then our final one is gonna be right here. And then this one's gonna be run script and return You got it. Move right. And let's see if this works. So if this works, our move right now is down. So snake should go down if everything is done the way it's supposed to be. So we've been going up because it's been failing. Now we should go down. Alright. This doesn't necessarily mean it's working yet because let's see if we go right. Save. Did we just actually implement this in, like, an effective way? This is wild. I'm, like, kind of Hang on. Hang on. Hit play first. We don't know yet. Yeah. What is up? Snake went right straight off the board and died. This is fantastic. I have never been so happy to see a snake die. I mean, last episode, I was really happy because we really wanted our snake to die. But, like, I'm Oh, yeah. I'm far more happy. That's pretty freaking cool. That is cool. But there was one final part, and then I think we're we we can we can call it on ReadySet Battlesnake, at least season 1 of ReadySet Battlesnake, who knows, which is right now we are saying all users that there is no segmentation. There are no different audiences. It's just everyone gets one response. But in the flow creation, in this start game, you know, flow, we can put in a dynamic value there. Now, I do not know how this works in dev cycle. Is this something that's viable? Yep. Yeah. Yeah. So hold on. Let's go back over and actually look at this. Because you said words and I heard the words, but then I stopped hearing the words. And so let's, let's go and shift this in that flow. And so we could do it in our in our dashboard. Right? We could actually We we we wanna do it in both. So here in the start, right, in the dev cycle operation that we created, if you go in and edit it, you see we put in our as fixed snake. So the question here is right now we're getting I think there's a step missing here, which is we want to register users. No. No. You don't actually so you don't technically need to register them there. Oh, I've gone all blurry. Hold on. Hold the phone. Why have I gone all blurry? What's happening? There we go. Alright. I'm back. I'm back. Okay. So what we can do here is this is all just stuff used for targeting rules. So let's say, okay. So you know how if it doesn't see anything, it goes up. Right? Correct? Not right. I shouldn't say right. If if it Yeah. If it's not seeing anything, it's gonna do that. So let's leave this as ready, set, Battlesnake and go over to the platform here Yes. And say Yes. Go, let's say go left, but only if the user ID contains ready. But but what I'm wondering is, can we get this to a spot? And, like, we can assume the outcome here, like, we'll we'll we'll do this. But what I'm wondering specifically is can we, in 10% of games, maybe this is about the game ID and not the snake ID. So maybe the the name of the property isn't quite right. But can we say in 10% of games or 10% of users, I suppose, can we change it? So in that case, when we first feed it the snake ID, which will make the game ID, is that can we do that? Yeah. It's just this. You literally set it to random distribution, and we say that we wanna serve 25% each of these distributions, and it will automatically do this for all users. So we don't need to do anything with this passing a random name or anything? No. I mean, you could do it within that. You could say only the snakes that have ready in it. Yeah. Exactly. Do this, you know, so you can further branch that logic down and get a real small selection of your audience. Should we remove that, the first set, the first conditional where you put ready? Yeah. Should we remove that, I guess? Because it's kind of just do all users. Yeah. And now we're just saying that all users random distribution. A random distribution. So if I save this, we should see if we run, say, 10 games, we should see something similar to that. So let's make sure this works. That's good. Oh, that was remarkably easy. It is very smooth. But but there is that other thing still where, like, if we if we register, can we say, no, ignore me. That makes part of that same mistake. All of these things are possible. If you can feed information into the platform, then you can you can do lots of stuff with it. And we've only discussed all of these ways of feeding data in, so we don't necessarily need to go too granular. But, yeah, let's create a ton of games. Okay. So here we go. So let's go first game. So we went left first game. Sure. Let's go create rematch. So we're going left. So that's 2 for left. Let's create a rematch. We should start going a different direction, and we're not. Maybe I didn't save. Hold on. Yeah. I was gonna say, did you hit that save button? All users, random distribution, schedule, none. No random distribution. We should be seeing that. That. All users feeding that in. 25%. K. Let me change this. I just wanna see if something happens. A 100%, 0. Oh, you you you have to make it worth what happens if it exceeds a 100 there? I don't I don't know. I'm curious. Yeah. Yeah. So we should see this. Like, all users should ever run a 100% should be there. Random distribution might require something else, but let's see. Yeah. Maybe. No. No. That's right. Yeah. I guess if I may. It must just be the logic that's being used in there. So let's do 5050, and that might be a little bit easier. 50 right, 50 down, and see if that Sure. Does it. That's there. It also does say a couple minutes to update. So let's see. Yeah. Maybe that's it. Maybe there's a little cache. Which is fine. Right. As I say, our snakes aren't spawning in particularly in particularly good spots to live. They're not? This isn't feeling unless it is really that thing because you you don't need feature flags to be literally like sub second. Know, there can be a little bit of a of a moment there. Yeah. So this is over, like, a longer period of time. So that might be part of it, but we should see a down eventually, because the logic that's there is technically correct. Oh, you know what it is? No. I'm wrong. Here's the thing. I I totally forgot about this. So because it feeds in user ID and we're feeding in the same user ID every time. So if we wanted to change this, it's actually not that bad. So that So this is actually what I wanted. Yeah. Yeah. So users and that makes sense because in the real world, you have a feature flag. You don't want that user getting a random thing every time they reload. Yeah. So ready, set, battle, snake was getting right after Oh, no. No. No. No. Hang on. Hang on. Go back. There's a there's a better value to put in here. Let's put in the game ID. Let's put in the because that's random. That's in every new game is a new is a new That's true. User in this context. So actually grab game. Okay. Double double, double brackets first, and it will be trigger dot body dot Game dot ID. Game dot ID because that's a random value each time. Yeah. It is. That's good. Yeah. Yeah. Yeah. That might that might do it. So we should now see 5050 if it works, which it may not. Mhmm. Mhmm. K? Good. So right on the first one, right on the second one. It's not looking good so far. It's not looking good so far, is it? Oh, there we go. Hey. Hey. There we go. So So that logic that I think that's Andrew, I I I'm I'm both really happy that we got this to work, But I'm also kind of sad because I think I think that might bring us. What do you think? I think I think we have we have eaten into to your evenings for many, many dates. Not for that reason. Not for that reason, but just I think that's I think anything more now is us just in hot like, doing things we've already done, but in this slightly altered context, but that's awesome. So you can really, like, yeah. So smooth. Yeah. I gotta say, like, I when we set out to do this, I knew that we might be able I knew Directus would work. Like, that made sense. But when we decided that I was gonna take the lead for the final show and we were gonna do the dev cycle, I was like, I don't know if this is gonna actually work because I tried to implement dev cycle with Directus a lot of ways. So I'm over the moon that this works. And, like, what a cool piece. And it's so fast too. Right? You're not having to worry about direct us doing anything. It's all managed externally. Like Yeah. And and part of this is an approach that we chose. And this is a very battle snake kind of thing. It is an approach we chose to make sure that we are we're not combating that 500 millisecond return require return requirement. And that is because we determined a strategy at the beginning of a game, not every move. So there is a couple more round trips within directors. We're having every move to go and figure out the game strategy, but this is all internal. These are just little database operations. That's awesome. And then, of course, going back to the last episode, we could now enrich our insights dashboards and saying when this was the strategy, this was the outcome. We could use the little global variable drop down to to pick. We could even go off to dev cycle, populate directors with all viable strategies, That was awesome. That was fun. Happy? This was a fun day. I'm I'm so Kevin, I was so it's been a couple episodes since I've been, like, on the keyboard. And, like, you were walking away so pumped after every and I was happy. I was definitely feeling it. But, like, I'm having a good this was a good It's good. This was a good day. We got we got things working, and our snake does the things, and other people can now go and use this to meld the world's all the d's, Directus, Devcycle. Yeah. What what do you say, as for as for Directus as a Battlesnake engine? I love it. I think it's super, super smooth. And I love the fact that there's actually, some code that exists out there for building a dev cycle management setup within the Directus platform. So, like, like, use Directus and then implement dev cycle and then play Battlesnake. That's the real that's the real goal here. Do Everybody wins. Everybody wins. Everybody wins. Everybody wins. Everyone, thank you so much for joining us. Andrew, thank you for getting on board with this idea to to, you know, have a Battlesnake video, you know, series after after a little while. Thank you audience for joining us for this limited series of Ready Set Battlesnake. If you want to learn more about Battlesnake as with all of these episodes down in the resources, you'll find a link to the docs for Battlesnake. It is such a satisfying and fun hobby project for developers at all stages of their career, whether you're just getting started or you are really pushing, you know, your very, very advanced knowledge and it becomes an optimization game. There's something in it for everyone. I'm glad they all worked. Honestly, there were so many points in this where we might have discovered this doesn't work irreparably and the whole thing's ruined. And every barrier we came against, there was a solution primarily actually through the ability to build extensions. Yeah. So that is wonderful. Oh, lovely. And a melding of my world as a big time and long time battlesnake lover and running dev rel, at, director. So Andrew, once again, thank you so much. You're welcome. And should we do it our one last try? This is our last opportunity? So here we go. What do you mean? What do you mean? You have little faith? This is it. You have a So here we go. What do you mean? What do you mean? You have little faith. This is it. You ready? Alright. Here we go. Alright. Do you want to count it down? Should we count it down first? No. Hang on. Hang on. Hang on. Hang on. I've got it. Uh-uh. Alright. This has been ready. Ready. Set. Set. Battlesnake. Battlesnake. Bye for now. Bye.",[195,196],"d2934fc9-1a8a-4260-8128-0ea918de1854","95293c50-dd25-47f3-b558-913cbe79f9b4",[],{"reps":199},[200,256],{"name":201,"sdr":8,"link":202,"countries":203,"states":205},"John Daniels","https://meet.directus.io/meetings/john2144/john-contact-form-meeting",[204],"United States",[206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255],"Michigan","Indiana","Ohio","West Virginia","Kentucky","Virginia","Tennessee","North Carolina","South Carolina","Georgia","Florida","Alabama","Mississippi","New York","MI","IN","OH","WV","KY","VA","TN","NC","SC","GA","FL","AL","MS","NY","Connecticut","CT","Delaware","DE","Maine","ME","Maryland","MD","Massachusetts","MA","New Hampshire","NH","New Jersey","NJ","Pennsylvania","PA","Rhode Island","RI","Vermont","VT","Washington DC","DC",{"name":257,"link":258,"countries":259},"Michelle Riber","https://meetings.hubspot.com/mriber",[260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,237,448,449],"Albania","ALB","Algeria","DZA","Andorra","AND","Angola","AGO","Austria","AUT","Belgium","BEL","Benin","BEN","Bosnia and Herzegovina","BIH","Botswana","BWA","Bulgaria","BGR","Burkina Faso","BFA","Burundi","BDI","Cameroon","CMR","Cape Verde","CPV","Central African Republic","CAF","Chad","TCD","Comoros","COM","Côte d'Ivoire","CIV","Croatia","HRV","Czech Republic","CZE","Democratic Republic of Congo","COD","Denmark","DNK","Djibouti","DJI","Egypt","EGY","Equatorial Guinea","GNQ","Eritrea","ERI","Estonia","EST","Eswatini","SWZ","Ethiopia","ETH","Finland","FIN","France","FRA","Gabon","GAB","Gambia","GMB","Ghana","GHA","Greece","GRC","Guinea","GIN","Guinea-Bissau","GNB","Hungary","HUN","Iceland","ISL","Ireland","IRL","Italy","ITA","Kenya","KEN","Latvia","LVA","Lesotho","LSO","Liberia","LBR","Libya","LBY","Liechtenstein","LIE","Lithuania","LTU","Luxembourg","LUX","Madagascar","MDG","Malawi","MWI","Mali","MLI","Malta","MLT","Mauritania","MRT","Mauritius","MUS","Moldova","MDA","Monaco","MCO","Montenegro","MNE","Morocco","MAR","Mozambique","MOZ","Namibia","NAM","Niger","NER","Nigeria","NGA","North Macedonia","MKD","Norway","NOR","Poland","POL","Portugal","PRT","Republic of Congo","COG","Romania","ROU","Rwanda","RWA","San Marino","SMR","São Tomé and Príncipe","STP","Senegal","SEN","Serbia","SRB","Seychelles","SYC","Sierra Leone","SLE","Slovakia","SVK","Slovenia","SVN","Somalia","SOM","South Africa","ZAF","South Sudan","SSD","Spain","ESP","Sudan","SDN","Sweden","SWE","Tanzania","TZA","Togo","TGO","Tunisia","TUN","Uganda","UGA","United Kingdom","GBR","Vatican City","VAT","Zambia","ZMB","Zimbabwe","ZWE","UK","Germany","Netherlands","Switzerland","CH","NL",1773850432487]