“Creator Kit: Beginner Code”: Day 2

Today I went through another big chunk of the Creator Kit: Beginner Code tutorial. Yesterday was an introduction to (a review of) variables and functions, plus some syntax for C#. Today was all about classes, and I was both bored and boggled by turns.

Bored

It is TBQH not the tutorial’s fault that I already know a lot of the concepts they’re introducing, and that I’m mostly in it for the syntax, but still. I ended up critiquing the lesson structure in my notes halfway through, which isn’t the worst use of my time (learning how to teach is definitely not nothing), but still wasn’t… great.

The lesson that got me was the unit about writing your own spawner class, which per my notes was structured something like this:

  1. Here’s how to write the syntax for declaring a class (always a good place to start)
  2. Declare your global variables (a good next step, though they didn’t actually call them global variables or explain what the difference would be, which seems important)
  3. Write the most important function, the one you absolutely need your class to be able to perform (a constructor, you say? no, no. just the function which is the primary point of the class. which… i get, but seems backwards)
    1. In writing the most important function, use a class and function which we have written for you elsewhere. This function should be relatively simple to write on your own, even if it would provide redundancy (I assume the function is also needed other places, which means they can’t wait for you to write it in the tutorial. But you won’t write it. We won’t tell you how it works.
    2. Here’s a hint: it’s almost definitely just a modulo operator. That’s it.
  4. Now you get to write the constructor function.
  5. But because we didn’t tell you about what public variables are, your code doesn’t work, and you now have five errors.
  6. That’s it, that’s the end of the unit. See you next time.

I bet it shows how impressed I was.

But it was actually good practice for writing code, and I found myself remembering syntax pretty intuitively, which was helpful.

Boggled

In order to treat myself and prove what a smart and special programmer I am, I decided to add in a for-loop, using a public int which one could set in Unity. The size of the int would determine how many health potions/how much money spawned at the start of the game.

Ladies, gentleman, and those of us who know better: I broke everything.

That’s perhaps a little overdramatic, but essentially, I crashed the Unity editor like six times. You could not change the variable and then run the game without immediately causing the Unity editor to freeze, which in turn forced me to kill the program from the Task Manager.

If you didn’t change the variable (which by default was 0), everything was fine, by which I mean the game would run without the Unity editor crashing. Everything was not fine, in that zero potions would spawn, with no way to change that.

Eventually I decided to put my for-loop inside a conditional clause: if the number of potions is less than or equal to zero, don’t bother. If it’s not, try the for-loop.

This worked, in that the game no longer crashed if you changed the variable. It still left me with absolutely no potions, because the game just did not care what you changed the variable to.

I gotta figure out how to write to the console in order to speed up my debugging. In the meantime, have a screenshot of my terrible for-loop (with the section it was supposed to replace commented out). That’s all, folks!

A screenshot of code, consisting of the declaration of two global variables, a function which contains a variable meant to calculate angles and an if-statement containing a for-loop containing a function that is meant to spawn loot. Commented out is the same function outside of the if-statement, but repeated four times.
Please witness that most important precursor to success: failure.

UPDATE: I FOUND IT. RIGHT AWAY. ABSOLUTELY CLASSIC.

(Hint: I asked i to be equal to zero, and also greater than whatever number of objects I wanted to spawn. Oops.)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php