All right welcome back bug so let’s uh do the detection for Monsters so go in here and we’re going to go edit the troll and so each time we’re doing this Loop what we’re going to do is we’re going to be okay if there’s a monster I want you To attack but only if there’s a monster so we’re going to do something similar to over here and it’s going to be a while loop in that for Loop so while Turtle dot do attack in the front equals true if it’s true then continue to attack if we just Go hey if there’s something there attack it then you know if it comes back and we attack it then nothing’s going to happen because it only do it once but if we attack and it comes back in enough time then we can keep attacking so do turtle do attack then end So while it’s moving first we check if there’s something in front of it if there is while that’s true we’re going to move we’re going to attack it and then move forward and then and then move forward yeah okay and then let’s see it’s only going To be done we’re only going to check if there’s something in front of us uh to attack so then we move forward and then if we go back into the loop and if there’s something in front of us again we’re going to keep we’re going to attack so it’s going to keep Repeating that pattern okay I think that’s all we need for an attack uh control save control exit let’s add some monsters here so uh zombies would be the easiest so let’s get some zombies let’s close the gate here and let’s get out of peaceful and easy all right There’s something wrong okay let’s go back to the code troll so we do our Loop first we check if there’s something in front of us if that’s true then we attack let’s see let’s add a statement print detected then print okay contrl save contrl xit and let’s Patrol what’s going on let’s see Refuel yeah we have fuel but why are we not moving forward and Patrol refuel okay and and edit so what is getting us stuck here so it never goes into this otherwise they would have this would have been printed so if fuel Target level oh we’re already So because we didn’t change the code here this um whenever it checks the fuel level it’s 788 something right now so it’ll never start so we need to check this and we’re going to put it at 7,800 so it’ll goes go at least five times around before it stops okay so contrl Save control exit and then Patrol but first we want to add monsters okay okay so it’ll attack and go forward okay it is attacking monsters good good while it’s going but it might only might work better at night okay it’s not attacking it should detecting it’s never going into that Loop of detecting Monsters and it should detect something right there so let’s go to Peaceful real quick where’d you go okay so let’s go back to options not peaceful and we’re going to put a gate right here and we’re going to put a monster right there but first let’s get out okay out Of there and we’re going to be okay uh Lua do we detect anything Turtle do if turtle. attack and we can leave it just like that because if it’s true it will be true then print true tected and it did not detect anything okay so let’s do turtle. Attack there’s nothing there but oh we don’t have a weapon so it can’t do anything anything there okay that’s the issue that’s the big thing we forgot we need a weapon my bad guys I mean my bad bug all right so let’s put it here we can’t detect anything and we Also can’t even do anything okay now let’s run that code before so it detected something all right so now let’s get rid of that and put more monsters then we’re going to go to our code exit out of here of Lua clear that edit Patrol and then it detects Something okay it should be good oh make sure you change this cuz we only want to go around like four times so seven and then save and then exit and then Patrol detected and attack it detected and attack it detected and attack and detected and attack okay going okay so the code is Still taking into account our Patrol so it’s not losing that so we’re still moving like we need to and we’re attacking correctly that’s oh no the monsters is all way behind all right uh we could always REM this by putting another robot behind it so like let’s see one right here but no Okay nothing detect it of course all right let’s see if we put a robot here it’ll do the same thing as this one so let’s our Patrol we’re going to put one right here and we’re going to put one right here and then we have weapons okay and Let’s put some monsters right here just to test things out a little further okay and then edit Patrol and let’s see we’re going to go around four times each one now we’re going to go around more than once okay more than four times contrl save contrl Exit and then and we’re going to not run that one we’re going to put it over here that is not what we want it h why okay all right let’s put a robot right here let’s put some eggs options okay and we’re going to run our code so Patrol all right and let’s run this one okay and it’s going to keep going and they’re going to be right behind each other so what happened okay keep going oh okay so even if our robot kind of messes up it’ll go back into the patrolling but it’s only partially Working because of our uh gate right here which isn’t a bad thing but we might need to take that into account with later code okay so we’re going to stop right here we got a patrolling robot and we can attack oh no no no I forgot I still have to teach you guys About how to refuel while we’re going so all right it stopped there let’s go in here and Okay so we’re going to do an if statement if fuel see we’re going to check the fuel right here so uh fuel equals turtle. get fuel if fuel less than One then I want to refuel real quick before I run out of power uh we’re going to select the energy source so select so one this one and we’re going to put our fuel in here and actually not less than one we’ll put like less than 100 okay Uh then select that and then turtle. refuel it’ll burn that up and then it’ll keep going and it’ll check again and again all right and then that should be good all right we’re all set okay uh save exit until next time bug and hopefully this helps if you have any questions just Post a comment uh and if you come up with any ideas you know I’m more than happy to uh show you or demonstrate how something might work all right till next time Video Information
This video, titled ‘Coding with Minecraft Forge Patrol 2’, was uploaded by Corg on 2024-01-05 22:00:03. It has garnered 68 views and 0 likes. The duration of the video is 00:14:13 or 853 seconds.
How to go on patrol and attack monster on your way.