 Okay, here we go. Hello, everybody. Happy Friday. We have made it through another week collectively So pat on the back for all of us Definitely a good day. How's it going Paul? We're in the discord chat there. Happy Friday to you Let's do a quick introduction. So Hello again to everyone. My name is Tim and I go by foamy guy on the github and discord As well as a couple other places online. This is the circuit python deep dive show This was originally a show Started by Scott Shawcroft the lead developer for a circuit python project Scott's on a reduced schedule right now because he has recently become a parent. So I am doing the streams for now So that is Where we are at and I think he's just about to take another chunk of leaves So Scott has been back with us for a couple of weeks, but I think we'll be taken off Here again shortly. So I'll be doing the deep dives for the foreseeable future as far as I know at least until he's getting back From that and then possibly a little bit after that before he gets into the swing I don't really know the the long-term plans, but that's where we're at For those that don't know if you are new to the program or anything like that Deep dive is a program where we get down into the weeds of circuit python. Sometimes we're working on Circuit python libraries Especially since I have started doing the stream So, you know Scott's like generally way deeper than I am in the core being the lead developer of the actual C portion of circuit python the C code that that is circuit python When I am on the show sometimes we do that I kind of dabble a little bit here and there although certainly not as deep as Scott does But we do some in the core We also do some at the library level, you know, we might work on a circuit python library We also do a bit at the project level as well, which today we're gonna be at the project level Working on the finishing touches to the game and watch octopus So if you're interested in this project after you watch today's stream and you haven't seen the prior streams I would encourage you to go back and find I think there was a couple of deep dives back where we worked on it for a bit I think there's also certainly been some Saturday streams on my channel where we worked on it a bit So if you're interested in the project you can go back and watch the vods of the prior Work that we've done on it, and I'm getting close to wrapping it up I have a couple of more kind of feature creep things that I want to put in just because I think they're cool And then I need to finish off the last bits of the guide which kind of need the code to get done first So that's kind of the stage I'm at there And that's what we'll be working on today Let me also say before I do jump right in though CircuitPython is a open source project You can find out more about it at circuitpython.org. This is the website for it right here This is a implementation of Python that runs on tiny computers called microcontrollers There's a bunch of pictures of them over here on the downloads page and one thing that you can see Quite quickly is that there are lots of different shapes and sizes of these devices, you know Some are big some are small some have screens some have e-ink some have no screens at all Some are round with alligator clips right all different shapes and sizes of these devices And we have a version of Python that runs on these tiny computers here This chip here is basically an entire computer inside there. It's not super powerful Although it is pretty powerful for its size certainly, but a tiny computer in there and it is compiling and running Python code for us And so we're building projects in Python that run on these devices In particular the one that I'm looking at today is this one right here, which is actually backwards right now This is the back of it, but this is a pygamer device So this is a circuit Python microcontroller as a screen on the front you can see this one essentially is kind of like a little game You know not quite Game Boy because it's landscape So it's you know, maybe game gear or certain other Handheld gaming setup, but it's kind of like a landscape hand-held gaming device with you know, AB buttons a joystick Has options for a speaker and some other stuff on the back there. So that's the pygamer This is one of these microcontrollers that support circuit Python And let me just wrap that bit up as well CircuitPython.org this is where you can go to learn more. It is an open source project So anyone is allowed to Contribute to the project if you're interested in getting involved in contributing Find us on github as well as definitely encourage you to join the discord That's where all of the development is coordinated Typically is through the discord and github. So head there if you want to get involved If you don't necessarily want to get involved if you're not interested in developing circuit Python or helping out with libraries or anything else But you do like circuit Python and you appreciate it and the folks who work on it and you want to show your support in some way Another way that you can do that is just by purchasing hardware from Adafruit. So this is their website adafruit.com Adafruit is paying the folks who work on circuit Python full-time like Scott who I mentioned before They're also paying folks to work on the project part-time as well such as myself So all of us that do get paid to work on circuit Python are paid by this company Adafruit They're a hardware and software company based out of New York and they typically sell Hardware devices so like the microcontrollers as well as the things that you can plug into the microcontrollers to do stuff with You know sensors lights buttons beepers buzzers levers Nobs pretty much any kind of little electronic doodad that you can imagine They will sell something like that most likely and you can hook it up to your microcontroller if you're using circuit Python You can write Python code to interact with it So thank you to everyone who does purchase hardware from Adafruit again That does help support circuit Python project and those of us who work on it So let me catch up here on the chat And in fact, let me also stop a couple of these previews because we don't Need to bog our computer down with multiple copies of this running So let's see here has a go and see Grover as well as Paul SK and DJ Devon 3 over on discord and then on YouTube How's it going out to let's see Avinash? Manohar as well as hope on and be autographed. Thanks for tuning in folks. Happy to have you here Um one more bit of housekeeping for today for folks that don't know yet The video just went out the other day so you can find this on my YouTube account If you need a link or anything like that, let me know I can drop a link But we I'm super excited to announce or just you know say again that the ESP 32 s3 hack tablet giveaway is now live The first round of drawings to figure out who's gonna receive the first couple tablets is gonna be on August the 3rd So that is next Wednesday is when the first round of drawings will be So there is still time to enter before that and then the final round of drawings will be on The I don't want to get it wrong. So I'm actually gonna scroll down right here on the 26th of August We will do Another drawing where we will select the final couple of people this way. We have a chance for some people To win it, you know sooner right on the third will draw them and then they'll get shipped out after that But we also wanted to do at least a couple of them after circuit python day because we figure it's likely that with the Publicity of circuit python day there might be people who hear about this giveaway on circuit python day and we really wanted them to still be able to Actually enter and have a chance to get one of the tablets So that's why we've got the two drawings again. The first one is on the 3rd of August That's coming up next week, and then we've got a couple of weeks Until the 26th for the final drawing. So you are interested in Getting one of these circuit python powered hack tablet devices Then head over to this gist right here, which has got more information about it as well as a link to the entry form Right here, which is where you can actually enter your information in order to have a chance to win one of the tablets So thank you to those of you that have already entered I saw just I think late last night I looked into the entries and so we've got a good chunk of folks in there now So thank you to everybody who has anybody who's interested Go ahead and enter again before the third and you'll have a chance to win the first couple And if you don't make it in time for the third Don't worry you can still enter before the 26th in order to get a chance to win those final few tablets So that is what's up in hack tablet land And now I think we are ready to jump into our actual Activity let's see new to out of fruit and excited to be part of the community just starting a survival pie in a Pelican case looking forward to learning and building with the Adafruit community be well all y'all that's awesome Thanks for joining first of all. Thank you for tuning in to watch the program But that sounds super cool a survival pie in a pelican case. You're gonna have like a Little like a cyberdeck type type thing in there. Is that the idea there? You'll have like a screen and a tiny keyboard or something you can kind of pop it up in the wild and Get down on some computing whenever you need you never know when you're gonna need to do some computing That's pretty nice Okay, so jumping into today's activity Let me I guess let's when we get our When we get our pie charm ready here, so Actually have some other stuff that we don't really want Let's pull that over here for a second This is day job pie charm. We need to switch over to fun time pie charm. Here we go Let's close this one as well Now we got fun time Python, okay One other thing actually that I will do before I dive straight into the pie gamer game as I will follow up on my PR I have one PR right now in circuit Python core And I have not checked in on it Since the other day, so I will check in to see if there's anything more for me to do on that And if so we may look in to do it, but it'll depend. Oh interesting. It's back to orange or yellow So it must have gotten a new commit or Merging okay just merged main Must be recent because it's still running The checks so that's where we're at there nothing more for me to do right now So we'll wait and see once I guess we'll probably see if this passes actions Maybe there will be more for us to do or maybe Scott will leave a another review or something like that with some feedback That's when we will go on from there and my mouse batteries are dying So I'm gonna go for a few more minutes here and nope as I'm saying it it's dying So I'm actually just gonna swap out my mouse batteries because I can kind of squeeze a little bit more out of it But it's gonna keep pausing on me which gets increasingly frustrating because you get shorter and shorter distances before it Dies on you each time. So I'm gonna grab two more batteries. I will be back in just a second Got the replacements. Got those ones in the charger. We'll plug that in later New batteries in here up the lid back on Switch we should be good now. There we go pit stop complete. We have a functional mouse now. Yes indeed. That's the idea awesome Yeah, that's super cool. Be sure to be Be sure to share your progress if you're interested either join us over on the discord if you're interested There's a show and tell channel there where you can Put updates about your projects But also feel free to share if you have like a blog or if you've posted it online anywhere else You know instructables or hackaday. I owe anything like that if you do have any information online, feel free to share We always love to see community projects that folks are working on so And if you want to show in a video form there's actually show and tell on Wednesdays I don't know how familiar you are with the with the show lineup yet But on Wednesday evenings, there's a show and tell you can actually come on You know via video and show your project kind of in person, you know over video feeds So that's pretty cool as well So today I am working on octopus game. One of the things I want to do is a high score so I basically have the basic gameplay working and I want to just pizzazz it up a bit right add a couple of like I said earlier kind of feature creep type things They're not necessarily what I had initially planned But the more I kind of thought about it the more I thought a couple of these things would be cool to do and so Let's get our camera back up here. I think we'll be all fuzzy Let's do the focus. How's it going Dexter? Happy Friday need circuit Python mouse on cutie pie s3. I would probably use a circuit Python mouse I know I know Scott uses circuit Python I don't think it's for his mouse directly, but it's like a switch that affects what his mouse does maybe or affects what his keyboard does one of the two And then I believe Jeff has a circuit Python keyboard as well that he uses as like the daily driver Sorry, I'm trying to find my focus thing here. There we are. That's pretty good So basic gameplay is pretty much working You choose a game this one's game a these are our left right buttons here You know just quick recap for folks if you haven't caught the old streams the ideas You're the diver character you come down you go across you try to take treasure from the treasure chest And then you try to take the treasure back up to the boat You get points for each treasure that you manage to capture and you have to try to elude these tentacles of the octopus if you get caught by The end segment the last segment of the tentacle you'll get caught You'll flail around in the middle right here And you'll lose the treasure that you have collected on your person But you will not lose the treasure that you already took back to the boat And then you just get points based on the treasure You know your score is right up here on the top and you pretty much display until you run out of lives You try to get as you know as much treasure as you can as high as score As you can Once you do lose your last life then the game is over and that's pretty much how it goes. So I'll Let's grab. Okay. There we go. So we get caught. We flail our arms around a bit there We get to go again. I'll get caught again real fast. So we flail around and at this point we're now in the game over state So essentially we'll just our diver will just sit there and keep flailing Our score of course will stay on 20 and it's basically waiting for us to play again If we want and the way we do that is by choosing game a or game b So if I choose game b this time, you know, there it says game b and we're ready to go with this one And essentially the difference between a and b is just b is a a little bit harder moves a little bit faster And that's the main difference so um So high score though is what I want to do. I want to make it so when you go to the game over state You It will record your score to some Long-term storage some persistent storage And then maybe it will also show you like The top, you know, I don't know three or five or something like that. It'll just show you a couple of them So that you can see the the high scores And I think the mechanism I want to do that with at least one of them is just going to be the sd card So I actually have an sd card plugged in right now. It just has a text file on it. There's really not much there um But that's perfect So we're actually going to put that in our pie gamer because on the pie gamer Which is what device this is on the back. There is sd card slot right here Excuse me knock the camera here. Let's try to carefully get my sd card Is So I think what I want to do is just uh nice and easy just like write it to the sd card in a json file um You know with just a list inside of it basically or an object with a list on the object If I got my sd card plugged in, um, I do not know The sd card code off the top of my head. I'll have to consult. Um I'll have to consult a learn guide. So let's say circuit python sd card You know one other thing I'm actually going to do real fast here is uh Turn the temperature down just a degree or so. I'm getting heating up a bit There we go. So let's see The circuit python code I basically have a couple of options. I know there's like sd card i o Like there was sd i o. I kind of I tend to Forget which one is the sort of like best practice one That's a good idea. I'm on data for discord. I'll keep building a log. Thanks for the info. Yeah for sure um Initialize using the support matrix Thing is I know that there's like sd i o i o but then there's also sd card i o And there's also adafruit sd card, which is the library the python library version I don't remember which one is the You know quote-unquote better one Uh used for me guys nvm helper for Persistent storage setup as a non sd card works great. Yeah, I was thinking That uh might be the plan as well. Actually, I got a little bit of uh, trick up my sleeves So I was thinking the sd card first Uh, but if the sd card is not present I do think I will Try to use nvm to store the The data as well sd card i o is better performance recommends you use that one versus the lib Let's check this one and then sd i o i o It's the one I don't remember usually my code doesn't work. I have no idea My code works. I have no idea why oh my code doesn't work. I have no idea why my code does work I have no idea why uh, yeah, I can definitely relate to that That's definitely true See here Buildable on these boards so if you the sd i o bus Parallel protocol Clock pin command pin one or four data pins Hi frequency One of them is on spy Okay, this one doesn't look like it uses spy Got a clock pin a command pin a data pin. Let's do this one. I think Well, let's see if we can find the pin. I guess first and foremost I'll just use to to find the pin I'm gonna just drop into the repl import board dur board Right like that. We'll see there Sdcs indeed. Yep, that's right there. So this is probably the one we want to go with sd i o looks like maybe a different uh Different hardware connection. So in my case the place where I'm going to put this is actually going to be inside the game object and It's going to be based on a parameter In the library It's sd i o i o because it's the library that implements the sd i o protocol Which is the fast one that requires hardware support on the board. I think okay, okay And I my guess is I think I probably can't use that one on the pi gamer Although we could check as well actually could we go This yeah no module sd i o i o. Okay, so I think that's not supported on this one, which is all right Um, I'm gonna do this inside the octopus game. I think what I'll do is just have another argument or well n argument at all because we actually don't have any arguments yet We'll just say actually want Two different ways for it to work And I'll try to comment this as I go along because in the last couple of days I have gone through every line of code of this project and Tried to comment it up. So at this point, I'm going to try to anything new I'm going to try to comment right out of the gate rather than having to make another pass through So these are going to be constants that represent different high score types high score Technology high score type constants high score sd card high score disabled We'll do zero on that one actually Maybe one for that one nvm two and then here we'll go high score type equals and by default we'll do Disabled So by default, uh, nothing it won't do high score at all But if you tell it sd card, then it will do that and if you tell it nvm, then it will do that So in our constructor, we will say down here we can just say set up the high score if Probably want to store this as well. Actually Let's put that on self that way. We can access it later I don't know. We probably don't really need this right. Let's just do it that way If Well, do we want to do the imports? Actually It does kind of make sense to do the imports inside of here that way. They don't get imported if they're not needed Okay, we don't really need to lister. I don't think although maybe that'll be helpful to, uh Just see if it's working And actually we don't really need to put anything on self because at that point We just like write files to there One thing maybe we will need Well, this is wrong first of all One thing we should probably do is try Try all of this and if it fails Let's do it without try first because I don't know the exception Type That it will raise Let's do it that way first. We'll unplug the sd card once and we'll see what exception that will raise That way we can catch it and then just put it back to disabled type the way we have Graceful fallback essentially We'll go if self dot high score type is self dot high score in vm pass Set up in vm. Yeah, let's do the sd card first. So if we give it the right argument it should Initialize the sd card and print the files that it finds on it card data, let's just say if We're using sd card high score system Okay, so we'll save that Let this run We didn't pass it yet. So let's go to code pie There we are here. There we go. We got our hello dot text, which is perfect Um Now let's make some helper functions that will kind of Let us uh Read and write our high score. So We'll just put them down towards the bottom here of our game object Def let's call one uh read high score data This is basically gonna try Open Um slash sd slash octopus High score dot json We should probably make a variable for that, right just in case if people wanted to use a different file name for any reason I don't know if that's very likely or not, but We're gonna open this for reading When we're just reading the data Can't return actually we need to say data object equals json.loads We need to catch this f equals f dot read f dot close Turn The object but we'll also say accept return None or should we return Maybe we'll return like a base object that's empty or something def initialize high score file That's gonna open it for writing So we basically want like We almost want to just say like if the file doesn't exist then we want to do this How do you check if a file exists? I guess we could do us.path import exists do we have that we do not I guess we'll do lister then we do have lister If that file But that's gonna be Only the file name Okay, so maybe we shouldn't have sd card in this Just be the file name We'll import json only if we are Doing high score Maybe only if the file doesn't exist. I want a chance. Yeah, that's what I'm thinking as well So that's what we're putting here. So if that file is not in os.lister Of slash sd slash Then That's when we're gonna do this High score list equals a list That's gonna get written Close Unresolved reference interesting. I guess we'll just import json I guess yeah, technically it doesn't know that I guess we'll probably need os out here as well. Oh, we already have it. I see print I don't think actually let's keep printing just for the minute so that we can actually see when our file gets created If the file is not in the list of files that are in the root of the sd card open it as writable This will now need this though Same thing here actually as well Because we don't really need that to be all split out like that If the file doesn't exist, it's gonna get created. So here Well, we'll still probably want to try catch as well inside of here also Because we need to basically handle if the You know if we didn't get the sd card initialized properly then this will Really raise an exception of some port Of some sort We're on github. Can I create an issue concerning aida fruit aio? time url request response, um It's a good question. I'd probably say that the aida fruit io circuit python library is about as good a place as any um Yeah, I'd probably start here Even though it's not like it sounds like your question is maybe not necessarily specific to this circuit python library But instead more specific to the server side Uh, but I don't know of another good place like the server side doesn't really have a github repo in the same way that You know this library does so um I'd probably start here and Somebody should probably see it here and know if there's a better place for it Like brint might know if there's a better place for it. Yeah, that's probably that's probably where I'd start I guess we do want to try this When we read here, so essentially anytime we read we'll initialize first Um, we'll figure out the try catch new data object You just call initialize here as well that way if it doesn't exist it'll get created and then yeah, and then we just write The data that we got in this file, so we'll go This one again But instead of this empty object We'll dumps new data object that one right there Now we'll write the data into there So basically when it comes time to do it we'll read the high score data We'll check the scores in the list if ours is higher than The ones in the list we'll put ours in and then We'll trim the list down to like three or five or something like that And then once we've done all of that we'll save The resulting modified object back into the file when returns none Read high score data This one returns a Dictionary I'm gonna put sd on all of these Because we will have slightly different logic for the nvm variation Or should we have the if statement inside of here? Actually, I think I like that better. Let's undo that Let's undo that Because this will have some initialization to do In uh an nvm land as well check if the high score File Or nvm object exists and create it with an empty list if it doesn't This then we'll actually say if self dot High score type and then we'll have l if nvm do whatever we need there as well So how do we want to show them? I think what we'll do is just I think we should have a label that we can hide and show So I think the way I want this to work is when you're in game over mode Or Waiting to begin mode, which is the mode. It's in when you first boot it up I think I want it so that if you press Either start or select Camera died again then It will show the high score to you and it will just be in a label that gets splashed on top of The rest of the stuff So let's go ahead and do that. So we're gonna say Back into here So interestingly because we chose to put zero for The disabled one that means that it will equate to false Which means we can actually just say if high score type and that will mean If it's any of the ones that aren't zero So we'll only do this if we are going to use the high score in which case we'll go self dot High score label equals a new label with Font terminal io dot font scale do background color Let's go roughly the same background as So we have to remember too. It's only gonna it's only gonna be as big as the text Okay Yeah, I think that's all right though. I think we want the color of this Which isn't there Yeah That I drop no I want to Oh, are you serious? I can't okay. There we go That's what we want right there. It'll be hex though Our color We don't need any text yet Anchor point Zero point five zero point five Catch up here. Just started using pie charm watching you all the shortcuts and tricks is neat Didn't know you could do a lot of stuff Like selection tab for in dense learning how to use pie charm better from watching you too. That's awesome. Yeah, I'm glad you mentioned that it's uh It definitely does has a lot of you know Quote unquote like batteries included. They say for that sometimes like it has a lot of Really really super handy Shortcuts for things Anchored Position is gonna be I think we'll just center this why don't we? Yeah, I think so. Let's center it. So we're gonna say uh anchored position is um Do we have display in here? We're gonna actually have display do we that makes it tough um Let's pass the display when we initialize this and Do it this way now we'll have height than width We go to display Okay, so now our label should be in the middle Doesn't have any text in it yet That's all right Let's just put some bogus text in it for now 67 New line Uh 50 33 new line 21 It'll be our high score for now adding left 20 pixels Adding right 20 pixels padding top 20 pixels padding bottom 20 pixels and You append it to self self dot append self dot high score label So now it'll just take over the screen. I think it'll just be showing on top of our game That's not what we want ultimately, but this will at least let us see if uh It's working. Okay. I see a box there, but I don't see Any text in it my guess is our text is probably white or some other very light colors. So let's go Monk Okay, there we are uh Feels too low We booked a work meeting during circuit python time. What's up with that? It's not the right time for a meeting Are they thinking I guess we just have too much padding there we go We get you know, we could have more On the sides than the top and bottom. In fact, maybe we don't need the top and bottom at all Okay Do we maybe we don't want scale to? I'm trying to think if we want scale to or not One thing we can do is line spacing 1.0 That should tuck it in a little bit better Yeah, we could probably fit a couple of more. Let's see how many we can See if that fits or if we're Got too many at that point Hmm not quite It's kind of clipped just a bit at the bottom there And it does look like possibly there's room for This to get even smaller I know that we want them too small, but I mean that's not that bad really That does fit all five pretty nicely Like that Wish we could have a border on it Uh, which I don't think we can Very easily That would be cool if we could Okay I think what I want is you'll just press either start or select During the game over mode or the game waiting to play mode When you press it it will show this label Populated with the data from the file or the nvm or whatever it is. So We've got it set now I'm going to keep this bogus data in it for a little while just so we can hide and show it and make sure everything's working Um And then we'll we'll go from there. So Uh, let's see here in code pie. We're passing through start and select just as Right button press left button press So what we'll do is inside of those functions Check which state we're in to determine the Appropriate action. So this says basically if the current state is not game over and the current state is not State waiting to play So if we say else then that means it is one of those or the other else How's it going i g tv? Thanks for tuning in friends It's happening to me a lot lately sympathize. Yeah people these days can't uh I mean if you can't count on people not to schedule a meeting during circuit python time, what can you count on people for? frankly So if we are in one of those states then this is when we want to Basically just we're going to toggle it. So we're just going to say self dot high score label dot hidden Equals not self dot high score label dot hidden basically take the opposite of whatever hidden currently is and Make it that Set it to that We'll basically have the same thing here Because I think we just want both buttons to do this doesn't matter if you press the Start or select button or in this case. We're actually calling them the right and left buttons since that's the way that this game works Um, so I should be able to hide it now by pressing the button indeed. We can Be able to show it again perfect There we go. So now we can hide and show the high scores Uh, we should probably Do like a well, let's say if high score type So because if it's disabled then we're not going to do anything of course But if it's either nvm or SD card then we do want to do this you may as well. I think also just go read Self dot read this I think what we're gonna do is actually change the way that this works. I'm pretty sure I had this function return But in hindsight, I don't actually really want it to return. I want it to Turn none Okay, wow Okay props props, uh where props are due Uh, I will say good job to youtube for making it so that when you report a Spam a clearly obvious spam in the chat such as the one we just had It no longer shows the person's name Which is fantastic because lots of the people who put spam in youtube chats choose names That are also kind of problematic to show on the screen So plus one thumbs up. Thank you to youtube for making the moderation experience of youtube chat A lot better Usable I would say even so. Thank you. I have spent time in the past kind of dogging on the youtube chat because it Is kind of frustrating the lack of tools for moderating but props where they are due that's Very good improvement over how it used to be so thank you and good job to youtube So we are going to read it. We're not going to bother returning it anymore. Instead. We are going to Put it into the label. So we'll just say self dot High score label dot text equals make high score text update high score text Update high score text this will get the data object def update high score text this takes data object and Actually, I just do this We'll wrap it in this that way we check if we're disabled or not only do this if we are not disabled Then can you do this new line dot join data object High score list Yeah, do we need anything else for that? I don't think so update high score text that really should do it We're going to pass in that object there Read high score data we'll call this update the text so at this point We could still hide and show it But it will no longer show our bogus data anymore. I think we'll end up with empty Yeah, after we hide it once and try to show it the next time It never shows again because it doesn't have any actual text in it because we don't have any high scores in our data file. So let's make one more function def evaluate High score Okay, so open the file for reading Read it close the file Now we're going to loop over the scores So if the score in the list Is less than the score of the current game numerate But if the score in the list is less than the current game score We want to insert at zero Self dot score and then You want to delete the last one I think we could maybe do del Uh, and then we give it the index or something Oh pop. Okay. What is removes an element at specified position Removes and returns the last element. Excellent. So we should be able to just say pop. So if we do add Then we want to also go After we insert Oh, no, we only want to do that if we have more than the max It's greater than four Then We pop Remove the last one So they'll get added Until we get to the fifth one once we've added the fifth one will then remove the last one to get back down to four And that will just happen over and over again. We will not insert at zero here. We'll insert at i So we want to insert in the place in the array where we're at That way they'll stay ordered the Highest one should stay at the top. I think I'm not positive if that's gonna work. We may have to tweak the logic. So we'll see um Okay, uh, if it is And after we have done all of this we then want to write the data back out. So write self dot write New data will just be data object which has now been modified Okay, I think we're there, right? So really the last thing we would need to do is actually call Evaluate high score And then once we do that it should start adding our scores to the list. So let's say Oh, where is this this is um It's gonna be essentially when we change to the game over state Which coincidentally enough is actually right here, which is super handy Uh, so here we'll just say if I love when I'm mindlessly scrolling around and find the exact thing I'm looking for and I didn't even know I was looking I didn't even know what I was looking for specifically when I started scrolling I was still in the process of figuring out what I needed to find Turns out we scrolled right to it before we even realized what it was So if we're using high scores, if they are enabled then evaluate high score and that should be all we need to do because Self that score will already be stored on there. It'll check the list. It'll do its thing But let's see if this works I am gonna put the back of this back on because it's easier to play Uh at some point we'll take out the Label, um, the bogus ones rather we'll take out the bogus Scores Oh camera died again It's getting pretty bad on the camera with this one now. I don't know Focus again One other thing we need to do is we need to hide the high score when we're about to start the game If it is showing because otherwise it'll just stay on top That is right here. In fact, why don't we just put it inside reset? that way It'll never be on top of the game Wait long enough Dang it. Oh, I shouldn't have gone here. Oh dear. Okay. There we go. Okay. Come on. Keep going get some more a little more Okay, now go Nice Okay, wait for the last one. There we go And back out. Oh, we got caught by that last one right by the boat All right, one more life. Oh, and then I just ran straight into it. So So much for one more life Good news is we get to check now. It should have called evaluate And theoretically it should have added 36 to it. So at this point we are in the game over state So if we press start or select Should hide the uh, it should show the high score label which should have 36 in it, but Doesn't look like it did so Let's figure out why Um lose life Game is looking fun. Yeah, thank you. Appreciate that Uh I'll check for game over Current state to game over If we have a high score type then evaluate High score Need to evaluate high score Just uh win in doubt just add some prints. Let's do some good old print debugging Uh print Inside evaluate High score. Okay, and I apologize, but I'm gonna have to run to the rest room really fast and come back. So brb Okay, sorry about that. I was not gonna make it The rest of the stream. Uh, so we got some in here It's just double check the logic while we're here evaluate. That's gonna read Get the data object Loop over the things in the list Uh, I see the problem. Does anybody else see the problem? Win in doubt print for sure. Yep. Hi tim late, but president. How's it going rich sad? Thanks for tuning in Uh, so the problem is if there's no things in the list We will not loop over this any amount of times So in that scenario What on earth did I do In that scenario If it has the length Do that else So if there's no scores in it then just add it We know that we won't need to pop because we're adding the first one We can just use a pinned instead of insert We do still want to write Give it a try Camera froze again. This camera is Killing me. I don't understand I don't understand what could be changing over time to make this so much less reliable But it certainly feels like After a couple of months of using the phone it starts getting messed up like this And I'd imagine what technologically it could be but Power through here. So we'll go game a Yeah, yeah got caught by that last one there At least I won't just run into it right away again though What were we we were 36 last time see if we can beat that even though it didn't save We still got Two lives Oh so close. I should have got one more Oh, no. Okay. Well, we got to 37 at least I should have gone past Oh, I don't know Okay Oh, there it goes. Oh and it crashed crashed Need to evaluate high score inside evaluate high score Join expects a list of string slash bytes objects consistent with self object I do this bit wrong Is it join and then you give it the string instead of string and you call join on it Blend up so lessons you must upgrade resistance as futile Yeah, well, that's the thing This is actually a newer one than the one I was using before And the one I was using before followed the same trajectory of like It worked fine for a long time and then started getting a little flaky and then got more flaky and then became unusable and This one started out fine for several months started getting just a little flaky Started getting more and more flaky and now it's getting to the point where it's pretty much unusable I wonder if it's storing like Cashed stuff or something. I wonder if the storage is full. Maybe so this is actually you give it the list I would have thought I do wrong here. So Maybe if the list is empty join expects a list of string slash bytes objects Maybe they were ints Maybe they were ints It actually gets tough How do we invert them to strings? Really we should Probably invert them to strings Prior to writing I think right shouldn't we and we'll have to convert back to ints to compare But I think that's okay Let's go Actually, this is silly. Why don't we do this? Convert it to a string when we put it in But leave it as Put it back to an int when we need to compare And so unfortunately We're kind of just stuck on the first one Because at this point we have a 36 number In our thing We need to get it back out of there or we need to convert it to a string one or the other Um Probably just delete it's going to be the easiest thing for now This will initialize a game Which will set up the sd card So that I can then go Or delete Now we can restart We still have our bogus ones, but if I click again, it doesn't crash. So I think Maybe we're okay at least for now Go game a One thing I should also do still is double check that my speed up logic is working Oops got caught. I implemented some speed up logic where As you get a higher score the game will go faster up to a certain point. There's still like a maximum speed Um But it would be good to verify that that's actually working And maybe make it a bit more aggressive I will say too because I don't feel like it's any faster right now But I also don't know At what point you reach the fastest speed like We may still have a ways to go before we actually hit the uh the highest with the current algorithm the fastest Okay, I think we'll lose after this one. Let's give it one more good Collection spam here. Let's get back to the boat and then Let's just get caught 77 made it up to Now we're in game over mode Be able to click again get our high score. There it is 77 so we should also be able to play again Get caught Let's get at least one Let's not have we don't want to get zero on the high score. In fact, we should probably Should we make a special case for zero? Should we say you're not allowed on the high score board? You only got zero score That feels kind of appropriate. I think Oh got caught by the last one Okay, let's just grab again. So 11 will now go into the high score Oh, no, it didn't Why didn't it? Oh, I see I see why I don't see because it's not in this part of the screen, but I know why and it's because inside of evaluate Our logic is wrong here. It says if we have No items then append it We have some items then loop over them and look for one that's lower than the current score We actually need to append it if we have less than four Let me catch up here as well Oh, it's been a minute. Uh, here we go By the way to those who were on the other night begging for the pico w got one ordered today from pie shop us limit one We'll do the wi-fi port on circuit python soon. That's awesome Uh, I would bet they were non strings. Yep. I think that turned out to be right Always a new phone even when you have the newest phone marketing for the next phone launch begins The model hits the stores. They prey on the perpetual cycle of FOMO. I will say I don't um Don't fall prey to that myself. My phone was Getting up to be about like five or six years old and then I bought one that is also still five or six years old from now, but Was new in box. It's just you know new in box phone that was released five years ago I tend to buy the old ones join. So this one is with the uh, what you call the uh expander. That's not the right name for this, but We're getting that the name of those um inline list loopy thingies Ex uh, expand expression expansion. I don't know. That's all right Zero gets an animation of lia a blink of laying an egg. That might be kind of fun. People play with 66 megahertz Microcontrollers not the type to be affected by FOMO Uh, I didn't just get two s3. So what do I know? Absolutely nothing tim. I miss uh weekly I missed this weekly because of work. Oh, that's no good Real question is who's organizing and when is the cp octopus twitch battle? Not it. I don't game. That's a good question If there is somebody who wants to have a uh an octopus off if there's somebody who would like To challenge me uh live on stream to a game of octopus if you have a pie gamer Or a pie badge device and if you have a way to like have a camera that shows your device um Anybody does have that and wants to do a live octopus Showdown on twitch. We totally could arrange that so Bring me on discord if somebody is interested in that That might be kind of fun to do We can uh get on a video chat or whatever and pull them both into the stream and then play side by side Once and for all find out who's uh the best treasure diver Probably will not be me. I'm guessing but I don't know. I have practiced a fair amount now. I guess So we basically we don't want to say if it's greater than zero Really what we want to say is if it's less than four No, we want it because we also we we do still need to check Okay, I think what we do is We keep it like this if it's greater than zero it goes in here it loops and checks if it's On zero then it just depends without checking When we get to the end of this list And we get to the end of the list If we haven't Added score equals false added score equals true We got to the end of this for loop if not added score And length this less than four Then just append it because that means that The current score is not higher than any of the ones currently in the list But there are less than four in the list. So we want to just append the new one to the end Which in our previous case that would have appended the 11 Onto the end there. Let's see here. Let's see here Circuit Python day octo battle royale. That'd be fun too. Yeah, if we had a couple of people We could do a tournament on circuit python day Well, my pico w comes I'll study micro python put it on pico and review the network support module and start the port Then test in a few days awesome Yeah, that sounds awesome Definitely super stoked about the pico w and having a wi-fi support into circuit python eventually. I think that'll be Pretty nice for the You know cheapest iot little wi-fi capable device being that cheap Um We'll be a bit of a game changer there. Let's cut in a decent chunk of change out of the price of Kind of like the most basic sort of iot type projects you can do Got caught That's all right. Truthfully, we're good now. We could just get caught again as long as we have some points Uh and as long as we stay under 77 as well, I guess because that's the logic we're trying to test is There aren't enough in the high score list yet There it was. Okay. So now we got our 18 We should try to aim for maybe more than 18 but less than 77. Let's make sure it gets inserted at the right spot Uh, and it's very possible that i'm actually off by one on the insert. I actually don't know If I did the uh index correctly I would say i'm not very would not be very surprised if I didn't if we were off by one I wouldn't be very surprised. I don't think oh shouldn't have gone Okay, now we'll just get caught. Oh no insert Something went wrong greater than list in lose life Evaluate high score 623. Oh goodness gracious Another round We'll take those bogus ones out here pretty quick as well Okay, we'll get caught here on 30 We we just don't want to test the same thing the uh inserting into the middle Okay, one more We maybe ought to hide that last segment whenever you lose a life that way You can't just immediately run straight into it again. I don't I don't think the uh the original game has that sort of Guard rail in it. I think it will allow you to just run into that first one, but As a player I can see it would be pretty cool If uh We don't let you just lose real fast like that. Did we put this inside the for loop? Most of them use that I both file it in purple jumper wires They're cut to the same length Can we change the divers to blinker we could theoretically Got enough running a guitar for sale on craig's list Found out it was a scam. I hope you didn't pay the scalping price Could it just be appended to the list and then sort it? Maybe Probably yes, but the shorter answer is I don't know how to sort lists Is there an easy function for that in circuit python? I also don't know if it'll matter because my list has strings in it that might make it Not sort right. I don't actually know for sure Um So I think what happened is that Basically added multiple times I think what happened is that it started this loop here This ended up adding a thing which then caused This to loop again Because now this has one extra item inside of it So it looped again I don't know why it decided to add again though Because it's not less than It would have been equal Unless it was still comparing to the old one Yes, that's probably it. It was probably still comparing to the top one So I think why don't we just go? Or we break out of the for loop so we just stop counting the for loop and unfortunately Now we have a lot of 37s like I'd like to uh Reset again. Do I want to make a function to reset? No, I think I'll just keep using the REPL Let's take the bogus ones out There it goes come to In case we want to turn it back on I'll delete it. Um Out of the final one though list sorted equals sorted list or list sort to in place sort Followed by the for loop to deduplicate. Yeah, that's the other thing too is I don't want to add duplicate ones Which I think the logic I have now will prevent Oh, no, it won't actually prevent adding duplicate ones Because it could be larger than the next one and then it would still add Don't add it if it's already in the list Okay 18's plenty. Let's get caught here Okay Got our 18 Okay Now we want to go between 18 and 7 So now we're game over There we are Now let's try between 7 and 11. Let's try to get 8 Oh, let's also show this and then start nice Oh, no, I shouldn't have gone back. Okay. Well, we could test 11 As long as I don't get any more because this should basically not add anything because we just added that check for not in list May also, I'll scroll the chat here in just a minute Oh, no, it still added it and it put it in the wrong spot Oh because of the other check afterwards dang, there's a lot of edge cases that I did not consider It's a list of ints cannot have any dupes. Sorry for not paying attention. It is a list of strings I forgot a space after the last Hashtag to know if that'll throw an error in pycharm. You would definitely complain about that Not sure where Is that one you said Hashtag do I have a hashtag in here? Oh the bit that I commented out Where it set the label of bogus text It's got to be I think what you're talking about right where I added the comment Yeah, I think it will complain but not Not like not run This one here. Yeah I think it does it's yellow block comment should start with yeah hashtag space Now the yellow goes away. So it does complain, but it doesn't stop it from running Um Okay, we got another Problem which is inside evaluate We don't want to add unless it's not in the list yet This one. Okay, so If we haven't added it yet Ie meaning that all the scores in the list were bigger than the current score That would be the reason why we haven't added it. So if we haven't added it And there are less than four in the list And the current one is not already in the list Then we want to append it And then only then We don't append it If we already added it, we don't append it if there's already four in the list We don't append it if it is already in the list as well So now we do have the second Copy of 11 in our high score though We need to fix that somehow Let's try to Do repl again I wish I could go up Find the things I ran before Let's make a little helper script to set up the sd card for us. Why don't we I think that will do it, right? There we go so Yeah, let's try to get a let's say more than seven less than 11 There we go. Nice Yeah, that one went in there between I think we're looking good I still need to do more testing of edge cases and stuff like You know, if we get one above 11, we need to make sure that The bottom ones get pushed down Oh my Nice, so seven got pushed off the list Now it's 18, 14, 11 and 10 14 being the one that we got this time Nice, okay I'm liking that Sort of dedupt list equals sorted list set list of strings to be all set theory about it. Oh, yeah, I forget about a set I have used set for that before as well To get rid of the duplicates in this case. I think my logic will make it so there are no duplicates, but That would probably work as well and honestly the code's probably easier to understand Probably than what I got but I think satisfying about watching an unordered list gets sorted. Yeah, definitely especially like if you've ever watched the sorting algorithms work like where they It visualizes like which ones it's moving at what time or whatever and you can see the difference between like bubble sort versus merge sort and all the others Okay I think that's probably where we wrap it for the night. So we got about two hours in we got the high score worked out for the sd card We got some of the infrastructure in place to do the nvm version and we're pretty much ready like I think all we would have to do for the nvm one is pretty much just inside of Read data read high score data and Write high score data initialize We'll need one branch in here that initializes the nvm object We'll need one branch in here that reads out of nvm and calls update high score We'll need one branch in here that writes to nvm instead of the sd card This will stay the same because it's getting past the data object. It doesn't care where it came from this will need logic to say If it's the sd card then do this If not then read it from nvm, maybe we should be returning Maybe this should return data object That's how I started it initially Because then inside of here It could just say data object equals read high score data Which will then correctly handle if it is an sd card versus if it is nvm because we're going to have Lf like this We'll do its own setup inside of here That way evaluate high score Actually won't have to care about it. It will just get it from the read function, which will make sure to do the right one It will check through the list if it wants to write it'll call right Inside of there that will do it correctly whether it's sd card or nvm Yeah, I think we're that's pretty much all we would need for nvm So it's really not going to be that many things. We basically just need to add branches to like three of these functions and tweak the uh tweak the logic inside this one to actually use the read function instead I think we'll plan on doing that tomorrow though On the uh, Saturday morning stream Better not to have to de-dupe after the fact Defragmentation sorting algorithm Competitions are really neat to watch put on the finishing touches on the game home stretch looking great. Yeah Yeah, I was I I struggled with it because I wanted to call it done I I I need to get the guide done and published I know I need to get the guide done and published But I was thinking about it last night um While I was doing some of the comments I was like, uh, I really wish there was a high score because then it gives you like incentive to play again Right, it gives you incentive to keep playing and try to beat your high score which like you could remember it I guess but I think having it show is so much nicer. It gives it that more tactile sort of like This is why I want to keep playing is to beat that score um And I figured this would be good as an example as well, right because Remember the point of this game is to be a game but also to be an example project. So I figured this ability of Storing the high score At all but then also storing it either on sd card or nvm Provides some good reusable chunks of code people will be able to take this concept and Use it for other things, you know, maybe they're keeping a high score inside their game Or maybe they're not even doing a high score. Maybe it's some other thing entirely But they want a similar You know ability to either use an sd card or nvm. So I figured this will give it some Good example code usage in the future Okay, so thanks for tuning in everybody. Definitely appreciate all of you. Um, I will say again happy friday Um, I hope everybody has a good night and a good weekend and all of that I will be back tomorrow morning at 10 a.m central time Uh for my stream over on my channel that one's on uh twitch.tv slash foamy guy underscore twitch Um, or youtube slash foamy guy. I think it is I'm less sure about that one I'll drop links in the chat. So if you're interested in catching those saturday morning streams, the best things to do are Uh, follow me on twitch. That's probably the best thing because then you'll get notifications from twitch when I go live Uh, or the other thing you could do is just definitely join the aida fruit discord Watch that live broadcast chat room and I'll put the links in there the direct links to the current stream Uh, whenever I am going to get started streaming in the morning. So, um tomorrow morning will Do the nvm storage will get that wrapped up and I think what we'll probably do after that is get the pr in For the learn guide repo to add this code to it And then once that is in The rest of the guide can be finished because it needs to embed Code that's in the learn guide repo. So that's where we're at there Uh, thanks for the deep dive always learn something new and useful. That's awesome. Yeah, thanks for hanging out Thanks for letting me know that uh, it's interesting and that you learn I definitely always appreciate that kind of feedback. So thanks folks Uh, thank you to ask patrick. Have a great weekend to you as well And yeah, I'll just say some quick goodbyes here again. So thanks to c grover ask patrick w dj devon Uh, who else did we have hanging out today? Todd bot? Uh, c grover. We said let's see rich sad. Thanks for hanging out Also, uh, thank you for the work you're doing on the wi-fi. That's going to be amazing as patrick w Let's see. Did we have any other discord folks today? Trying to think back. Uh, mark gambler. Thank you for hanging out paul sk. Thank you as well neardoc Uh, I think we made it there dexter Paul sk paul cutler as well. Thanks paul cutler. That's our uh, that's our discord list over on the youtube We got biata usual suspect. Thanks for tuning in. Appreciate you as always Uh, i g t at dot tv fury command corvus Let's see their hope on and avanage. Thank you to all of you folks for watching I will catch you all next time which again for me. That'll be tomorrow morning. Um, but i'll Oh, uh real quick actually last bit of housekeeping is no deep dive next week I'll be gone next week. I have other plans on friday So no deep dive on friday or at least i won't be doing it I don't know if anybody else is interested in stepping in uh to do a stream on friday evening if so reach out ping me I'd happy to Help get you set up if you are interested in doing that, but yeah, I will be gone next week So no deep dive with me at least next week on friday. So, um, yeah, I'll catch you all Tomorrow morning for my stream. Thanks again