MS Coding Camp(working title)

This forum is for discussion about anything else.
User avatar
Cheetory6
Cheetory6
MS Painter
User avatar
User avatar
Cheetory6
MS Painter
MS Painter
Posts: 7403
Joined: September 21, 2014

Post Post #9 (isolation #0) » Thu Nov 03, 2016 11:02 am

Post by Cheetory6 »

I would be interested in sitting in on the design discussion at the very least if not participating in helping to make it.
User avatar
Cheetory6
Cheetory6
MS Painter
User avatar
User avatar
Cheetory6
MS Painter
MS Painter
Posts: 7403
Joined: September 21, 2014

Post Post #25 (isolation #1) » Sat Nov 05, 2016 2:26 pm

Post by Cheetory6 »

I think we're going Unity.
User avatar
Cheetory6
Cheetory6
MS Painter
User avatar
User avatar
Cheetory6
MS Painter
MS Painter
Posts: 7403
Joined: September 21, 2014

Post Post #34 (isolation #2) » Thu Nov 10, 2016 2:03 pm

Post by Cheetory6 »

MS Project for Unity Development: Lesson 1
Spoiler: Description of Unity (shamelessly plagiarized from wikipedia)
Unity is a cross-platform game engine developed by Unity Technologies and used to develop video games for PC, consoles, mobile devices and websites.
First announced only for OS X, at Apple's Worldwide Developers Conference in 2005, it has since been extended to target 21 platforms.

With an emphasis on portability, the engine targets the following APIs: Direct3D on Windows and Xbox 360; OpenGL on Mac, Linux, and Windows; OpenGL ES on Android and iOS; and proprietary APIs on video game consoles.
Unity allows specification of texture compression and resolution settings for each platform that the game engine supports, and provides support for bump mapping, reflection mapping,
parallax mapping, screen space ambient occlusion (SSAO), dynamic shadows using shadow maps, render-to-texture and full-screen post-processing effects.
Unity's graphics engine's platform diversity can provide a shader with multiple variants and a declarative fallback specification, allowing Unity to detect the best variant for the current video hardware and,
if none are compatible, to fall back to an alternative shader that may sacrifice features for performance.

Unity is notable for its ability to target games to multiple platforms. Within a project, developers have control over delivery to mobile devices, web browsers, desktops, and consoles.
Supported platforms include Android, Apple TV, BlackBerry 10, iOS, Linux, Nintendo 3DS line, OS X, PlayStation 4, PlayStation Vita, Unity Web Player (including Facebook), Wii, Wii U, Windows Phone 8,
Windows, Xbox 360, and Xbox One. It includes an asset server and Nvidia's PhysX physics engine. Unity Web Player is a browser plugin that is supported in Windows and OS X only, which has been deprecated in favor of WebGL.
Unity is the default software development kit (SDK) for Nintendo's Wii U video game console platform, with a free copy included by Nintendo with each Wii U developer license.
Unity Technologies calls this bundling of a third-party SDK an "industry first".


tldr: Unity works on a lot of consoles/pcs and does a lot of neat visual stuff.


Spoiler: Task 1.00: Install Unity
https://unity3d.com/get-unity/download
For the purposes of this project [and really any purposes you'll likely ever need..], I would suggest using the Free version.
For this, we will be using Version 5.42. Try to make sure you have an up to date version if you already have Unity on your system!
Follow the installation process and if you have any trouble then refer to this Unity troubleshooting page:
https://docs.unity3d.com/500/Documentat ... Unity.html

If you're still having issues, drop a post in the thread or give us a shout on the discord and we'll try to help you figure it out.
Once Unity is installed, you'll need to create a Unity account. There's no fee or anything for joining, it just gives you better access to various features which can help you with your Unity programming experience
[and it's mandatory but I mean..]
If all worked as it should have, you should see something like this when you run the Unity shortcut:
Image


Spoiler: Task 1.01: Create your Working Folder
When you're developing/programming, it's usually best to try and keep all of your files as organized as possible.
Basically this lets you quickly/easily access stuff, saves you the headache of hunting around on your computer for where you saved something and helps you to keep your projects separated in a clean way.
You can mix things up a little if you want based on your personal preference of organizing things, but for me, I like to organize my projects as follows:
i) Create a folder on your desktop called "Development" [All of your programming files would then go in here]
ii) Create a folder within Development called "Unity" [All unity related files go in here and if you were to start using another language, you would create a new folder for it]
iii) Create a folder within Unity with the name of your project.

In this case, we'll be calling our project "HelloWorld". You can also help to organize your projects by giving them number prefixes to help you get to your most recent projects faster. IE: "01_HelloWorld"
[Sorting your folders by date made will also function in the same manner]


Spoiler: Task 1.02: Create first project
Image
When Unity is first booted up and you're logged in, you will be brought to the Project Wizard screen. Unfortunately there are no real wizards here, only project specification options.
Set the project directory to point to your working directory as we set it up in the last task.
For the purposes of this first project, you won't need to worry about importing any packages so just ignore that mumbo jumbo for now.
Underneath the login there's an option for choosing whether the project is 2D or 3D. For now we're going to stick with 2D, so please change the project to be 2D.


Spoiler: The Interface
https://docs.unity3d.com/Manual/Learnin ... rface.html
Image
I've highlighted and elaborated on portions of the interface that I feel are most important to understand [at least to start out with].
#Scene panel
:
A viewpoint that allows you to see the level that you're designing as you work. This viewpoint is meant to be flexible to allow you to get proper angles and orientations to edit things as you want them to look.
#Game panel
:
A viewpoint that allows you to see the level in the context of what the player will see as they play. You can only translate your viewpoint as a player playing the game and not as an editor. This is primarily for testing.
[Nothing will show up in this panel if your game isn't running]
#Hierarchy
:
Hierarchical text representation of every object in the scene. The hierarchy reveals the structure of how objects are attached to one another.
#Project panel
:
Shows all of your assets that you can currently use for your project
#Inspector panel
:
Allows you to view and edit all the properties of the currently selected object.
#Console
:
Place for the game to give text output for the programmer to see. Very useful for checking the status of various aspects of the game as it runs/testing for problems and bugs.
#Toolbar
:
Tools for manipulating the scene in various ways.

#Objects
:
"GameObjects are the fundamental objects in Unity that represent characters, props and scenery. They do not accomplish much in themselves but they act as containers for Components,
which implement the real functionality."
https://docs.unity3d.com/Manual/class-GameObject.html


Spoiler: Task 1.03: Hello World!
Now that you've got your first project going and you're a little familiar with the interface, we're going to jump right into your very first Unity program!
The first thing you're going to need is a game object. In Unity, most game behavior is represented by how game objects are programmed to behave/how they interact with each other.
In this case, we want an object that is programmed specifically to send us a message. So, to start, go to the menu at the top, select the GameObject menu and create an empty object.
If you look at the Hierarchy panel, you'll see a new object called "GameObject" alongside the Camera that was there before. In general, you'll want to name all objects [and really everything you ever use] in a way
that makes it a little more clear to you as to what they do.
IE: This gameobject that is going to send a message to you might be better named "Messenger" rather than just "GameObject". So, click it once and rename it.

Next, we want to actually create the code that will attach to this object to create and send the message to us when the code is running.
Move your attention to the Project Panel and find the Asset section. Right click and under the create section, choose C# Script. A new C#Script file will show up under the asset section with a generic name.
Image
We'll rename this file to SendMessage.
Open SendMessage and once you're done loading, you should see something similar to the following:
Image

This is essentially your first Unity Program. There's a decent amount to take in here if you’ve never programmed before or are a little inexperienced, so I'll ask you to mainly focus on two parts of the program:
i) // Use this for initialization
void Start () {

}

ii) // Update is called once per frame
void Update () {

}

The first block is a section of the code that will run when the object is created.
The second block is a section of code that will run constantly while the program is running.
For the purposes of HelloWorld, all we really want to do is send a single message to ourselves, so we'll focus primarily on the Start block.
In the empty line between "void Start() {" and "}" we're going to add Debug.Log("Hello world!");
This will write "Hello world!" to the Console [a part of the interface] when the program first starts if it is attached to an object.
Also, replace NewBehaviorScript with SendMessage in this line if it hasn't already been changed otherwise you may get a compilation error:
"public class SendMessage : MonoBehaviour"

Save and close your code editor and return to the Unity Editor. We have a script, but as of right now the script isn't doing anything because it isn't attached to a Unity Object. Think of a script as behavior and an object as something that does that behavior. IE: Walking could be a script and a person could be an object. A person can’t walk unless it is instructed to do so, right?

To instruct the Messenger object to send us a message, double click on it and bring your attention to the inspector panel. You should see a button that says "Add Component", click that and choose Scripts and then assign the SendMessage script that we created to it. If it worked, you should see the script as part of the object in the inspector panel:
Image

And we're nearly there! All of our program has been set up to run properly, now all you need to do is actually run the program. If you look at the top at the toolbar, you'll see a play button. If you hit play, your program will start.
If you click on the console, you'll see the following when your program is running:
Image

If you've reached this point, you've completed lesson one without incident! Congrats!


If you’ve completed the lesson, feel free to copy and paste your code in a post here or to screenshot the results of your code running. If you feel like experimenting and do anything neat, please share that too. And obviously if you have any questions just shout em out and we’ll do our best to help.
If there’s anything in the format/presentation/or really any aspect of these lessons that you think could be better/improved that would also be greatly appreciated as we’re still pretty new to this kind of stuff! [or at least I am zzz]
We're starting up a discord if people want to hang out while working on things or if you just would prefer to ask questions in real time there we figured it might be easier for some! Ask myself, chamber or errant for linkage if you're interested!
Happy coding. :)
Last edited by Cheetory6 on Mon Nov 14, 2016 12:52 pm, edited 1 time in total.
User avatar
Cheetory6
Cheetory6
MS Painter
User avatar
User avatar
Cheetory6
MS Painter
MS Painter
Posts: 7403
Joined: September 21, 2014

Post Post #39 (isolation #3) » Thu Nov 10, 2016 4:49 pm

Post by Cheetory6 »

We're mostly aiming to just get the result with the first lesson and to go into detail on exactly what the code is doing as we go more in-depth with coding in general in future lessons.
User avatar
Cheetory6
Cheetory6
MS Painter
User avatar
User avatar
Cheetory6
MS Painter
MS Painter
Posts: 7403
Joined: September 21, 2014

Post Post #57 (isolation #4) » Thu Nov 24, 2016 12:55 am

Post by Cheetory6 »

What code editor are you using? Visual Studio or Unity's? If VS, can I get a version #?
User avatar
Cheetory6
Cheetory6
MS Painter
User avatar
User avatar
Cheetory6
MS Painter
MS Painter
Posts: 7403
Joined: September 21, 2014

Post Post #59 (isolation #5) » Thu Nov 24, 2016 1:12 am

Post by Cheetory6 »

He said it's when he first creates any project so I'm thinking it's different.
User avatar
Cheetory6
Cheetory6
MS Painter
User avatar
User avatar
Cheetory6
MS Painter
MS Painter
Posts: 7403
Joined: September 21, 2014

Post Post #62 (isolation #6) » Thu Nov 24, 2016 2:51 pm

Post by Cheetory6 »

Spoiler: Intro to Control Structures
Today we're going to be covering control structures, which are an important set of tools used to direct the flow of your program. To understand what control structures do, we first have to cover exactly what the flow of a program is in general. Let’s revisit our code from the first lesson:

Code: Select all

void Start () {
  Debug.Log("Hello world!");
}


From your experience in the first two tutorials, you know that when you run this code, you’ll receive the Hello World message in the console. From later examples, you may have inferred that from the following code, you will receive the following messages in the following order in the following program:

Code: Select all

void Start () {
  Debug.Log("Hello world!");
  Debug.Log("How's it going?");
}

OUTPUT:

1 - "Hello world!"
2 - "How's it going?"

Given this, you probably understand that a program flows from top to bottom and in this case, the program will flow from the first open bracket to the second open bracket of the Start codeblock:
{ == START

step1
step2
step3
..
..
stepN
} == FINISH

The program will go line by line until it reaches that terminal bracket and then the program will terminate.


Spoiler: Codeblocks
Before we go any further with this example, now is probably a good time to elaborate a little bit on exactly what a codeblock is. Essentially, this is any grouping of code trapped between two matching curly brackets “{ }”. The outermost brackets will delineate their own codeblock and the innermost brackets will delineate their own codeblock.
IE:
{
==============

BLUE

{

==============

BLUE
RED

{

==============

BLUE
RED
GREEN
==============

}

BLUE
RED
==============

}

BLUE
==============

}

Anywhere marked as blue is within the blue brackets’ codeblock, anything marked as red is within the red brackets’ codeblock and so on.


Spoiler: If Statements
Most programs you're going to typically want to do something a little more complicated than just go from the start of the program to the finish every single time. Sometimes you're going to want to direct the flow of your program with these aforementioned control structures to achieve results that would otherwise require an absurd number of lines of code or would simply be impossible.

Recall back to our variables lesson. We covered a few different types of variables including booleans. At the time you may have wondered why a boolean would be considered important. It can be true or false. You might be wondering, “what’s so special about that?”
Well, booleans play a big role in the first control structure, the If statement [and the others too but we’ll get to that later]. An If statement is by definition “a programming conditional statement that, if proved true, performs a function or displays information.” In layman’s terms, an if statement is a coding tool that will run a section of code
ONLY
if it is given a boolean input that has a value of True.

Consider the following two If statements:

Code: Select all

if(true)
{
        Debug.Log("I am the code in the first If statement. You get to hear me.");
}

if(false)
{
        Debug.Log("I am the code in the second If statement. You do not get to hear me");
}

The brackets beside the If term contain the boolean value that is used to determine whether the code within the curly braces will be run or not. The first If statement has a value of true, and the contents associated with it will be run. The second If statement has a value of true, so the contents associated with it will not be run.

Hence, our output will be just:
“I am the code in the first If statement. You get to hear me.”

By extension of the last lesson, you can also provide a boolean variable as input to an if statement and you can even use full boolean expressions.


Spoiler: Garbage opinions that probably don’t matter much to new programmers
Something to consider is that doing the latter can lead to some bulky and ugly code in. A variable containing a boolean argument with a smart name will usually be easier to understand on revisit than a big block of boolean expressions sitting unlabeled within an If statement.
I’ll spare you the horror of some really nasty examples [partially because I don’t have time to go hunting for some of my worst offenses q.q], but trust me that you’ll thank me later if you really get into more complicated programming. Really try to practice putting complicated expressions into well named variables, especially if you’re ever planning on returning to code at a later date!


Spoiler: ElseIf/Else Statements
ANYWAY.
Continuing on with If statements, we’ll next be considering the Else statement. Essentially, an Else statement is an If statement in its own way. It’s a statement that if given a value of true, will run the code contained within its braces, except in this case an Else statement will
ALWAYS
follow an If statement of some kind and will
ONLY
run if the If statement that preceded it was skipped over because it was given a value of True as input.

If that’s potentially unclear, just consider the following example:

Code: Select all

if(false)
{
        Debug.Log("I am the code in the If statement. You do not get to hear me this time.");
}
else
{
        Debug.Log("I am the code in the Else statement. I am finally heard! >:D");
}

The else statement in this example has no condition, which makes sense given that it’s condition is kind of inherent. When the If statement before it is run, the Else statement is skipped. When the If statement before it is skipped, the Else statement is run. In this case, the latter is run and the second message is played:
"I am the code in the Else statement. I am finally heard! >:D"


Next up we’re covering the combination of the previous two concepts, the Else If statement. This may read a little confusing to you, so let’s start off with an example:

Code: Select all

bool condition1 = false;
bool condition2 = true;
if(condition1)
{
        Debug.Log("I am the code in the If statement. You do not get to hear me this time.");
}
else if(condition2)
{
    Debug.Log("I am the code in the Else If statement. My turn, nerd.");
}
else
{
        Debug.Log("I am the code in the Else statement. I am also not heard this time.");
}

An Else If statement will be run if all If/Else If statements before it are skipped over due to having a boolean input of false
AND
its own boolean input gives a value of true. In this case, condition1 is false, so the first If statement is skipped over and condition2 is true, so the Else If statement is run.


Spoiler: While Loops
For the other two control structures, we will be using a similar concept of using boolean expressions to guide the movement of our program, but we’ll adding the concept of Loops/Looping on top. A loop is essentially a section of code that gets repeated in the flow of program’s operation. We will first consider the While loop:

Code: Select all

int i = 0;
while(i < 4){
    Debug.Log(i);
    i++;
}
Debug.Log(“Escaped!!”);

The basic idea of the while loop, is that while the condition within the brackets is true the code within the curly brackets will repeat.
In this case, the while loop will repeat the code within its curly brackets until the variable i is no longer less than 4.
OUTPUT:

1 - "1"
2 - "2"
3 - "3"
4 - "4"

You have to be really careful when using while loops! There is the potential to create a set of conditions where a while loop will never have its condition become true and then the code within will repeat indefinitely and lock up your program. If you remove the contents of the code within the while loop above as follows, you will never get the “Escaped!!” message.

Code: Select all

int i = 0;
while(i < 4){

}
Debug.Log(“Escaped!!”);

OUTPUT:


Spoiler: Arithmetic Tangent
Before we move onto the last control structure, we need to cover a bit of a tangent. Programming has a lot of focus on condensing large amounts of code into something more compact and easier to digest. This extends as far as simple arithmetic. Programmers just don’t want to write out something like adding or subtracting a 1 to a number. Your first option for decreasing the size of your arithmetic-based expressions is to get rid of the variable and the operator on the right side of the equation by doing the following:
x+=1;

This statement essentially implies that the value of x is increasing by one.

You can do this with any value or any of the four basic arithmetic operators. Programmers weren’t satisfied with that, so they created increment/decrement operators [++ and -- respectively]. These essentially let you implicitly increase or decrease the value of a number without writing out an entire expression.

Consider the following example:
x++;
is equivalent to
x = x + 1;
which is equivalent to
x+=1;


The moral of the story is that coders want to be lazy [or neat, depending on how you want to look at it!].


Spoiler: For Loops
The final control structure we’ll be covering today is the For loop, which in many ways is very similar to the while loop, but with a little more in terms of working parts. Instead of just a generic boolean input, the For loop has three sections that have to be set before the code within can start repeating.
The most generic for loop declaration is as follows:
for(int i = 0; i < 4; i++)

Let’s break it down.
i) Initializing the counter variable - int i = 0
Set i to an initial value that it will take on at the beginning of the loop’s run.

ii) Setting the boolean condition - i < 4
Set a boolean variable that must no longer be considered true before the loop can stop running.

iii) Incrementing the counter variable - i++
A step that will occur every time the loop reaches the bottom bracket and goes to start the next iteration through the loop’s code.

So what does this mean in effect? Well, basically the For loop in this example will run the exact same as the While loop did in the last example. It will run the code inside its braces four times. One difference to consider is that the variable i will only exist within the For loop. If you try to access it before or afterwards, you’ll get an error. [If you experiment you may be able to find a similar effect in the If and While control structures!] We’ll go into more detail on why this is the case in future lessons, just something to note for now!

So, now we have a bunch of control structures. Big woop.
What can we do with them?
Well, surprisingly a lot, really. These are tools that you’ll find yourself using again and again and again as a programmer and it’s best if you really try to get a sense of how they work as best you can. Experimenting really helps here.


Spoiler: Nested Control Structures
One final thing to consider with control structures is that you can embed them within each other. [think back to the codeblocks example]
IE:

Code: Select all

if(...){
  while(..){
      if(..){
      }
      else{
      }
  }
}

The While Loop is within the first If’s codeblock and the If/Else are within the While Loop’s codeblock and the outer If’s codeblock.
This is called nesting or nested control structures.

If you’ve reached this point then you’ve completed this lesson! Congrats!


Spoiler: Challenges
1) Last week you were asked to print to the screen the largest possible value for an int. To do this you likely had to just calculate it outside of the program and then manually print that number. This week do the same thing, but do the calculation in unity using control structures.
2) Simplify the following hypothetical If/If Else statements into just two If statements [by hand, not in Unity]:

Code: Select all

if (condition) {
    if (conditionA) {
        codeBlockW;
    }
    else if (conditionB) {
        codeBlockX;
    }
}
else {
    if (conditionA) {
        codeBlockX;
    }
    else if (conditionB) {
        codeBlockW;
    }
}


3) A Fibonacci sequence is a series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc. Print all of the Fibonacci numbers under 100 to the console.
4) Find the biggest prime number under 100.
5) Add together all numbers between 1 - 1000 that are not divisible by 3 or 5, except for numbers that are divisible by both 3 and 5.
include : 1,2,4,7,8,11,13,14,15
exclude 3,5,6,9,10,12
Last edited by Cheetory6 on Thu Dec 01, 2016 3:24 pm, edited 1 time in total.
Post Reply

Return to “General Discussion”