As mentioned before, I am a total n00b when writing code. My experience comes from visual scripting, using programs like UDK, as well as editor extensions like Playmaker and Ork Framework. However, learning the terms on the extensions, as well as the experience I had writing in Actionscript 2.0 (AS2.0 henceforth) allows me to at least understand coding enough to manipulate things to my liking. I am using this information to learn to code and using this series as a way to teach others, as well as myself.
I am becoming more adept at coding thanks to these posts. I am thinking about Redoing “Bipeds Journey” AGAIN but switching the Coding from AS 2.0 to C#. I will be Proposing a game type to a group and If successful, this can be the cornerstone for the coding. as always, I will have someone with more experience check the code for efficiency.
This post will not be about that code, however. This post will be more about definitions and the structure itself.
Many of the things that I discuss here are on previous discussions but I wanted to put the information together for a one-stop shop before I add more information. Keep in mind that I am learning C# within Unity, so some of the libraries that exist will have differences.
As I mentioned before, in coding, words don’t have meaning until you give it meaning.
Library: A code library can be compared to to an actual library. Just like a library is a building full of books organized by genre, a code library is a package full or code organized by classes. the code/class can be adopted into the code you are currently writing using the word “using.” the Unity Engine has its own “UnityEngine” library and Microsoft has the “XNA” Library
this can be read as “I am using the information provided in the code [CodeName]”
“using” can be used on all sorts of code, adopting the information of the code name that you add:
using Door_Logic; (a code i created. see the discussion here)
Class Name: Within unity, the name of the Class is also the name of the Code. When Creating a C# code in Unity, for example ExampleCode would create a file called ExampleCode.cs and within the file would have “public class ExampleCode : Monodevelop”
public / private: adding public or private before the code changes the ability to edit the parameters within the code. for example, if i had a public variable named thisVariable and I entered “thisVariable == 1” – In the component window for the code you will see a paramater called thisVariable and a text field with “1” in it. this component can be changed within the window. if the previous variable was private instead, then the component would not appear by default. (however you can have private variables appear in unity’s component window in other ways, more on that by request)
function: a group of code that can be called upon when the function name is mentioned. it is normally written
[public or private][function type] FunctionName ([variabletype],[variablename])
a function type that is definitely used is void (explained below), but there are others.
after the function name is the “arguement” within the parenthesis you can add values and give the value a name. That value can be manipulated throughout the code later, more is explained here.
void: This is a type of function, one that is used frequently. The function is one that does not return a value (thank you for the correction, Aaron)
here is a void function:
public void ThisFunction()
thisStatement = True;
followed by coding that will use that function:
if (thisVariable >=5)
basically , this would be read: “If the variable is greater than or equal to 5, run the function called ‘ThisFunction.'” the function will then change change the variable “thisStatemtent” to “true.”
if / then / else: If-Then statement was one of the first topics i discussed. for simplicity’s sale, If-then can be read: “If one thing happens, then something will happen in effect.” else adds more information that can be used if the original “if” is untrue. so..
If one thing happens, then something will happen, but if something else happens instead, a different effect will occur. There is an if then statement above, however to expand on that:
if (thisVariable >=5)
else if (thisVariable > 5)
thisStatement = false;
The biggest thing that one should know about coding is that All Characters Matter (no joke). One missing character will completely break the code. I may have mentioned this before, but my code for Biped’s Journey completely broke when i missed a semicolon at the end of the coding. Luckily programs like visual studio lets you know where to expect errors if you miss anything.
As mentioned before, I am not an expert and I can be wrong. However I believe that in teaching others, I also teach myself. Hopefully you learn something, and if you know more than I do, leave examples in the comments. i would be happy to discuss more on this.