Am I allowed to ask the professor questions after failing multiple times on my own?

Feel free to make some jokes, even I can see how comical this is becoming haha. (Abbot and Costello anyone?)

Parameters can be used for passing information in / out of a method, I would suggest in most cases where I have used them it’s normally inbound.

Here’s a little example you can pop into a scene really easily…

void Start()
{
    string message = "Hello from the console!";

    DisplayMessageToConsole(message);
}

private void DisplayMessageToConsole(string message) 
{
    Debug.Log(message);
}

So, nice and simple this one. In your Start() method you have created a variable to hold a value, in this case its a string and it will hold a message that we want to display to the console.

We have a method DisplayMessageToConsole() which we can use for just this purpose. As you can see it has a parameter of Type string, I have named this parameter message but it could be called anything (keep them relevant to what they are though is a good idea).

This method just makes a call to Debug.Log() to display the text, in fact, Debug.Log() is doing exactly what our DisplayMessageToConsole() method is doing, it too is just taking in a parameter.

So, when you have this working, change some bits. Change the value of the variable in the Start() method to say something else. You will see that you don’t need to change your DisplayMessageToConsole() method at all and you can have different text appearing.

You could do the same for other data types also, int, float etc…

Regarding void, void is a type as well, but when used with a method it states that nothing will be returned. Again, an example;

private void HelloWorld() 
{
    Debug.Log("Hello World!");
}

The above method is referred to as a void because it doesn’t return anything to the statement that may have called it, you may have used this in the Start() method for example like this;

void Start() 
{
    HelloWorld();
}

Another example of a method that does return something could be this;

private int Add(int firstNumber, int secondNumber)
{
    int total = firstNumber + secondNumber;

    return total;
}

This time instead of void we have stated the method will return an int, the method in this case takes two numbers and adds them together, returning the total. We can use this from our Start() method like this;

void Start()
{
    int total = 0;

    total = Add(2,2);

    Debug.Log(total);
}

So in this case, we define a variable total and set it to equal zero. Then, we say that it equals the result of the Add() method. I passed in two numbers (2 and 2), the method adds them together and returns the result. I then output this using Debug.Log() - equally, if you still have the DisplayMessageToConsole() you could pass this is by saying;

void Start()
{
    string message = "My total is : ";

    message += Add(2,2).ToString();

    DisplayMessageToConsole(message);
}

The only thing I’ve added is a ToString() to the end of our Add() method, so that it converts the result, which was an int to a string before concatenating it to our message variable.

Hope this helps and the best way to really see what this is doing is to paste the above in step by step into a script in a basic scene and give it a go :slight_smile:

1 Like

Hey @ninjachimp
So I finally had some time to play with GitHub… still very confusing but I think I managed to get a bit of the basics down… maybe.

So, I made a Repository folder on my computer, then created a Repository in GitHub.com(+ 1 Readme file), I added TextController.cs file and the Game.Unity file(in case it was needed). Then cloned/copied the repo, and after youtubing a few videos, learned to use the terminal to add my repo clone to my computer (the video explained how using the GUI apps is frowned upon at companies- and not that I think I’ll be able to get a job coding anytime soon- I figure to try it this way (It was fun, reminded me of the Commodore 64 and DOS days) and get practice in the field in case an opportunity should arise.

I opened the GitHub Desktop app (since now I was sort of lost at what to do next) then opened the repo on GH.com

I wanted to practice with the program, so I tried making very slight changes to test out if what I did worked, and I found it to be half and half:

I edited the ReadMe file on the website- then did a pull request (unsure why, but after hitting many brick walls, this seemed to be the only loose brick lol) I finally saw a change on the github app and then decided to merge on the website. (unsure if what I’m doing is good or not, it was better than just staring at a screen that would not change- so I feel progress Was made.)

I saw these changes being listed on the GH app- but I feel I am still fuzzy on GH’s purpose. Is it JUST for updating and sharing files/projects? Im not meant to do any editing at all with the GH app - just to view branches (when I fully understand that concept)?

So anyway, after merging the branch into the master, I was confused as to why my files on my computer havent changed, then I realized that the initial cloning was prior to the editing readme file. I would have to download the zip file (or re-clone?) the way I did with terminal- but I feel that would give me overwrite errors (so I assume that is a no-no).

So now that I have my first repository, does this mean, now, that if i have any issues- I just upload/update the file associated with the repo in github and sync it with the desktop app?

This is the area that I have lost complete control of whats going on.

(I wish i had other quiestions, but this was all I could accomplish in the meantime.)

Thanks again, in advance, still working out the switches and the sort but I figured I can’t get help easier until I figure out github.

-mne

The basic flow with git is:

  • Before you start work, PULL the latest code from the remote down to your local repo
  • do your work locally
  • COMMIT your changes to your local repo
  • PUSH the changes from your local repo to the remote

It gets complicated with branches, pull requests, merging etc but for a one-man team, the above is all you need initially. You shouldn’t need to open the GitHub website once you’re set up - it is possible to edit files directly there, but the idea is that you can work locally, pushing your work to the remote at GitHub when you’re ready.

I would definitely use the GUI clients at first to help you get a grasp on the concepts. There is some elitism about command line, and in many cases it is more efficient than GUIs, but there’s absolutely nothing wrong with using the clients to simplify things for yourself and visualise how everything is set up.

For a single developer, Git is useful for:

  • backing up (source code is hard to replace if lost)
  • tracking old versions of code, so that you can revisit previous versions or wind back something
  • easily sharing your project with others
  • trying out new things in a branch, without affecting your master code stream
  • tying commits to specific bugs or features, for forensic debugging

It’s hard to codify all of the benefits that Git brings, but take it from someone with 18+ years of software development, it will save you someday.

Cool, so from here, if I am working with the most up to date version of the code, I do my work- save my work- then through the desktop app I would commit the changes (I guess in this case the new .cs file?)- then use the push option in the menu and it will sort of give me check points in my work process. Did I understand that correctly?

Correct. Here’s an example, the repository for my game Freezo Run. You can see all of the files that were added (the + symbol) or changed (the … symbol) in the latest commit, and how the commits have stacked on top of each other.

You can also see that when I was trying out integrating stomt with my project, I did that in a branch. Without Git I would have had to back out all those changes, and my code would have been broken until I did. With Git, I simply left the bad code on the 004_Stomt branch and continued on with my working code in the master - and the Stomt branch is there if I need it later.

1 Like

Privacy & Terms