 Welcome to this Commodore 64 basic tutorial or example And this is the first video like this that I've done and I don't want to whittle on for too long about Things in general. I want to try and keep it to the code and to that end I might not explain things in as full detail as possible If that is the case you'd like some further explanation Just drop me a comment below and I'll I'll get back to you But I want it to be concise and try and keep the time down So you don't lose interest too quickly So what this example is as you may have seen if you're looking at the source code in front of you on the screen is a very Simple rock-paper-scissors game Okay, so we start off here at line 10 by printing the character Represented by number 147. No, what is that? Well, it's a it's a character It isn't just a isn't just a key that you'd press on the keyboard Hence why after the print there could be a space here. There isn't in this example You know put a space in if you like for readability What'll actually happen is the Commodore 64 will strip that out. It's not necessary and that's what had happened here And that's what happened Elsewhere you can see when I've pasted it from the vice Commodore 64 formula into Into this text editor You know some of the spaces have been stripped out So by printing CHR dollar sign number 147 we can print a character that isn't Either isn't or isn't easily accessible, you know and by a key press so in this case character 147 will clear the screen of all text Won't change any sprites that might be displayed But we're not using sprites in this example So just have the effect of clearing the screen for us with a nice blank page to work with very next line sets up a variable called CPU and a variable is just a Just some letters, you know can be a word or a mnemonic or a single letter that stores a value And in this case, we're going to store an integer so a whole number R&D is the is the basic interpreter directive for to get a random number and We want that to be a random number between one and three Because there are three possible outcomes or three possible or choices in rock-paper-scissors, aren't there? So once the CPU has chosen its random number between one three stores it in the variable CPU and Then at the end of this line after the colon now colon separate commands that are in a single basic line So I could just as easy as easily put goes up 100 on the next line But I've chosen just to tack it on to the end here and it just shows you I use elsewhere You'll see Colons to separate often similar commands on one line rather than taking up multiple lines So let's quickly nip down to 100 where this go to subroutine 100 would send send us and starting here we can see 100 we have three if statements and then we return now the return directive sends the Program or since the basic interpreter or the CPU back to Just after the the go sub command that sent us sent us there in the first place So once this return is here would be sent back to you after the go sub 100. There's nothing more here so we go on to The next line start executing from there. So anyway, so line 100 is an F statement well, they all are and So depending on what variable sorry, what number has been stored in the CPU variable one two or three We'll then set up a create another variable called C and it's a string as denoted by the dollar sign and If one is in CPU then the C string gets set to rock if two is in the CPU Then the C string gets set to paper three would be scissors and then we return So right away for anything is displayed on the screen clear the screen For any messages are displayed with these print statements that I'll come to in a sec The computer already has already made its decision if you like so really chosen rock paper or scissors So then straight after we print a welcome message and some simple instructions for playing the game and you can see here that I've separated and These print statements just with a colon just to fit all three on one light or four rather on one line now When it runs You'll see that each one of these the reason that it's not just one long print statement So I wanted each one to be on a separate line that there's no obvious symbol here for or character for Doing a line feed and a carriage return Yeah, the C64 basic interpreter and others I'm sure Automatically at the end so if it reads if it prints sorry a string Terminated just with a speech mark It will automatically add in carriage return and line feed So what you'll see when their program is running is that this are for rock P for paper as for scissors are all on separate lines The one below the other and then there's just a blank line left inserted for yeah, just to make it look nicer when it's displayed then The message press any other key to quit leave another line then we get into the first loop of the game Which is this on line 50? So we set up another string called P String variable called P in it. We put nothing so it's just blank then we ask the user for inputs So read a character is what get does into the P string if no character has been pressed So if the P string is still empty after this get commanders run has been run then we go to 50 Which is the line we're already on so this line will loop over and over until a key is pressed Now you can see from line 60 70 and 80 We're looking for the user to press our P or S to represent You know their choice of either rock paper or scissors So if we if the user presses are then we'll go to subroutine starting a line 200 they press P 300 s got subroutine starting at 400 Okay, so let's have a little look down here It's right at this moment that I realize lines 140 to 160 will never get executed and shouldn't be there at all Really, so when we return you'll see I've just deleted those like nothing ever happened Right, so if R is pressed. Oh, sorry, and if nothing is pressed this line 90 So so not nothing if something other than RP or S is pressed See none of these if statements will execute But something is that we'll break out of this loop because this this P string will no longer be nothing But none of these ifs will execute so we'll fall through here to the this print statement She prints goodbye and then colon and and the end instruction just returns us to the ready prompt and ends the program Gracefully, okay, so if the users pressed R would be sent to Line 200 which prints you chose rock I chose I've left the space after chosen the closing speech mark and this semicolon here afterwards that stops the line feeding carriage return automatically being being put in by the year by the computer so What happened is as it's as it's still part of the same print commands as it's still On the same line and there's no there's no colon What happened is that that semi kind of removes the carriage return line feed and it will then print the contents of the C string So it'll be we don't know and but it'll be one of these, you know, whatever Whatever value stored in CPU denotes which, you know, which Word gets stored into the C string. So it was a huge as rock I chose now if that C string so happens to be rock and it'll be then it will print the word draw If it so happens to be paper, then you lose the user loses because Paper beats rock scissors, then you win because rock beats scissors. Okay, and once that's done There's no return. So really this goes up to 500 could have been a go-to Either will work and I've chosen I've chosen just to use them use go sub in it in this instance So we'd go to go sub to 500 which would then print a blank line The message thinks of playing another blank line and then press y to play again and Then 520 is an identical loop to line 50. Well, just repeat It'll set up a queue string with nothing in it ask for an input to the queue string if it's blank Then it'll go which repeat the line over and over if y is pressed then The program just goes straight back to the start right to the very top clears the screen and gets on with the game again if anything otherwise is pressed then The message goodbye just like online 90 is displayed And the program ends so I'm going to show you now the game Playing I'm going to copy and paste this code into into vice so you'll see that going in So you'll the code being entered the game will run automatically except for this run and a carriage return at the bottom So as soon as it finishes pasting it automatically runs So here we can see the vise emulator I'm just pasting the code in as you saw as we was just going through and then ultimately runs Here we go. Welcome to rock paper scissors press after rock paper paper as for scissors any other key to quit I chose rock and the computer chose rock so it's a draw and I'm going to play it through a couple of times So here I'm going to choose paper and I win because the CPU chose rock Play game and go with scissors see what happens and a draw We both pick scissors that you can see very simple game here Let's see rock and the future is paper. So there's a lose So there we are and I pressed another key here. So we just ended The program and got back to the ready prompt. So thanks for watching my first video Please like and subscribe and leave a comment