Design a site like this with WordPress.com
Get started

Day 61: Lists, Arrays…

Lists, arrays, hashsets, queues, stacks, collections and dictionaries –  a lot of information to take in and will need to reread this section to get a firm understanding of the differences between them all.

On a personal note, I got a double-dose of good news today.  The test result came back negative, thank goodness.  I also heard back from an employer I had two interviews with last week – I got the job!  

It’s substantially more pay (it’s not like it could’ve been any lower) and a set Mon-Fri schedule.  This will allow me to focus even better on learning to program.

Ironically, this has left me feeling really apprehensive because good news is so rare. It’s almost like I’m waiting for the other shoe to drop.  Silly brain.  I need to learn to just enjoy the good times.

Current Progress Status

  • Tower Defense Tutorial: 57/73
  • Clean Code by Robert C. Martin (pg 284/464)

Onward!

Advertisement

Day 60: Abstract Classes

The SoloLearn app has been effective in teaching me different C# concepts but lacks in providing real life coding examples.

I was having a little difficulty understanding why an abstract class would be used and how it would be implemented, so I was thankful someone linked the following video in the comments. It helped clear everything up!

This youtuber has an extensive C# tutorial playlist that I’d like to go through, but unfortunately the mic issues aren’t resolved until video #61 😦

Current Progress Status

  • Tower Defense Tutorial: 56/73
  • Clean Code by Robert C. Martin (pg 209/464)

Onward!

Day 58: Shorthand

Just a little something I found interesting – in VS Code when the quick fix lightbulb suggests to encapsulate a field, it automatically inserts something like this:

public float DebuffDuration { get => debuffDuration; set => debuffDuration = value; }

…instead of the longer code below which was in the tutorial:

public float DebuffDuration
{
     get
     {
           return debuffDuration;
     }

     set
     {
           this.debuffDuration = value;
     }
}

It seems a lot cleaner & easier to read having the accessors all in one line instead of spread over a dozen.

As far as I can tell, they both do the exact same thing as it hasn’t messed up the game or thrown any errors.

I don’t know if that’s what’s referred to an Auto-Implemented Property, expression lambdas or just a shorthand way of typing the same code. Either way, I didn’t realize the same code could be written in different ways.

Between this little realization and what I’ve read thus far in ‘Clean Code’, programming well can be considered an art.

Current Progress Status

  • Tower Defense Tutorial: 56/73
  • Clean Code by Robert C. Martin (pg 185/464)

Onward!

Day 52: SoloLearn

I’ve added the SoloLearn app to my phone and will be alternating between it and reading Clean Code on my lunch breaks at work.

The app’s early C# lessons are basics that I’ve already covered in other tutorials but I need the repitition to firmly implant the syntax and use in my mind.

I also enjoy reading the comments under each topic – there’s always someone sharing something useful that wasn’t covered in the lesson.

Current Progress Status

  • Tower Defense Tutorial: 52/73
  • Clean Code by Robert C. Martin (pg 62/464)

Onward!

Day 50: Debugger For Unity

Apparently I had installed Debugger for Unity along with other VS Code extensions back on Day 11 but had never used it.

Today I spent a little time setting break points and using the debug console. It’s a big step up from inserting Debug.Log’s everywhere in order to scrutinize the code as I had been doing thus far.

Current Progress Status

  • Tower Defense Tutorial: 49/73 -> Health Bar Tutorial Completed
  • Unity in Action (completed)
  • Clean Code by Robert C. Martin (pg 62/464

Onward!

Day 49: Asset Packages

I enjoyed learning how to create and export an asset package from one project and import it into another.

From the Health Bar project, we exported the health bar prefab & scripts…


…and imported it into the Tower Defense project, made the necessary adjustments to the sprite and code, attached it to the enemy prefab – voila! A functioning health bar on the alien dude.

Current Progress Status

  • Tower Defense Tutorial: 49/73 -> Health Bar Tutorial Completed
  • Unity in Action (Pg 336 of 352)

Onward!

Day 48: New Behaviour Script

If you want to change the default new script when you Create -> C# Script in Unity, follow the path ~\Unity\Editor\Data\Resources\ScriptTemplates and edit the text file named 81-C# Script-NewBehaviourScript.cs.txt

Sorry, I don’t know what the path is on Mac

Note: You may need to run Notepad as an administrator if you get the ‘Access is Denied’ error message.

With the text file open, you can now edit the default new script.

I deleted the comment lines because they were unnecessary and felt too cluttered. As I get more experienced and see what functions I use frequently in a project, I can tweak it further and save some time.

Current Progress Status

  • Tower Defense Tutorial: 47/73 -> Health Bar Tutorial: Completed
  • Unity in Action (Pg 336 of 352)

Onward!

Day 45: Time.deltaTime

I grew up playing on dedicated consoles like the Sega Genesis where a game would run exactly the same no matter whose Sega you played it on.

On PC, developing a game means having to adapt code to run smoothly on virtually an unlimited amount of computer configurations.

This is where the concept of Time.deltaTime comes in. (I’m just reiterating what I’ve learned to solidify the points in my head – feel free to correct me if my understanding on any of the points are wrong)

Let’s say I’m creating a game where I want to move an object at the speed of 6:

public class moveObject : MonoBehaviour
{
     public float speed = 6f;
      
     void Update()
     {
         transform.Translate (speed, 0, 0)
     }

But I’m poor and have a slow computer. It runs the game at 30 frames per second.

FPS (30) * speed (6) = 180 (distance moved)

Someone else has a faster computer. It plays at 55 frames per second.

FPS (55) * speed (6) = 330 (distance moved)

In one second, the game object on the faster computer traveled nearly twice as far in the same time because it called the Update() function 25 more times in one second.

Time.deltaTime is used make this movement frame independent. It represents the time passed in seconds since the last Update().

public class moveObject : MonoBehaviour
{
     public float speed = 6f;
      
     void Update()
     {
         transform.Translate (speed * Time.deltaTime, 0, 0)
     }

My Slow Computer
30 (frames) / 1 (second) = 0.0333333333333333 (time between updates)
Speed * Time.deltaTime =
6 * 0.0333333333333333 = 0.2 (amount moved each frame)
30 FPS * 0.2 = 6 (distance moved each second)

Someone’s Faster Computer
55 (frames) / 1 (second) = 0.0181818181818182
Speed * Time.deltaTime =
6 * 0.0181818181818182 = 0.109090909909091
55 FPS * 0.090909099090909 = 6 (distance moved each second)

Using Time.deltaTime made the distance traveled by the object frame independent. Now no matter how fast or slow your computer runs, it will move at the same rate on screen as another player’s.

The same principle applies on the same computer. If I have a lot of programs running, my game might be running slower at some points and faster at others. Time.deltaTime will smooth the movement of the object instead of it looking twitchy each time Update() is called and the object ‘rushes’ to catch up.

In the same vein of frame rate independency, I also need to learn about FixedUpdate() for physics calculations.

Current Progress Status

  • Tower Defense Tutorial: 47/73
  • Unity in Action (Pg 324 of 352)

Onward!

Day 39: Naming Conventions

When you’re learning a brand new programming language AND an engine it’s initially very confusing as to whether the code is:

  • plain C# syntax
  • derived from Unity’s built-in class base, MonoBehaviour
  • a user defined variable, method or class name

For example, tutorials might have code like this:

public void ReleaseObject(GameObject gameObject) 
{ 
// do something 
}

It will eventually become second nature, but for newcomers like myself it’s a little intimidating when you don’t know the syntax. Which of the ‘objects’ is the variable, class or method?

I like how in Unity in Action, Joseph Hocking has all his variables prefixed with an underscore. The first line of code would then look like:

public void ReleaseObject(GameObject _gameObject)

Such a minor change but at a glance I can see the flow easier and quicker.

Sure it doesn’t adhere to camelCasing convention yet for someone learning it helps oh so much.

I know in time I’ll look back and laugh at this gripe, but it’s currently a little overwhelming keeping everything straight when variables are named exactly the same as a type save for a capitalized letter. Another example:

public class TowerButton : MonoBehaviour
{
    private Sprite sprite;

    public Sprite Sprite
    {
        get
        {
            return sprite;
        }
    }
}

Too many “sprites”!

The best explanation on methods and classes I’ve read was in the following reddit comment:

Current Progress Status

  • Tower Defense Tutorial: 38/73
  • Unity in Action (Pg 215 of 352)

Onward!

Day 35: C# Notes for Professionals

C# Notes for Professionals is a free 808 page ebook containing commented code samples, quick reference links and is a great overall resource: download page. (It’s compiled from Stack Overflow Documentation) I’ve found it useful so it’s been added to my Assets & Resources page.

The site GoalKicker.com has dozens of these free ebooks on a host of different languages and development programs. It may be worth a look.

Current Progress Status

  • Tower Defense Tutorial: 33/73
  • Unity in Action (Pg 183 of 352)

Onward!


%d bloggers like this: