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 #25 (ISO) » Sat Nov 05, 2016 2:26 pm

Post by Cheetory6 »

I think we're going Unity.
User avatar
chamber
chamber
Cases are scummy
User avatar
User avatar
chamber
Cases are scummy
Cases are scummy
Posts: 10703
Joined: November 20, 2005

Post Post #26 (ISO) » Sat Nov 05, 2016 3:42 pm

Post by chamber »

Yeah, plan is Unity atm.
Taking a break from the site.
User avatar
xRECKONERx
xRECKONERx
GD is my Best Man
User avatar
User avatar
xRECKONERx
GD is my Best Man
GD is my Best Man
Posts: 26087
Joined: March 15, 2009

Post Post #27 (ISO) » Sat Nov 05, 2016 3:44 pm

Post by xRECKONERx »

/in to learn
green shirt thursdays
User avatar
chamber
chamber
Cases are scummy
User avatar
User avatar
chamber
Cases are scummy
Cases are scummy
Posts: 10703
Joined: November 20, 2005

Post Post #28 (ISO) » Sun Nov 06, 2016 7:14 am

Post by chamber »

Unity has some framing that is custom but lets you use 1 of 2 languages for scripting, one of which is c#.
Taking a break from the site.
User avatar
Clumsy
Clumsy
Mafia Scum
User avatar
User avatar
Clumsy
Mafia Scum
Mafia Scum
Posts: 1706
Joined: January 10, 2016
Location: MAP:08

Post Post #29 (ISO) » Sun Nov 06, 2016 8:09 pm

Post by Clumsy »

/in as student!
Current game: Witch Trials Mafia, in Mini Theme Queue. 2/6 Pre-ins.

Next D&D game: In design stage.
User avatar
Majiffy
Majiffy
Go with the Flow
User avatar
User avatar
Majiffy
Go with the Flow
Go with the Flow
Posts: 23825
Joined: November 23, 2011
Location: Memphis, TN
Contact:

Post Post #30 (ISO) » Mon Nov 07, 2016 2:11 am

Post by Majiffy »

I'd be interested in learning the C's, not Java though.
Only playing in games at personal moderator and/or 50%+ playerlist request.


How To Win Every Game At Mafiascum (The Flowchart)
||
In case anyone was unsure...
Svenskt Stål (23:38) majiffy, worst mod on ms? we talk to a surviving victim of his game
User avatar
Flubbernugget
Flubbernugget
Survivor
User avatar
User avatar
Flubbernugget
Survivor
Survivor
Posts: 11751
Joined: June 26, 2014

Post Post #31 (ISO) » Mon Nov 07, 2016 1:17 pm

Post by Flubbernugget »

They're close enough to the same thing if you're beginning
User avatar
theplague42
theplague42
Mafia Scum
User avatar
User avatar
theplague42
Mafia Scum
Mafia Scum
Posts: 1505
Joined: October 31, 2010
Location: Denver, CO

Post Post #32 (ISO) » Tue Nov 08, 2016 7:32 am

Post by theplague42 »

Ah unfortunately none of my experience is with Unity; I'm web. :(
Part of the problem.
User avatar
GuyInFreezer
GuyInFreezer
Magical Girl
User avatar
User avatar
GuyInFreezer
Magical Girl
Magical Girl
Posts: 18048
Joined: January 23, 2013
Location: In your wall

Post Post #33 (ISO) » Tue Nov 08, 2016 7:32 am

Post by GuyInFreezer »

/in student
Show
"I used to think you had this elegant-trolly, minimalist playstyle. Then I realized the playstyle is ~Lazy~
The true enlightenment was realizing that they are the same thing."
~fferyllt

"who the fuck fakeclaims Tracker like that
WHO THE FUCK DOES THAT"
~Alisae
User avatar
Cheetory6
Cheetory6
MS Painter
User avatar
User avatar
Cheetory6
MS Painter
MS Painter
Posts: 7403
Joined: September 21, 2014

Post Post #34 (ISO) » 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
gigabyteTroubadour
gigabyteTroubadour
Jack of All Trades
User avatar
User avatar
gigabyteTroubadour
Jack of All Trades
Jack of All Trades
Posts: 7577
Joined: May 30, 2016
Location: New Jersey, the Armpit of the United States

Post Post #35 (ISO) » Thu Nov 10, 2016 2:14 pm

Post by gigabyteTroubadour »

oh, i think my post was moved to the other thread but I /outed for this :P

sorry guys!! (tho if you're going to post lessons in thread i might follow along for future reference)
i no longer strictly go by they/them and honestly prefer she/her but they/them's fine if you're used to it i guess

☭ I'm coming for that toothbrush ☭
User avatar
Accountant
Accountant
Jack of All Trades
User avatar
User avatar
Accountant
Jack of All Trades
Jack of All Trades
Posts: 6419
Joined: May 16, 2015
Location: Wonderland

Post Post #36 (ISO) » Thu Nov 10, 2016 3:24 pm

Post by Accountant »

/in student
There's nothing that says that a fake can't beat the real thing.

You must not imagine that for beings like you and us there can be laughter. The low men laugh, and we envy them. But for us, the higher ones, there is no laughter, only an unending vigil, purely serious, stretching on into the night.
User avatar
GuyInFreezer
GuyInFreezer
Magical Girl
User avatar
User avatar
GuyInFreezer
Magical Girl
Magical Girl
Posts: 18048
Joined: January 23, 2013
Location: In your wall

Post Post #37 (ISO) » Thu Nov 10, 2016 4:01 pm

Post by GuyInFreezer »

Image
Show
"I used to think you had this elegant-trolly, minimalist playstyle. Then I realized the playstyle is ~Lazy~
The true enlightenment was realizing that they are the same thing."
~fferyllt

"who the fuck fakeclaims Tracker like that
WHO THE FUCK DOES THAT"
~Alisae
User avatar
xRECKONERx
xRECKONERx
GD is my Best Man
User avatar
User avatar
xRECKONERx
GD is my Best Man
GD is my Best Man
Posts: 26087
Joined: March 15, 2009

Post Post #38 (ISO) » Thu Nov 10, 2016 4:47 pm

Post by xRECKONERx »

Image

I think it'd be helpful to understand what we're coding. Like, what is the "Debug" command? Etc
green shirt thursdays
User avatar
Cheetory6
Cheetory6
MS Painter
User avatar
User avatar
Cheetory6
MS Painter
MS Painter
Posts: 7403
Joined: September 21, 2014

Post Post #39 (ISO) » 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
chamber
chamber
Cases are scummy
User avatar
User avatar
chamber
Cases are scummy
Cases are scummy
Posts: 10703
Joined: November 20, 2005

Post Post #40 (ISO) » Thu Nov 10, 2016 4:50 pm

Post by chamber »

In post 38, xRECKONERx wrote:Image

I think it'd be helpful to understand what we're coding. Like, what is the "Debug" command? Etc
We do intend to teach everything that's going on in this example eventually. But Everything is a lot. We wanted there to be some sense of accomplishment rather than here's 6 hours of us truly explaining everything you need to learn before you can do anything.

Expect it to be peppered into future lessons when knowing more about it becomes more useful.

In this instance, the Debug command is used to help debug your code, when you run into issues it can be useful to write things to the console about the state of the program so you can better figure out where and why it's failing.
Taking a break from the site.
User avatar
xRECKONERx
xRECKONERx
GD is my Best Man
User avatar
User avatar
xRECKONERx
GD is my Best Man
GD is my Best Man
Posts: 26087
Joined: March 15, 2009

Post Post #41 (ISO) » Thu Nov 10, 2016 4:52 pm

Post by xRECKONERx »

so Log is what tells it to print to console?
green shirt thursdays
User avatar
chamber
chamber
Cases are scummy
User avatar
User avatar
chamber
Cases are scummy
Cases are scummy
Posts: 10703
Joined: November 20, 2005

Post Post #42 (ISO) » Thu Nov 10, 2016 4:52 pm

Post by chamber »

Yes.

There is a very deep rabbit hole to better explain what's going on. For now trust that we will get there in time, and that this lesson was mostly about getting you comfortable working in unity a little bit.
Taking a break from the site.
User avatar
Sudo_Nym
Sudo_Nym
Pseudo Newbie
User avatar
User avatar
Sudo_Nym
Pseudo Newbie
Pseudo Newbie
Posts: 1144
Joined: March 12, 2007
Location: Washington

Post Post #43 (ISO) » Thu Nov 10, 2016 4:56 pm

Post by Sudo_Nym »

This was fun, though a bit simple. Here's my code for SendMessage:
Spoiler:
using UnityEngine;
using System.Collections;

public class SendMessage : MonoBehaviour {

// Use this for initialization
void Start () {
Debug.Log("Hello World!");
Debug.Log(@"Please enjoy the following poem:
A hobo always goes and goes
He does not stop to change his clothes
He rides the rail that he has chose.
Water pours out from a hose!

Do not show me tramp or bum
Tramp may ride, and bum's a chum
But both beg from the other one
Kids, stop chewing bubble gum!

Neither works like hobo does
Carving coin and twisting fuzz
Into a pretty pair of gloves
The past tense of 'to be' is 'was'!

A hobo, he will never steal
Unless it is to get a meal
Or cash, or gems, or fur of seal
Some Japanese eat broiled eel!

But saddest: those who will not ride
At all, but stand and die inside
As world spins on and throws aside
The past, and hope, and faith, and pride
In one direction trains do glide
Not looking back, on windward side
Across the continent's divide
The hobo rides and rides and rides
I'll eat anything that's fried
--Mindbender Steve, The Appeal to Reason, 1916");
Debug.Log("Thank you.");

}

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

}
}
One time, back in 'nam, Sudo was set upon by an entire squadron of charlies. He challenged them all to a game of Pictionary, which he won resoundingly. The charlies were forced to not only surrender the skirmish, but also their world-famous chili recipe, which Sudo sold to Texas for a hefty profit. Sudo is a master of diplomacy.
User avatar
Equinox
Equinox
he/they
Shot Count
User avatar
User avatar
Equinox
he/they
Shot Count
Shot Count
Posts: 10105
Joined: April 12, 2010
Pronoun: he/they
Location: Los Angeles, CA

Post Post #44 (ISO) » Fri Nov 11, 2016 4:52 pm

Post by Equinox »

Image
User avatar
Sotty7
Sotty7
That Damn Good
User avatar
User avatar
Sotty7
That Damn Good
That Damn Good
Posts: 6744
Joined: October 7, 2005
Location: Minnesota

Post Post #45 (ISO) » Sat Nov 12, 2016 4:39 am

Post by Sotty7 »

Image

Times I thought I would be a little overwhelmed but the instructions were done well so I didn't get lost. A nice intro to it all I think.
User avatar
Errantparabola
Errantparabola
Composed.
User avatar
User avatar
Errantparabola
Composed.
Composed.
Posts: 4636
Joined: March 13, 2015

Post Post #46 (ISO) » Sun Nov 13, 2016 5:15 pm

Post by Errantparabola »

Hi! personal issues have kept me from being able to keep up to date on this, but those have largely passed so I should be fully engaged in 2-3 days. thanks and apologies.
did another ms user do something lovely? recognize their achievements here!

Today's modern mafia consumer demands dozens, nay, hundreds of roles that are vanilla cops.
--implosion
provided
User avatar
Firebringer
Firebringer
Trail Blazer
User avatar
User avatar
Firebringer
Trail Blazer
Trail Blazer
Posts: 52501
Joined: June 28, 2015
Location: woofbringer
Contact:

Post Post #47 (ISO) » Thu Nov 17, 2016 10:23 am

Post by Firebringer »

/in student
working on first week assignment now
Show
"You are the Joker of mafia players" - Oversoul
"last time I was scum with Firebringer
his first post in the scum PT was "yes I rolled scum!"
I decided to post "haha just don't post that in the main thread", but to get up to date on the main thread first.

His first post in the main thread was "yes I rolled scum!" -popsofctown
User avatar
chamber
chamber
Cases are scummy
User avatar
User avatar
chamber
Cases are scummy
Cases are scummy
Posts: 10703
Joined: November 20, 2005

Post Post #48 (ISO) » Thu Nov 17, 2016 12:32 pm

Post by chamber »

Spoiler: Introduction
In the previous lesson we used the following code:

Code: Select all

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

In today's first lesson we will be covering one part of this in more detail. "Hello world!". If you were observant you may have found it strange that we had to put quotation marks around this, but not other parts of the code. This is because "Hello world!" represents a string value. This shouldn't mean anything to you yet if you are new to programming, so don't worry. For today's lesson I've provided code snippets for most of the examples, however I encourage you to type them yourself rather than copy-pasting them. This will help your familiarity going forward.


Spoiler: 2.01: Variables explained
Variables are a means of storing data for later use. They are one of the core pillars of programming. It may help you to think of a variable as a box.

Image

It has a name used to access the value, and the value that is stored. Variables come in different types, today we'll be handling 3 families of variables. Words, Numbers, and True/False (in programming called a Boolean). With the exception of Booleans, these are not typically grouped like this, and are only being done so now as a teaching tool. For Words your primary type of variable is a string. A string holds whatever characters you want it to, and is enclosed in ""s. An addition type is char, which is a single character. char's are enclosed in ''s.

If we go back to the program we made last week, we now know some of what we need to make a change.

Change

Code: Select all

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

To

Code: Select all

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


And run the program again. You should see the same message as last time.

As I said previously "Hello world!" is a string value. We know this because it's enclosed in ""s. What's new here is

Code: Select all

        string message = "Hello world!";


This has several parts which I will now break down.

'string': This is the type of the variable we wish to declare.
'message': This is the name of the variable we wish to declare, we can then use it in the future to represent the stored value.
'=': This is the assignment operator. This may be confusing for people with a math background. Thinking of it as a traditional equals sign can get you in trouble. It means set the value of what's on it's left side to the value of what is on it's right side.
'"Hello world!"': This is the value we assign to message using '=' the assignment operator.

At this point I encourage you to play around a bit, entering your own string values.

Above we declared and assigned the variable in the same line. This is common, but not the only way to do things. You may not know the value a variable will have at the time it's being declared. In such cases you can break it up

Code: Select all

        string message;
        message = "Hello world!";


Note that string is not repeated at the beginning of future references to message, only when it's first declared, and that you need to end each line with ";" the line terminator. If you are observant you'll notice that this isn't true of all code by looking at other parts in this file, but for now, everything you do inside of 'Start' will require it.

Try one final example to help understand variable assignment

Code: Select all

void Start () {
        string message;
        message = "Hello world!";
	Debug.Log(message);
        message = "Hello world Again!";
	Debug.Log(message);
}


At this point if you feel you don't understand variable assignment, please ask one of the teachers in discord.

That will cover strings for now, but as I said above, we are also covering Numbers, and booleans.


Spoiler: 2.02: More Types
There is a lot more going on with types for numbers than there were for strings and chars, and we wont be covering it exhaustively today. Primarily they are divided in 3 ways. First, whether the Number is an integer or a floating point (real). Second, the maximum and minimum sized number it can hold. And Third, whether it can hold negative values or not(signed).

The primary Type you will use for an interger is
int
. The primary type you will use for a floating point number is
double
.

An int is also known as an
int32
. This is because it can store 32 bits worth of data. It is signed, which means it can hold both negative and positive numbers. Because of this the maximum value it can hold is (2^31)-1 and the minimum value it can hold is -(2^31).
The first bit of the 32 being used to indicate whether it is odd or even.

A double holds 64 bits of data and is also signed. Because of the way a double stores data, it can store very large values, but is only precise to 15 or 16 digits.

Now lets try and use some new types of variables in our program.

Code: Select all

void Start () {
        string message;
        message = "Hello world!";
	Debug.Log(message);
        message = "Hello world Again!";
	Debug.Log(message);
        int number;
        number = 7;
        Debug.Log(number);
}


Now lets try a double

Code: Select all

void Start () {
        string message;
        message = "Hello world!";
	Debug.Log(message);
        message = "Hello world Again!";
	Debug.Log(message);
        double number;
        number = 7.0;
        Debug.Log(number);
}


The final variable Type we introduce in this lesson is a Boolean. A Boolean is either true or false. Up until now all of our programs have run from the top of 'Start' to the bottom of 'Start' in order. Boolean values are key in controlling and altering the flow of a program. We wont be doing so this lesson, but I wanted you to understand their significance.

Code: Select all

void Start () {
        string message;
        message = "Hello world!";
	Debug.Log(message);
        message = "Hello world Again!";
	Debug.Log(message);
        double number;
        number = 7.0;
        Debug.Log(number);
        bool isTrue = true;
        bool isFalse = false;
        Debug.Log(isTrue);
        Debug.Log(isFalse);
}


Take this Moment to ask in discord if you feel you don't understand anything.

Now that we know some basic variable types lets have some fun with them.

Think a bit about what you think these will do before running them.

Code: Select all

void Start () {
       int number1 = 1;
       int number2 = 1 + 1;
       number1 = number1 + number2;
       Debug.Log(number1);
}


Code: Select all

void Start () {
       int number1 = 1;
       int number2 = 1 + 1;
       number1 = number1 + number2;
       number2 = 5;
       Debug.Log(number1);
}


Spoiler: 2.03: Operators
Now that we have a basic grasp on variables, we are going to introduce and cover some basic operators. That sounds more scary than it is because we've already used one above +(addition). Some other operators are -(subtraction), *(multiplication), /(division), %(mod). For those that have been out of school for a while the % operator will return the remainder of a division operation. So 5%2 would be 1. These are collectively known as arithmetic operators. Most of those should work how you expect. However there is one big exception. / can have unexpected results for new programmers because if both sides of the operator are ints, the return value will also be an int. For example 5/2 would not be 2.5, it would be 2.

I don't have any structured exercises to take you through for these right now, but I suggest you play with them a bit on your own. When you are comfortable with them we can move on to some string operators.

The only string operation we are going to cover for now is concatenation. That's a big scary word, but it just means adding 2 or more strings together. When they are added the latter will be appended to the former. In c# the concatenation operator is also +.

Code: Select all

void Start () {
      string hello = "hello";
      string world = "world!";
      string helloworld = hello + world;
      Debug.Log(helloworld);
}


You'll note that the 2nd string was appended (added to the end of) the first string. However, we are missing a space between them. I did this intentionally because its an easy error to make, and wanted you guys thinking about it.

Code: Select all

void Start () {
      string hello = "hello";
      string world = "world!";
      string helloworld = hello + " " + world;
      Debug.Log(helloworld);
}


All better.

Finally for booleans we are going to cover the comparative operator(==), not (!), or(||), and (&&). We will cover these in more detail later, but I at least want to get them introduced to you now. == is used to compare two values and resolves to a boolean. So for instance 1 == 1 would resolve to true.

Code: Select all

void Start () {
      Debug.Log(1 == 1);
      Debug.Log(1 == 2);
}


The ! operator inverts the boolean value of anything its put in front of. For instance

Code: Select all

void Start () {
      Debug.Log(!(1 == 1));
      Debug.Log(!(1 == 2));
}


|| and && are used for more complex statements, for instance

Code: Select all

void Start () {
      Debug.Log((1 == 1) || (1 == 2));
      Debug.Log((1 == 1) && (1 == 2));
}


|| is true if either side is true, && is true only if both sides are true.



Spoiler: Challenges (not so challenging this week)
1 print the boolean true value to the screen using all of the different boolean operators we worked with. Don't just copy a previous example.
example:

Code: Select all

Debug.log((1==1) && !(1==2) || (1==1));

2 Same as above but false instead of true.
3 Try concatenating a string and an int or double. Print it to the screen.
4 Try the same with a string and a bool.
5 print the product of any 2 numbers.
6 print the maximum value of an int.
Taking a break from the site.
User avatar
GuyInFreezer
GuyInFreezer
Magical Girl
User avatar
User avatar
GuyInFreezer
Magical Girl
Magical Girl
Posts: 18048
Joined: January 23, 2013
Location: In your wall

Post Post #49 (ISO) » Thu Nov 17, 2016 4:46 pm

Post by GuyInFreezer »

Spoiler: Challenges
Image
Show
"I used to think you had this elegant-trolly, minimalist playstyle. Then I realized the playstyle is ~Lazy~
The true enlightenment was realizing that they are the same thing."
~fferyllt

"who the fuck fakeclaims Tracker like that
WHO THE FUCK DOES THAT"
~Alisae
Post Reply

Return to “General Discussion”