Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won



Expires: Never (Permanent)

Joshy last won the day on May 6

Joshy had the most liked content!

Community Reputation

2,900 Rainbow

About Joshy

  • Rank
    Do the right thing

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Please look for Staff threads regarding Shout box bans and Telemetry. Telemetry has several "proof of concepts." The only thing ever proven to past leadership is the concept of massive regret, and the likelihood of losing members before the cycle is repeated and additional bans are issued. The fact that this has repeated on Discord should be further evidence and proof of this concept. The ban in place was not made by one person alone (namely myself), and it's not based on one particular event such as a heated discussion with Jerry Hat Trick. I am considered extremely modest when issuing bans or punitive actions... they're only meant to be a remedy or learning experience, and this was a wonderful alternative compared to a well-deserved permanent ban.
  2. Arrays

    I covered last time how to run parts of your program conditionally, and how to loop through it repeatedly instead of retyping the same code over and over again. These next tools will help improve the legibility of your code and its elegance. We previously looked at conditions with two prominent outcomes: (1) It's true, or (2) it's false. What if you have many conditions or options to choose from? Something like below: You could approach this using the brute force method you are already familiar with by cascading many if-else statements together, and it would work. #include <stdio.h> int main() { int userSelection; printf("Choose a case [1-5]: "); scanf("%i", &userSelection); if(userSelection == 1) { printf("You chose 1."); } else if(userSelection == 2) { printf("You chose 2."); } else if(userSelection == 3) { printf("You chose 3."); } else if(userSelection == 4) { printf("You chose 4."); } else if(userSelection == 5) { printf("You chose 5."); } else { printf("Not a valid case!"); } return 0; } Wouldn't it be nice if there was an alternative way to do this without so many if-else... something a little more straightforward rather than checking through each condition? Something like below? Let us pretend the user only wanted to run case 1. Switch case is your solution, and the syntax is pretty easy. The code here will give you the same output as the earlier cascading if-else. Try running both to see for yourself. You begin each case with "case" followed by the integer (ie. 0, 1, 2... 99) or a character (ie. 'a', 'b'... 'y', 'Y'), and you end each section with "break." If you don't use "break", then it'll run both that particular case and the one(s) below it until it hits a "break" or the end. #include <stdio.h> int main() { int userSelection; printf("Choose a case [1-5]: "); scanf("%i", &userSelection); // userSelection can only be an integer or a single character switch(userSelection) { case 1: printf("You chose 1."); break; case 2: printf("You chose 2."); break; case 3: printf("You chose 3."); break; case 4: printf("You chose 4."); break; case 5: printf("You chose 5."); break; default: printf("Not a valid case!"); } return 0; } This could even ease up the pain of having multiple conditions running the same code. Earlier: You may have noticed that the user selection was case-sensitive. If the user selected lowercase 'y' and you had typed in capital 'Y' into your code for the condition, then it would have not ran that code. You would have to cascade two conditional statements using what I have given you before. printf("Yes or no? [y/n]: "); scanf("%c", &userSelection); if(userSelection == 'y') { printf("The user selected yes."); } else if(userSelection == 'Y') { printf("The user selected yes."); } else { printf("The user selected no."); } // I'm purposefully neglecting to use || (OR) to make a point here This could be made equivalently by using switch case: printf("Yes or no? [y/n]: "); scanf("%c", &userSelection); switch(userSelection) { case 'y': case 'Y': printf("The user selected yes."); break; default: printf("The user selected no."); } Lets run that earlier example of adding numbers using a switch case instead of if-else. You can copy and paste this, and it shouldn't surprise you that it runs exactly the same. #include <stdio.h> int main() { // Declaration and initial values int count = 0, numX = 0, numY = 0; char userSelection; printf("Would you like to add numbers? [y/n]: "); scanf("%c", &userSelection); switch(userSelection) { case 'y': case 'Y': printf("How many numbers would you like to add?: "); scanf("%i", &count); for(int i = 0; i < count; i++) { // User interface printf("Input number to add: "); scanf("%i", &numX); numY = numY + numX; } // Output printf("The sum is: %i", numY); break; case 'n': case 'N': printf("Exiting program."); break; default: printf("You did not select 'y' or 'n'!"); printf("\nExiting program."); } return 0; } The variables you have been working on have only been able to hold one item. It's time for you to expand into the next dimension. It's time for... 1-D? That's it? The strategies and concepts here will work the same way for multi-dimensional sets, but you can still achieve a lot with 1-D compared to working with a single item. Have you ever used Excel or some spreadsheet? Arrays are exactly the same thing. You can hold a set of numbers or characters in a single variable we call an array, and each item or element in the array has a corresponding "index." The above picture is literally from open office (the open source version of Microsoft office). As you can see in the first array I have the second item '2' selected, and the array has a size of 5 items (1, 2, 3, 4, and 5). I made another array with 5 items in it too (3, 7, 8, 10, and 11). One of the more tricky things with arrays is how the computer interprets it. The computer wants to start things at zero (0) instead of one (1), and so an array of 5 items will run through index 0, 1, 2, 3, and 4. The equivalent second item in Array1 would therefore be in index '1' (because '1' is the second index coming after '0').: // The declaration is the name of the array, followed by its [size], and the elements inside of it {element1, element2... } int Array1[5] = {1, 2, 3, 4, 5}; // This would print the second element "2". // The first element in this array is Array1[0] contains a "1"... // ... and the thid element in this array is Array1[2] contains a "3". printf("%i", Array1[1]); Lets try another array just to get a feel for it. #include <stdio.h> int main() { char name[6] = {'J', 'o', 's', 'h', 'y'}; for(int i=0; i<6; i++) { printf("%c", name[i]); } return 0; } Now that we are seeing you can use switch instead of if-else for a large selection, and that you can loop through your arrays instead of using multiple variables, lets explore some other ways to repeat tasks without having to rewrite code multiple times. Learning about functions is SUPER helpful for repeating tasks. This is probably an area of focus if you're interested in developing, and so I suggest paying special attention here and running through the examples if you can. Without functions: The concept of your code will look a lot like below: Implementing functions in your code will have you write that operation only one time although you can use it many times throughout your code As you can see: This is much more elegant and you wont have to rewrite your code over and over again. One could argue, that you could use a loop instead, but imagine if your operation involved some type of loop or you wanted to perform this operation in several loops. This would become a mess. Sometimes you use functions not just to prevent repeating code, but to also make your code legible or easy to understand. Here's an example of a code using a mathematical operation: #include <stdio.h> int main() { int a = 2, b = 3, c = 0; int power(int base, int exponent); // you have to declare your functions too c = power(a, b); printf("%i to the power of %i = %i", a, b, c); return 0; } // <-- End of main program // type name(arguments) <-- Beginning of your function called "power" int power(int base, int exponent) { // base^exponent int output = 1; for(int i=0; i<exponent; i++) { output = output*base; } // this is the output when you call it in the main function return output; } And another example where multiple functions are involved. We'll pretend I want to round numbers to the nearest 10th using another function. #include <stdio.h> int main() { int a = 2, b = 2, c = 0, d = 0; int power(int base, int exponent), round10(int inputNumber); // you have to declare your functions too! c = power(a, b); printf("%i to the power of %i = %i", a, b, c); // Now we will round this number to the nearest 10 d = round10(c); printf("\nRounding to nearest 10th: %i -> %i", c, d); return 0; } // type name(arguments) int power(int base, int exponent) { // base^exponent int output = 1; for(int i=0; i<exponent; i++) { output = output*base; } // this is the output when you call it in the main function return output; } // end of power // beginning of another function called "round10" int round10(int number) { // This function rounds the input number to the nearest multiple of 10 int R = 0, output = 0; // Modulo "%" tells you the "remainder" (R) after something is divided // For example 7%5 is 2. R = number%10; if(R < 5) { // Subtract the remainder rounding DOWN output = number - R; } else { // Add whatever you need to get to then next 10th output = number + (10-R); } return output; } Maybe the function above seems harder than just directly typing in the equation. Lets take a look at some data array examples and use a function that helps us finds the maximum value inside of the array. Using a function makes it easy for me to call "max(arguments)" and so my code is easy to understand, and I don't have to use so many loops to get the job done. #include <stdio.h> int main() { int someArray[5] = {0, 1, 12, 3, 18}, dataSet[7] = {1, 101, 5, 1, 1, 0, 12}, randomNumbers[3] = {3, 2, 1}; int max(int arg[], int size); printf("%i", max(someArray, 5)); printf("\t%i", max(dataSet, 7)); printf("\t%i", max(randomNumbers, 3)); return 0; } int max(int array[], int sizeArray) { // Find maximum value in array[] of a given size // Arbitrarily low value int maxValue = 0; for(int i=0;i<sizeArray; i++) { if(array[i] > maxValue) { // If new value is bigger than old, then set new value to maxValue maxValue = array[i]; } } // This is the output of our function return maxValue; } This stuff was pretty heavy, wasn't it? You could still copy and paste a lot of the code above just to get a feel for it, and to again massage the code or use it as a framework for something else of interest. Here's what I recommend trying: Take that summing example and make a switch that allows the user to select an operation (adding, subtracting, multiply, divide...), and make each option a function such that you have something like this: int add(int X, int Y), multiply; // declare your functions int userSelection; printf("1. Add\n"); printf("2. Multiply\n"); //.. printf("Choose an operation: "); scanf("%i", &userSelection) switch(userSelection) { case 1: add(X, Y); break; case 2: multiply(); break; //.. } return 9001; } // <-- end main int add(int X, int Y) { int outputValue; return X + Y; } int multiply( //.. Try a multi-dimensional array. This is the strategy: // name[row][column] = {elements} someArray[][] = {item1, item2, item3}, // a comma before next row {item4, item5, item6}; Conceptually: Interestingly: You could continue using this style of thinking into 3-D and beyond (4-D, 5-D, ... , 100-D). Try a function that returns a character or a void (one without a return) char someFunction(int argument) { char output; switch(argument) { case 1: output = 'a'; break; //.. } return output; } // void function void otherFunction(char argument2) { //.. } Make a sorting function ie. takes in an array and rearranges all the items in ascending or descending order (I recommend nested loops)
  3. This is a follow up for those of you who are more advanced than my first tutorial: We will cover conditions and looping here. I will post a lot such that you can copy and try to massage the code again, and so don't worry if this is a little bit confusing. Just try running and see what happens. A condition is exactly as it sounds: A part of the program will only run if it satisfies a condition. Lets do an example: If you give me $5, then I will do your homework. If you don't give me $5, then I wont do your homework. The programming equivalent to this is the following: #include <stdio.h> int main() { // Declaration char userSelection; // Here is where the user can choose whether or not to give $5 printf("Give Joshy $5 to do your homework? [y/n]: "); scanf("%c", &userSelection); if(userSelection == 'y') { // The user selected 'y' for yes, and so this will run printf("Joshy will do your homework."); } else { // This will run if the user types in anything other than 'y' printf("Joshy will NOT do your homework."); } return 0; } You should be noticing in the above the conditional statement is inside of the if() piece. if(condition) { // Runs if the condition is true } else { // Runs if the condition is not true } There are many other types of "logical" conditions such as the following: != is NOT EQUAL. == EQUAL TO > Greater than >= Greater than or equal to < Less than <= Less than or equal to && AND (both conditions must be true) || OR (one of the conditions must be true) This is just logic, which I am assuming you would know. Here are some examples: // AND example if(someCondition == 1 && anotherCondition == 1) { //.. both conditions must be true to run } // OR example if(someCondition == 1 || anotherCondition == 0) { //.. only one of these conditions needs to be true to run } // Is 5 "less than or equal to 10"? int test = 5; if(test <= 10) { // This one WILL run because 5 <= 10 printf("Yes."); } else { // This one will NOT run printf("No."); } Some common PITFALLS to take note of: It is common for beginners to accidentally use a single equal sign "=" instead of two of them "==", which will not work for checking conditions. A single equal sign "=" will literally set the variable to equal that value. DO NOT USE THE FOLLOWING: if(test = 5) //<-- This is a MISTAKE! Used "=" instead of "==". { //.. } It is a mistake to put a semicolon at the end of a condition or loop. DO NOT USE THE FOLLOWING: if(condition); // <-- this is a MISTAKE! You do not want a semicolon here { // Nothing in here will run... ever... } You CAN use the condition as a bypass without the else statement if you would like. #include <stdio.h> int main() { char bypass; printf("Would you like to skip the next part of this program? [y/n]: "); scanf("%c", &bypass); // if the bypass does not equal to 'y' (yes), then run this code if(bypass != 'y') { printf("You did not skip this part of the program.\n"); } printf("This always runs unconditionally."); return 0; } You might use this in parts of development such as checking if someone has a certain amount of HP, if the player is on a certain team, if the player is in a group like Admin or VIP, or if the targeted player is even online. One of the benefits to programming is taking care of repetitive tasks really quickly. A way for us to take advantage of this is through using loops. The two prominent loops are "for" and "while" loops. For loops run for a set number of times, and its format is along the lines of: int firstNumber = 0, lastNumber = 10; // Counting up from zero to 9. for(int i=firstNumber; i<lastNumber; i++) { // Example of a repetive task printf("%i\n", i); } // This can be done equivalently with for(int i=0; i<10; i++){.. // The above loop will only run from 0 to 9, which is 10 times or 10 "iterations" While loops run until its condition is broken. ageJoshy = 1; // my age will be the condition while(ageJoshy < 18) { printf("Joshy is just a child.\n"); // This increments my age ageJoshy = ageJoshy + 1; // You could also use ageJoshy++; } printf("Joshy is no longer a child."); Some people use "do while" loops, which only guarantees the while loop will run the first time (regardless of the condition) and runs like a regular while loop afterwards; however: I do not plan to confuse you further by talking more about it, and it is not used often- just know that it's available if there is ever a time you may need something like that. You can read about it if you're interested (reference). Another confusing but commonly used strategy is "nested loops." It's much like the movie inception except you've got a loop within a loop, and sometimes (multiple) loops within a loop. I recommend running this one below just to see what it does. #include <stdio.h> int main() { for(int row = 0; row<10; row++) { // This will run through all the columns before going to the next row for(int column = 0; column<10; column++) { printf("Row: %i, Column: %i\n", row, column); // You could make it count by replacing the above with the following line printf("%i\n", column + 10*row); } } return 0; } // This will print out elements of a 10 by 10 array or "matrix." A nested loop conceptually: Let us see what we can make of all this using our earlier program from the first thread. The original program only allowed the user to enter a set amount of numbers to add. Lets make it such that the user can choose how many numbers to add! We'll also give the user an option to exit out of the program if they did not want to add numbers. You can copy and paste this just to get a feel for it. #include <stdio.h> int main() { // Declaration and initial values int count = 0, numX = 0, numY = 0; char userSelection; printf("Would you like to add numbers? [y/n]: "); scanf("%c", &userSelection); if (userSelection == 'y') { printf("How many numbers would you like to add?: "); scanf("%i", &count); for(int i = 0; i < count; i++) { // User interface printf("Input number to add: "); scanf("%i", &numX); numY = numY + numX; } // Output printf("The sum is: %i", numY); } else { printf("Exiting program."); } return 0; } Here's what I recommend trying next: Give the user the option to try other operations such as multiplication ie. printf("1. Add"); printf("\n2. Subtract"); printf("\n3. Multiply"); printf("\nSelect an operation: "); scanf("%i", &userSelection); if(userSelection == 1) { // The user picked option 1. Add numZ = numX + numY; } if(userSelection == 2) { // The user picked option 2. Subtract numZ = numX - numY; } //.. Try having that "nested for loop" print even numbers only, or make it count down instead of up. Try a "nested while loop" counter. If you get stuck in a run time error, then an easy way to exit is to use "CTRL+C" just like the copy shortcut. Make a guessing game where the user wins if they guess the correct number. Try copying any of the code above using for loops and remake an equivalent code using while loops instead Example for loop version: for(int i=0; i<10; i++) { printf("My name is Joshy.\n"); } Example while loop version: //Equivalent version using while loop below int i = 0; while(i < 10) { printf("My name is still Joshy.\n"); i++; } Use different conditions Example condition: if(joshyIsCool == 1) { printf("Joshy is cool."); } Its equivalent condition: if(joshyIsCool != 0) { printf("Joshy is cool."); } Follow up in the next thread to learn more:
  4. Badges

    Great suggestion ( ͡° ͜ʖ ͡°) I've been trying to recover my old programming guides (the first set of guides I did not stage in a word document, and so I do not have it saved elsewhere). I was very skeptical when I saw the updates and some unusual movement I often preach against, but some of these are good updates- badges have been needing some attention for a long while. I still see a lot of things I don't like, but overall it's okay. Keep up the good work.
  5. My friend, Ron, recently passed away from this, but I knew him better in real life and less about his gaming life. Some advice I received from my professor when a close friend passed away a while ago was to live two lives: One for ourselves, and one in continuation and honour of our loved ones. I'm beginning to many lives, but I'll do the best that I can. I'm sorry for your loss.
  6. Saint Patrick's day I wish I noticed that cool Sharkpedo thing!
  7. Any chance on recovering these guides? I do regularly reference these guides to others outside of GFL.
  8. I found another: Conditions and Loops in programming by Joshy https://gflclan.com/forums/topic/22411-conditions-and-loops/ I think the name of the other one I wrote in programming is Switches, Arrays, and Functions, but I haven't been able to find its link yet.
  9. You could become a programmer starting today! I was planning to post this later with better quality, but it looks like this might be helpful now and I can fix it up later. I hope this may encourage some of you to take a stab at it. I'm going to do a lot of hand-waving, and so that you can dig in and start. For the sake of my own time: I'm going to assume you're using Windows although I can update this later to include other OS. Sorry. We'll start with downloading Quincy. It's a very straightforward and small download. My goal at this moment is to have you become familiar with Quincy first so that you may use it for small projects. Let us begin with your first program. No: Not "Hello World." You can find this anywhere else if you really want to (reference). We're going to do a little bit of arithmetic because I believe you will be using this more often if you develop for GFL. Choose C++ Source File. This is just to keep things easy although you'll notice my personal style will use mostly C as you learn more. You'll acquire your own style in the future too. Now: You should see a blank text document, which you can type into. This is spoon feeding, but copy and paste the following into your text file: #include <stdio.h> int main() { // Declaration and initial values int numX = 0, numY = 0, numZ = 0; // User interface printf("Input first number to add: "); scanf("%i", &numX); printf("Input second number to add: "); scanf("%i", &numY); // Operation numZ = numX + numY; // Output printf("%i + %i = %i", numX, numY, numZ); return 0; } It should look like this. Save it as a CPP file. Now: You have your first program, which I wrote I just want you guys to get a feel for it though. Let us run it and see what happens. Click on Debug and then Run. You can also use F9 as a shortcut. Two windows will open upon clicking Yes: A Build window and your program. This is where you'll be able to experience your program as a user, and to debug it should that become necessary. That was easy! I get that you didn't do anything here besides downloading a file and copying my basic program. No problem! Here's what you can do next: Edit my code so that you can perform other mathematical operations such as multiplication or division (using star * or slash /), or make it such that you can add three or four numbers instead of two. Here are some hints: If you need more variables, then you will have to declare them at the beginning of the program. The declarations I used were the following: int numX = 0, numY = 0, numZ = 0; You don't have to "initialize" the values to zero like I did. You can initialize them to other numbers or leave it open although initializing is considered good practice. I used printf() to display something to the user. printf("No hello for you."); You can also have it show variables such as numZ like I did. printf("My variable, numZ, equals to the following: %i", numZ); What happens if I add 2.5 and 1.2? Will my program still work? My variables are integers meaning they are numbers without those decimal points. You can try other variable types such as a float. You can read more about other variable types here if you would like although I recommend sticking with the basics for now. // Do not forget to declare it! float numZ = 2.5; int dog = 3; printf("numZ wants to be a float like this one %f", numZ); printf("\nCan dog be an integeter? I suppose so. dog = %i", dog); // That \n makes it on a "new" or "next" line. This is great for formatting! Scanf() looks suspiciously like a way for the user to type in a value. Don't forget to declare at the beginning if you do use it. float userInput; scanf("%f", &userInput); Try a few small basic programs and post your results here! If you make an error, then the Builder pop-up window will give you hints as to where the problem is. The most common mistake for new programmers is leaving out the semicolon (;) at the end of the line. Try running the above program with a missing semicolon in one of the lines and see what the error looks like. Make changes in stages instead of doing many changes at once, and so you know exactly what is causing the problem. Good luck! Want to learn more? You can learn follow up with conditions and loops in my next thread:
  10. A Quick Start in programming section by Joshy. https://gflclan.com/forums/topic/22401-a-quick-start/ There were two others in that section, but I cannot remember their names because I didn't reference them as often; however: I put links to their counterparts in each guide. Please move them to the greater forums.
  11. They just fade away. It's long overdue and I'm outdated here; it's just not my thing anymore. Thanks for letting me share and being a part of my adventures. I'm not going to ask for stupid things like disabling my account or claiming I'll never return * lurking mode activated *, but there's no doubt my activity has dimmed substantially, and correspondence or visits to the forums are often frustrating. I figured it was a worth a goodbye thread.
  12. I cannot even keep track of how many times we have removed the equivalent Council position, and it has failed every time with the equivalent Directors burning out only a few months down the road. What conditions have changed that suggest that it might work this time? I am very doubtful, and the approach was distasteful and haste. Burned out Directors do not do a good job focusing on the servers; you are staging yourself for another failure. We keep picking people for these staff positions who - as I described more modestly in the promotion announcement - can whisper into your ears for a week or two and write an if statement in python. You've got to stop picking these people, and you've got to bridge the gap between your low tiered teams and the Director position. What's going to happen is the same as always: You will not be able to find good candidates to fill in these shoes and you will be super dependent on your wonderful Director team... You already have a hard enough time getting Division Leaders, and they are likely your "next" Directors should that even stay around. BAD NEWS: These are real people. They have lives. They have things to do, and they will get tired of working with little kids who cannot handle bad news from time to time, and they will step down. They wont want to make difficult decisions, and that's what you guys always go with (the easy, quick, and bad decision). You will fail and chase your tails every time wondering why you are disappointed again. Consolidation is a good idea and I definitely support it, but you're cutting in the wrong places again. Take a look at this, which I got from this thread. I certainly had a good laugh when I saw Council Reboot back in 2016, and I've seen many other flavours of Council 2.0s and Community Advisors. You don't need to be rocket scientists to make a good guess on our "changed direction." Have minutes of fun browsing through that web-archive if you're curious to see what's next... it has all happened before, it has happened so many times.
  • Create New...