Oh hello youtube and welcome to your fifth episode are in the GUI series and in this episode I’m going to cover how to use the key typed method so as you can see I have commented out what we did in the last tutorial and I have made the Method public void key typed which takes two variables the first being a character variable or char variable which we are going to label see and the second one is an integer variable which we are going to call I now basically this if we type the usual override Statement at override like so you can see that it is an override of the GUI screen method key typed now basically when this method is run the char variable will return the character of the key you’re pressing so if you press the esky this will return s those of you That don’t know what character is if we type for example chart x equals then you use quotation marks and put a single character in so this can be a number it can be a yeah it can be a number a letter things like that but if you try And put more than one in so say 11 it will error it can only be one character otherwise it will be a string so that’s what a character where you is then the integer variable will return the integer value of that key corresponding with java’s the way Java works with keys so If we want to check for example if the I variable so if we type if I is equal to keyboard dots so you use the keyboard class within java nothing not to do with minecraft then you can reference all the different keys Sookie underscore and then what the Actual key is called so for example if we put key be so what we’re going to do is if I equals equals keyboard key underscore be and another know is this method will only run once you press the key and I don’t believe it will it will Only run one swing press the key I don’t believe they’re actually am repeats the statement while you’re holding the key I will show you how to do that in a second but we’re just going to print the line see so basically if I press the B letter On the keyboard it will run this method and it will pass in the chart of B and the integer value of B which is also what this is so and then to check the is working it will print out the chart in which I have pressed so if we save that And load the book mode now just to let you know this workspace that I’m working at the moment is actually my pacman modification workspace I am working on that I’m working on the 1.3 version which is why I won’t go into that world because you will see stuff and you’ll See spoilers basically and a note for people wondering about that mind and I did code that actually like a year ago so the code for it is really old really bad I just fired release it see what people think I got a lot of attention which I’m really happy about but i have Since recoded it I’ve not finished yet but I’m getting there I’m quite close I’ve got the main game mechanics finished and basically there’s no bugs like getting stuck in corners it’s actually got ghost AI it’s got it reads map files from vary from text files I’m not going to say anything else I Don’t want to spoil all the things I’ve put in it but I’ve put a lot more work and effort into it it’s taking me a really long time and I may have just spawned in that world backs and or did I create a new order can’t remember I Don’t want to run against the things that that isn’t okay right so basically to open the GUI I just set it i believe so its return okay so you can see we have just a default screen because if you look over here it’s just drawing the default background nothing fancy and if You guys didn’t know this these are comments so basically if you type / / in front of online I don’t hail or error because when it went but if its app / / basically this rant line will not be read I was just a comment to keep track Of things and a slash star will open one that ends with a slash lasting over multiple lines yeah so we have this and basically if we press B you can see down here it prints out be however if however I’m holding be at the moment and it only Prints out once so it is only when you press the key it is not when you hold the key so if we want to do it when you hold the key basically what we want to do is call the method public void up update screen so this method will run With the tick and you can see overrides update screen in GUI screen so we have written that correctly or wrote that correctly locates you capital s and basically what we can do is we can check if the keyboard dot is Q down so that’s a method we use for this and then it Takes an integer variable which will be keyboard and then the key we want so if for example we do the okey so basically if the keyboard key is equal to 0 then we want to print out line and we’re just going to print out zero it’s basically now if we save that we Can launch this again and you’ll see that when we hold down oh it will actually keep repeating that method and for every game tick so if we see here free press B hold it down it does nothing to press oh so it’s 0 and hold it down it’ll keep repeating On the tick if you press it once it will probably do too because that’s kind of like holding down if you think about it so that is the key type thing you could also do if c is equal to the chil bong you have saved be so if we save that Basically that will do the same thing so if the sea variable chart is equal to the chart of B then it will print out that chart so just going to you I’ll move this across so now if we press B you can see it prints out that char Still what we could also do is actually remove the if statement so we can just check what key and pressing so WASD H okay answer some keys as yoon SI don’t work because they don’t return a child value value like am pressing enter now and space all the numbers work on the Letters work some of the symbols work I don’t know if you yep you can even shift press and so capital Q lowercase Q capital a lowercase day shift also returns space and I just got sticky keys and yeah so that is how to print out and Obviously you could also print out the I variable which will return the number variable for that and also to note that the Escape key is one and as you can see there i pressed escape and it is not exiting out the GUI now there are two Ways you get on this firstly yeah you can do if the eyebrow was equal to one or keyboard by u dot key on the score escape then basically what we can do is MC which is the minecraft variable in the GUI screen class display screen display Do i screen oops and then in here type null so basically what this means is if we press escape it will display the screen null which is just the game window so close all the GUI screens that are currently open even though you can only open one at a time but yeah the Other way you can do this is you can type super dots ki typed sharp sorry c comma i takes two variables basically this is calling the method that we are overriding in the superclass basically i’ll show you what runs in that but obviously if we open this thing again if You press escape now it will exit out the screen the reason it is doing that is because if we go look at this method you can see that it displays the screen being null and it also sets game of focus just basically that means it sets It to its default thing oh wow it doesn’t really matter you don’t need to know what that does um yeah and put if part 2 is equal to 1 which is the escape key party they’re basically got as what we had is I then yeah it will close the Current GUI screen so that is what is basically the whole coverage I’m going to do on the key type method there’s not much more you really need to know a lot of this series is just to teaching you the basics and then from that you can develop your skills are upon your basic Java knowledge and create some cool guis like for example my Pakman mod and for those of you interested in that mud again basically I am going to make hopefully in the near future i am going to make more games like space invaders Tetris and games like that hoping to get Some server stuff going with it as well and yeah it’s just it’s a really fun mod to experiment with and to create my own little twists on the game and I am basically the current version that i’m working on coding it like i would code a Real game in java it’s just I have to mess around a bit with the way the the game library the minecraft game library or game system was court i forgot the game engine that’s the word works so it takes a bit longer but yeah i’m basically coding a game so that’s why The delay is so long and also I’ve got to put it into like block form and for those who are interested I have actually got the UM I’ve got the if you have seen the previous version basically you couldn’t rotate the blocks the pac-man arcade block and in this version I fixed That I’ve made the block look and not a lot nicer it’s a lot less glitchy the gameplay is the main thing I focused on and basically it’s a much bigger map it looks a lot better it plays a lot better that there’s basically generic code so You can write I’m not gonna say much more cuz I want to spoil it because there’s some things I don’t want to tell you that are going to be really cool in my eyes that yeah basically i’ll make a review video on it when it’s out on my House play channel yeah and i might do a couple of teaser videos and stuff to show you what it’s looking like and yeah i will probably put updates out with that for like new blocks I say blocks like new tiles because a tile-based game that could basically my own twist on the game And yeah I hope you guys brilliant dry that might I hope you guys enjoyed this tutorial I hope that helps you with creating basic and hopefully progressing to advance guis now the next tutorial i am not sure what it will be and sorry also i forgot to mention this at the Beginning so for the long delay upon releasing this video basically i start college about a week ago and yeah it’s it’s been tiring and stuff I haven’t really got chance but today I only had like a half day at college so if I’d come home make a video and then get some Work done so basically and also I’ve been focusing a lot on making this pac-man one thing like I’ve spent at least 46 hours on it this week over the past over the spread out over the week which is a lot of time if you think why It’s not i’m not getting paid for it i’m not benefit from benefiting much from it is just fun really and well obviously I do get paid but not even worth it’s not even worth mentioning how much I get paid but yeah hopefully I can get that Out for 1.3 point to you soon and as you guys probably know 1.4 is coming out even from ridiculous he’s doing basically and which supposedly was going to have the mod API but from what I’ve heard I don’t think it is I’m not too sure about that don’t take my word for It but I hope it does because I know it’s going to be a lot of work to get mods ready for it and basically I don’t know whether to release for 1.3 point to which I hopefully will if I get it done in time or to wait for 1.4 which I’d Rather not do because basically once I’ve got the code done I’m just telling me a straight poor and a bit of bug fixing with the new the new systems and things and you api’s and again I am keeping it with just normal modloader i’m not using like for drinkers it’s really not necessary And basically I might use for eventually if the majority of mods do go over to forge wish they are starting to use FML but there’s no real for trucks that I need for this it’s basically just the GUI thing that’s happening I might use some item renders from Forge if I need To but for now I don’t so yeah sorry for dragging this tutorial out six the minutes most of it’s just been me talking yeah sorry Bella I think it’s going to take for a how to render but yeah thank for watching guys I hope you enjoyed the tutorial make sure you stay Tuned for the next one sorry for the late video and I’ll see you in the next one Video Information
This video, titled ‘Minecraft | Modding Tutorials | Gui Series | Ep.5 keyTyped’, was uploaded by HowNot2Code on 2012-09-14 15:49:43. It has garnered 1091 views and 11 likes. The duration of the video is 00:16:50 or 1010 seconds.
Welcome to a new series covering the coding behind various gui interfaces, in this episode I show you how to use the keyTyped method.
Paste bins :
mod_Gui :
GuiTest: