I really love the happy vibe your videos have, like a lot of tutorials (even paid ones) have a boring vibe to them which will also make you bored (probably because the teacher is bored or not excited at all)
I have some sort of nostalgy rewatching this as he made them in the past as well, when i was a complete beginner. I learned the syntax from him, but everything else was practice => error => fix the error
For any aspiring programmers wanting an extra dose of iterations, there's also the do-while loop: do { //repeating code here } while ([condition]); A critical difference is that a do-while loop checks the condition AFTER executing the repeating code rather than before. In practice, this means a do-while loop will always run at least once, whereas a while loop has the potential to not run at all.
Thanks! My code was having both "die" equal 0 to begin with, but the do loop fixed this. I also figured that simply setting them to different numbers would work, but this seems more efficient.
Hi, 2 years later. Thank you for posting this! I actually got stuck on the challenge, I noticed that since roll1 and roll2 were both initially 0, the while loop detected that roll1 != roll2, before it was able to randomly re-assign them from 0 to a number from 1-6. It took me a minute, but I realized that since the value of 0 was going to be overwritten by a randomly generated number anyways, I could just give roll1 a value of 0, and roll2 a value of 1. This worked, and I completed the challenge. Afterwards, I saw your comment, and I tested it out myself to see if it would've fixed the issue, and I set both roll values to 0. It worked! So I took note of the syntax in my study book and I'll use it the next time I want it to check conditions AFTER code. Much appreciated! I love youtube comments.
using System; namespace C__Projects { class Program { static void Main(string[] args) { //activate random numbers somehow Random numberGen = new Random(); int roll01 = 0; int roll02 = 1; int attempts = 0; Console.WriteLine("Press enter to roll the dice"); while(roll01 != roll02) { //Makes the program wait for you to press "enter" before rolling Console.ReadKey(); //Generates new numbers roll01 = numberGen.Next(1, 7); roll02 = numberGen.Next(1, 7); Console.WriteLine("Roll 1: " + roll01); Console.WriteLine("Roll 2: " + roll02); Console.WriteLine(); attempts++; } Console.WriteLine("It took you " + attempts + " attempts to roll two of a kind."); Console.ReadKey(); //Stops the program from instantly closing } } }
Im a very experienced coder and ive been using for loops for so long this entire time without actually knowing what the code meant so even for advanced people simple videos like this can still help, thanks brackeys!
@@reawy14 i++ is the incrementation, incrementation in code is when you add to something, for example if I increment x by 2 then that means im adding 2 to x i++ means you add 1 to i, its the same as doing i+=1 or i=i+1, i is your counter in a for loop so basically on each iteration you’re increasing/ incrementing the counter Starting with i=1 i++ i is now 2 i++ i is now 3 If you want to count backwards you can even do i- which is equivalent to i-=1 or i=i-1
I paused around 17:16, tried to do the exercise based on the information in the video, set up the other roll as a variable, was confused that the rolls ended before I could even press enter, then I changed the value of the second roll to a different number and it worked! As someone in the comments explained, the first value assigned to the roll variable is just a placeholder until the numberGen does the randomizing. It felt really good to piece that together through working code, the comments, and the solution on Brackeys website! May these tutorials be equally useful to everyone else who finds them in the future.
Yep, was stumped for a bit, looked through my code and realised that it was probably determining the placeholder 0s as doubles. I suppose another option could be to have a do while loop (learnt from another commenter) which checks it after running, rather than before.
I had the same thing happen to me just now. I'm glad that many users share their issues and solutions as you have. It's very helpful to us newbies, so I thank you. I'm upset to find that Brackeys has decided to stop making content, but he left so much information for us to absorb, and for that I'll be ever grateful.
I came into this course a complete beginner. I enjoy it when i get things right, but of course there are times when I get something wrong and I am not sure why. Luckily I have managed to find solutions to all my mistakes. I am excited to see how this course leads on to other more advanced courses, and how the contents of these courses integrate with developing games on Unity. The guy who teaches this course is an incredibly good instructor.
I just started learning C#, I taught myself VBA a few years ago and wanted to see if I could learn other languages. These videos are really well put together and easy to follow. For the exercise you gave at the end of the video, I created a lottery simulator. I had a user select 6 numbers from 1 to 49. If the user selected a number < 1, or > 49, or if they selected a number they had already picked I output a message telling the user it was invalid and to select again. Once the user selected 6 valid numbers, I rolled 6 dice (1-49) but I rerolled any dice that ended up with the same result as a previous dice roll. I then checked to see how many of the "dice rolls" matched the user's picks. If the user didn't match 6/6 I repeated the process. I figured out how to update a line of text without adding a new line of text, so on my line of text I could see the number of attempts go up to the millions and I even included a line of text to show my matches found. When I finally hit 6 matches I had the console print out the results from the dice roll to make sure dice rolls matched my picks. It was a fun project, I've coded something similar using VBA but VBA always crashed before I could actually see the results of my simulation. I'm amazed at how fast C# can run through the loops. Thank you so much for these videos!
I've been a professional GameDev and Software Developer for years now... I really hoped, starting up, for some content like this... It's just pretty heartwarming to see. Congrats on the amazing content.
This dude tough me a lot! He has the best free tutorials out there. With his help, I started my gaming company and made a game that downloaded more than 45M. So appreciated!!!
I managed the challenge on my own, but couldnt figure out why it was telling me it took 0 throws to roll two of a kind every time. Checked the forum, and it seems its doing that because if I set both variables to 0, its 2 of a kind from the start! So, I have to set one of the variables to a different number, then it works perfectly. I think Im getting the hang of this...
Console.WriteLine("Estimate a random number within the interval [1;25]"); int a=1; while (a>0) { int x; x = Convert.ToInt16(Console.ReadLine()); if ((x >= 1) && (x
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { Random numberGen = new Random(); int roll1 = 0; int roll2 = 0; int roll3 = 0; int attempts = 0; Console.WriteLine("Press enter to roll the dice."); while (roll1 != roll2 || roll1 != roll3 || roll1 == 0) { Console.ReadKey(); roll1 = numberGen.Next(1, 7); roll2 = numberGen.Next(1, 7); roll3 = numberGen.Next(1, 7); Console.WriteLine(" You rolled " + roll1 + ", " + roll2 + " and " + roll3 + "!"); attempts++; } Console.WriteLine("It took you " + attempts + " attempts to roll a triple... Fascinating."); string input = ""; while(input.ToLower() != "exit" && input.ToLower() != "quit") { Console.WriteLine("Please type 'exit' or 'quit' to exit the program."); input = Console.ReadLine(); } } } } I've done this. ChatGPT sure is helpful AF.
if you initialize the two rolls as zero in the beginning. The game would end instantly because the match. To fix this i had to set my second roll as random at the start. static void Main(string[] args) { Random numgerGen = new Random(); int roll = 0; int roll2 = numgerGen.Next(1,7); int attempts = 0; Console.WriteLine("Press a key to roll the dice."); while (roll != roll2){ Console.ReadKey(); roll = numgerGen.Next(1,7); roll2 = numgerGen.Next(1,7); Console.WriteLine(" Dice 1 You rolled: " + roll); Console.WriteLine(" Dice 2 You rolled: " + roll2); attempts ++; } Console.WriteLine("It took you "+ attempts+" attempts to match"); Console.ReadKey();
I almost did the same, but we were overthinking it. A new random isn't required. Just have roll = 0 and roll2 = 1. They're no longer the same so the loop starts, and since that initial value is just a placeholder, it doesn't affect anything that happens during the loop.
Hello Sir, I am from India , and i have made my first Game and i want Congratulate you for that because you are the one whose Videos and tutorials helped me in making my first game successfuly Thank You so Much for that.i will never miss a chance to meet you if will get one.
Don't mind me, just using this for notes. Random numGen = new Random(); int roll01 = 0; int roll02 = 1; int attempts = 0; Console.WriteLine("Press enter to roll dice."); while (roll01 != roll02) { Console.ReadKey(); roll01 = numGen.Next(1, 7); roll02 = numGen.Next(1, 7); Console.WriteLine("Roll 1: " + roll01); Console.WriteLine("Roll 2: " + roll02); Console.WriteLine(""); attempts++; } Console.WriteLine("It took you " + attempts + " attempts to roll two of a kind."); Console.ReadKey(); } } }
Iv done one of these tutorials plus the challenge every day for the last 4 days and I love doing it im sad you quit RU-vid and I know im really late to the channel but seriously really appreciate it
using system; namespace brackeys_comment { class learning { public string learning; } class program { static void Main(string[] args) { if (learning >= 1) { Console.WriteLine("keep watching brackeys!") Console.WriteLine("I think that is what you meant, may be wrong") Console.ReadKey(); } else { Console.WriteLine("damn, brackeys is nice"); Console.ReadLine(); } } } }
I added my own thing to the first part of this tutorial where instead you can only add how many numbers you wanted you can also add how much you wanna go up in: //Text for console Console.WriteLine("How many number/s you want: "); int count = Convert.ToInt32(Console.ReadLine()); //Reads first value for how many sets of numbers you want Console.WriteLine("How much you wanna go up in: "); int valup = Convert.ToInt32(Console.ReadLine()); //Reads second value for how much u wanna go up in numbers //Loop for (int i = 0; i < count; i++) //Adds the value that the user has put in for the amount of number/s { double result = Math.Pow(valup, i); //Goes up in the value that user puts in Console.WriteLine(result); //Console writes result } (Sorry for the bad explanation I just normally keep these to myself)
For all of the challenges I like to add some twist to force myself to think creatively and critically about what I'm doing. For this one, I had the program keep rolling dice until the two added to seven, which is the most common 2d6 roll.
@@GaithTalahmeh He also has a youtube Channel in which he teaches a lot! Check that out, his programming style is super clean. i dont wanna advertise another channel in brackeys channel so no link. The 1000$ offer is for people who wanna get really serious and can afford it, but it also offers a lot of things it's not like a 3 part youtube series and then you're done. I can't tell much about the 1000$ Course and what all is included, cause i also only know his youtube tutorials, but if i would become professional and could afford it, then i'd take that course cause his coding style is really nice.
@@mr.dingleberry4882 I'd guess that most developers aren't game developers and don't work solo, its much easier to make a living by working for a business instead of trying to create a business yourself.
Yeah, actually any expression you put in there evaluates to bool (6 == 6 evaluates to true and so on) That means you do not have to compare the bool, just use "while(isJamesEating)"
Dermakol already answered but I wanted to add that while loops are always using booleans. If you think about how you would describe the work your loop is doing in English you can see this: loop while james is eating, loop while your list is not empty, loop while the path is not clear. As you can see all of these are either true or false statements, aka Booleans. Hope that makes sense.
no need to say isJamesEating = true, just say isJamesEating. This would work, but make sure that the loop does something that will eventually make isJamesEating equal to false. If you don't, the loop will go on forever, which will freeze up your program and make it crash!
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; Console.Title = "While Loops"; //while loops they are also a type of loops just like for loop they also repeat code. //while loops syntax is: //while (here we write the condition) //{ //Here what the while loops has to execute if the condition is true or false. //} Random numberGen = new Random(); //Here we are making a number generator that will generate any number. //Here random is a class that creates random numbers numberGen is like a variable that stores //the random numbers and the new makes a new random number after another. //This how this Random numberGen = new Random(); works. //numberGen.Next(1, 7); //Here we are using numberGen as a variable and the next class is letting us choose the minimum and the maximum values that would be generated. double roll1 = 0; double roll2 = 1; double attempts = 0; Console.WriteLine("Press enter to roll the dice."); while(roll1 != roll2) { Console.ReadKey(); roll1 = numberGen.Next(1, 7); roll2 = numberGen.Next(1, 7); Console.WriteLine("You rolled a: " + roll1 + " on first dice."); Console.WriteLine("You rolled a: " + roll2 + " on second dice. "); attempts++; } Console.WriteLine("You took: " + attempts + " attempts to roll a same number."); //while (roll != 6) //{ // Console.ReadKey(); // //Here we are adding this so that whenever the user press enter the dice would roll till it's a six. // roll = numberGen.Next(1, 7); // //Here we are using numberGen as a variable and the next class is letting us choose the minimum and the maximum values that would be generated. // Console.WriteLine("You rolled a: " + roll); // //As roll is constantly changing so as soon as roll is equal to 6 it would exit the program. // attempts++; // //The attempts would be adding up as many times as it takes us to roll a six. //} //Console.WriteLine("It took you: " + attempts + " turns to roll a six."); ////Displaying the attempts the user took to roll a six. Console.ReadKey(); } } } (P.S: It took me thirty minutes to figure out that i had to change roll2 to 1 from 0. If I do not do that then they would be already equal.)
or you could use the following. using System; public class HelloWorld { public static void Main(string[] args) { Random NumberGen = new Random(); int Roll1=0; int Roll2=0; int Attempts=0; Console.WriteLine("Pres Enter to Roll:"); do { Console.ReadKey(); Roll1 = NumberGen.Next(1,7); Roll2 = NumberGen.Next(1,7); Console.WriteLine("Roll 1 : "+ Roll1); Console.WriteLine("Roll 2 : "+ Roll2); Attempts++; }while (Roll1 != Roll2); Console.WriteLine(" Total No of Attempts = "+ Attempts); Console.ReadKey(); } }
Trust me, Im also a beginner and for a few months I couldn fathom what the fuck was he ( or any other tutorial). However , something that worked for me ( and maybe It could or couldnt work for you) is that just copy step by step what he does, dont watch the whole video, pause the video, repeat exactly what they do, go back if you need to until youre absolutely sure that youre doing what they are doing. Then look at the code and " explain" to yourself what anything does, like youre trying to teach yourself what youre seing or trying to " guess" , then go back to the video or go forward until youre sure you understood ( at least on a basic basic level) what they are doing and why ( which is the important thing to catch when you explain to yourself) they are doing it.
Can we all agree that Brackeys is the best YT game dev to ever live. You inspired me to post a video in which I give my personal opinions with what are the best tips for beginner devs. If you have some spare time it would be really cool if you checked that out and critique my ideas!
Thank u brackeys. Really thank you. Im too poor to get into University to study stuff like this but u make me learn the basics and im very happy u did. I love you. Stay healthy and safe
I know you are doing C# here, but I wanted to pop in to see if you could do a revamp of your blender tutorial. I was trying to follow along, but it seems that blender has changed drastically since the airing of this video, and I was learning much easier through you than the official videos. If you could make one also showing how blender works with unity character rigging that would be the best!!!!
Please post more often, I know high quality vids like your take a lot of time (writing the video script, filming, editing, rendering and uploading!) and your schedule is per week. By the way, yet another awesome video team brackeys!