:: -------------------------------- :: :: Welcome to the Pojcode User's :: :: Manual. :: :: -------------------------------- :: :: Pojcode Version: 1.0.0 :: :: -------------------------------- :: :: This manual provides a basic :: :: understanding of the Pojcode :: :: language. :: :: -------------------------------- :: :: NOTE: This course assumes that :: :: you have a simple understanding :: :: of general language syntax. :: :: -------------------------------- :: :: Syntax Note -------------- End all strings with a semi-colon (;). :: Printing ----------- Printing is the action of printing something to the screen. We can print words, sentences, numbers, variables, you name it! Example: - println("hello world"); In the above example, the code would output the phrase "hello world" to the screen. Use the statement "println" (standing for print line) followed by a pair quotations within a pair of parentheses. The phrase you wish to print will go inside of the quotations. :: Comments ----------- Comments are a simple concept. They are lines of text that does not get executed by the compiler. They are only for humans to read. These can be helpful, as they can be used to explain your code and help other programmers who are going to read your code understand it better. Example: - // this is a comment! The compiler doesn't notice me! To create a comment, use two forward slashes (//). Anything after the comment is not run by the compiler. NOTE: This is a single line comment. If you do something like this: - // I am a - comment You will get an error message. The comment cannot exceed one line. "command" is not a statement that can be run. To make a comment that spans multiple lines of code, just use more forward slashes. Example: - // I am a comment - // Look, another comment! - // Cool! :: Data Types ------------- There are four data types in Pojcode. - Integer (int) - String (str) - Boolean (bool) - Floating Point (float) - Valueless (void) The first data type is an integer. An integer contains whole numbers only. The second data type is a string. A string contains a letter character, or a word/sentence. The third data type is a boolean. A boolean can only contain two values; true or false. The fourth data type is floating. A floating point contains a decimal number. :: Variables ------------ A variable is used to contain a value that can be called upon later. When creating a variable, it is important to specify the data type of the variable that you are creating. Exmaple: - int my_num = 5; First, we specify the data type (integer). Then, we give the name of the variable (my_num). Then, we assign the value to the variable (5). The same syntax is used for bool and string variables. Example: - int my_num = 5; - str name = Simon; - bool awesome = true; - float my_float = 1.34; NOTE: You do not have to assign a variable a value immediately. You may want to get the user's input and assign it to a variable. In this case, use the following syntax: int my_num; Notice the syntax is the same except the variable value. This value can be added later manually, or by user input. :: Printing Variables --------------------- We can print phrases and numbers, but you may want to print a variable. Example: - int my_num = 3; - - println(%my_num%); To print a variable, type the variable name within a pair of percentage symbols with the parentheses. NOTE: When printing a variable by itself, exclude the quotation marks with the parentheses. Here is an example of printing a variable within a sentence. Notice the quotations are present because the variable is not the only thing being printed. - int my_num = 3; - - println("My favorite number is %my_num%!"); :: User Input ------------- Like I mentioned above, you can create a valueless variable and assign it the value of user input. This is very useful. Example: - str name; - - println("Hello! What is your name?"); - add[name]; In the above example, we create a variable called "name". We then ask for the users name and then assign it the the variable "name". To assign the user's input to a variable, type "add" followed by a pair of brackets. Place the variable name you want to assign to within the brackets. :: If Statements ---------------- Now, we can get user input, print statements, and make variables. But what if we want to execute code based on a condition? That's what If Statements are for! Example: - str name; - - println("Hello! What is your name?"); - add[name]; - - if %name% == "Simon": - println("That's my name, too!"); - - end:if In the above example, we ask for the users name and then see if it is equal to the name "Simon". If it is true, we print "That's my name, too!". Here is a pseudo-code break down: - if condition == true: - execute code - - end if statement The syntax is simple. Write the statement "if" followed by the condition and a colon. The code under it will be run if the statement is true. At the end of the if statement write "end:if". This ends the if statement. Note the double equal signs. We use two because it is checking for equality, not assinging a value. There is also "!=" which checks if something is not equal to something. There is also ">", "<", ">=", and "<=". Example: - if 5 != 2: - println("5 is not equal to 2."); - - end:if :: Else Statements ------------------ Okay, so we can make the computer execute code based on a condition. But what if that condition isn't met? That's where else statements come into play. When the code in the if statement are not equal to true, we can have it execute something else. Example: - int my_num; - - println("What's your favorite number?"); - add[my_num]; - - if %my_num% == 3: - println("That's my favorite number, too!"); - else: - println("Aw, that's not my favorite number!"); - - end:if The syntax is similar to if statements. To make an else statement, simply but the statement "else" under the if statement followed by a colon (:). Then, under the statement "else" write the code that you want to be run. Then, after, end the if statement with "end:if". :: System Commands ------------------ System commands can be very useful. Each operating system has a command line, which recieves commands and then does what it is told. Perhaps you want to call one of these commands within a Pojcode program. This is what system commands are uesful for. However, make sure you keep in mind what OS you want the program to run on. Commands differ from OS to OS. Example: - println("Let's ping google.com!"); - system["ping www.google.com"]; In the above example, we use the Windows command prompt command "ping". The syntax is simple: write "system" followed by a pair of brackets. Within those brackets, put the command you wish to execute within a pair of quotations. :: Functions ------------ Functions are an extremely helpful thing in Pojcode. You can create a function, which contains code. You can then call that function, and it will execute the code you wrote the function with. This can help with keeping code short. If you want to run code multiple times, you don't have to re-type it, you can just call the function. Example: - function get_name(): - - str name; - - println("What is your name?"); - add[name]; - - end:function In the above example, we created a function called "get_name". This function creates a variable called "name", get's the user's name, and then stores it in the variable "name". Perhaps we want to ask them for their name again. Instead of writing all the code over again, we simply call the function like so: - function get_name(); This line of code will execute the code within the get_name function. The syntax is pretty simple. To create the function, type the statement "function" followed by the name you wish to call the function. Add a pair of parentheses and a colon (:). The code under will be the code within the function. Be sure to add the statement "end:function" at the end once you finish writing the code you want in the function to prevent accidentally adding code you didn't want to add. :: Example Program ------------------ Below, I will show a program using most of the things we've gone over so far. ############################################################################# int health = 100; int coins = 100; str input; function print_info(): println("Your health is %health%. You have %coins% coins."); end:function println("Would you like to view your health and coins stats? (y/n)"); add[input]; if %input% == y: function print_info(); else: println("Okay!"); end:if ##############################################################################