Help - Is there and Ah Ha moment to Scritpting/Programming?

Hey all,

I was hoping really hoping to get some great advice with regards to the best practices and approaches when it comes to tackling scripting/programming, specifically how you all go about problem solving and beginning your projects with relation to writing code.

For years I’ve dabbled in several different languages (C#, Java, C++, python), gone through countless books, websites, and courses from beginner to intermediate levels. Unfortunately the aspect of writing my own code has always been extremely illusive for me to grasp and even more so discouraging when left to my own devices. I seem to hit an immediate wall. For example I can go through multiple lessons and concepts and believe to fully understand them, but when left without any reference I seem to blank, become uncertain of how to approach the problem, where to begin structuring code, etc.

For whatever reason code has always been this illusive skill I’ve never truly felt comfortable with on my own. I keep thinking I’ll have this “ah ha!” moment if I keep plugging away. Unfortunately I feel like I’ve constantly studying the same concepts over and over and not really breaking through.

So my question to all those I look up to so much is how do you approach a blank slate? What design, flow charts, variables, etc do you structure prior to writing code? How defined is this structure? Most importantly what exercises helped you get better at breaking down problems and writing code for them?

Any help would be greatly appreciate as it already is from this community!

Cheers.

Hi millmuff22,

I took coding classes in high school, and received my B.S in computer science. That said, I’ve always hated coding. I never knew how/where to actually start.

The biggest thing for me was to say screw it to all of the books, tutorials, and lessons.

Once I started using Unity, for instance, I just jumped in head first. I always have a general idea of what I’m trying to accomplish, and how I think I can accomplish it via code.

With that, I’ll just keep hammering away trying to reach my goal. If something doesn’t work, or isn’t working as expected, that’s when I’ll go to the documentation, search on Google for C# information, or just ask around here for help.

This approach has worked really well for me, and now I actually enjoy working on my projects. Additionally, I learn a lot faster by doing this.

At this point, I still run into lots of coding puzzles when programming, but I just keep my mind focused on the light at the end of the tunnel, and come across several “aha!” moments along the way to lift my spirits.

Regards,
Ezro

Have you started off with tiny exercises and made sure you understand them in depth?

If you’re jumping into a game engine and having trouble understanding what your code is doing it’s quite possibly because in a game engine your code is often quite removed from what the computer actually does, and/or there are many other influencing factors.

For instance, the below snippet looks pretty simple…

void Start() {
    transform.position = new Vector3(1, 2, 3);
}

… but to fully understand what that does and what it means already requires a fair bit of supporting environmental knowledge aside from just knowing what the code does. It’s easy to explain “it assigns a new value to the position of the transform”, but that doesn’t actually help you understand. What is transform and what is position? What is a Vector3 and in what context are the numbers it contains used? How does the transform determine the location of something in the scene? On that note, what actually is a scene? What is the Start() method, how is it used, what calls it and when?

A lot of tutorials out there cover the “how”. Which is to say, they’ll give you a code snippet like the above and just say “this is how you set the position of a GameObject”. Which is cool if your knowledge doesn’t have to extend further than that, but that’s not enough to go on and write your own code that solves your own problems.

On the other hand, the typical “hello world” programs people start with are actually pretty straightforward. All you need to understand aside from the code you write is what your output pipe is, because that’s the entirety of the context which matters to you at the time. And then you can build on that a few pieces at a time, and you’ll get up and running with the basics pretty quickly.

So my advice is to pick a language (C# is a good one for this, since it’s used in Unity) and buy a decent book or do a Uni course that just teaches the programming side of things. Learning programming and learning Unity are two separate activities. Also, learning game programming is a specialization of programming, not a subset, so learn some general coding first and then apply it to games once you’ve got the basics.

that may come from the fact that there are several ways to do this and all are more ore less equal valid. usually there is no “perfect” way as perfect is an aggregation of several aspects fe development time, lines of code, maintenance capability, runtime performance, extendability. if you give the same task to 10 programmers all would come up with a different solution as they have different experiences and judging of “perfection”.

structuring and managing a big project is not an easy task and i think it cannot be learned by a book/tutorial but only by experience. try it several times and you will notice where your system lacks and need improvement. but this also depends on personal style and simply copying the methods of someone else who use them successfull will not always work for you imo.
however, there are some “rules” and guidelines. the single most important one to me is to reduce complexity by increasing decoupling. have a read over this article and the following 3 for additional methods. i prefer the id-lookup and have a system only manage a sertain type where the objects are indexed to be shared by other objects. together with the composite pattern this allows real flexible interconnections and it can be extended by don’t break other working code.

a big problem i see with your considerations is that there are so many methodologies out there that you can’t stay actual and know all of them. this would make you to permently change your code when you learn something new. if you decided for a system use it to the bitter end and explore its (dis)advantages and when you learn about a new method consider what would change when you would use it but wait with applying it until the next project (or restart if it is groundbreaking).

thats the reason why i consequently ignore noob questions like “what is the most perfect way of achieving this”. don’t bother with making it perfect but try to finish it as good as you can.

You kinda have to experiment for a while.

Ill explain the snippet you gave us:

void Start() {
    transform.position = new Vector3(1, 2, 3);
}

Okay. Lets split this up into two parts - the function (void Start), and the command (transform…)

Functions

There are many different functions, which are each used to do different things. Think of a function as a folder. When the folder is opened (When the function is called), all the commands on the inside (The code) is executed. So:

void Start(){ //The folder
//All the stuff inside the folder
}

Lets break this up.

void Start(){

Okay. This is separated into 4 parts = void Start(){
Sorry if those colours are hard to read.

void = this tells the computer that you are defining a function, or ‘folder’.
Start = this is one of the built in functions. This is executed at the start of the script, before every other function. (There are exceptions to this, such as Awake(), which is executed before start)
() = I have no idea what this means, what this is. I dont care. You put this after define a function. I’ve been coding for 3 years and I haven’t needed to know what it is for. All it is used for is defining a function, and putting values into it. (Will explain later)
{ = this defines the start of the folder. The contents of the folder are held inside the { and }.

The command

This command is simple, but you need a bit of ‘backstory’.

transform = this denotes the position, rotation, and scale of an object.
position = this denotes the position (surprise!) in a Vector3 format.
Vector3 = Vector3’s are co-ordinates. x, y, and z. y is height, x is distance left, z is distance right. (I may be wrong on the left/right, and they can be different in different softwares).

So:

transform << This tells the computer we are going to change the position, scale or rotation of an object.
transform.position << This tells the computer we are going to change the position
transform.position = Vector3(1,2,3); << This tells the computer we are going to move the object to the co-ordinates 1 unit left, 2 units high, and 3 units right.

Does this help?

To the person above me, your terminology is slightly out.

void does not say you are defining a method (function). void is saying that there is no return type required (null). You could easily do:

IEnumerator Start() { } which returns the the type IEnumerator. This requires a yield return.

You could easily do: bool MyMethod() { return false; }

These are still methods (functions)!

The () next to a method are paramater brackets, ie they can be empty (no paramaters) or with paramaters, ie:

Vector3 GetDistanceBetween(Vector3 a, Vector3 b){
return a - b; //Not sure if valid, but its an example :smile:
}

Just needed to clear these things up :slight_smile:

Forget about designing something new “exactly right” before you have started programming it… that’s not going to happen, all you’ll do is convince yourself that you’re never ready to code anything.

If it’s something relatively standardized, that has been done before, you can get some initial design ideas by looking at examples.