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

Hello Ben, Ive been taking your class for about 10% of the content (id say a week, but its been a lot longer, it feels… maybe two)

I think I’m at the end of the Text|101 class, and I believe the next step is learning how to upload it… but I feel like I am an eternity away from that goal.

I rewound and replayed the videos over and over to find that I still feel like im missing something important.

Without further ado, I would like to present my issue. I’m sorry if its messy and unruly. I tried to keep the ship running tight, but after many attempts and googles and stack overflows and msdn (the c# website) I have reach my wits end.

Here is my current code… (brace yourself, I’d say pun intended, but I’m not sure I would understand why it would be funny, lol)

http://pastebin.com/tkub28JR

I have been speaking back and forth with a Mr Rob Meade. He was tremendously helpful, I just wish I could grasp what he was trying to teach me. With every reply it sounded promising, like it was the answer. Then, I would go and do it and feel more lost than before.

I think one of my problems may be that I’m not sure where I should be entering this code, or string of code.

I wanted to use the Input Field, but then when i did incorporate it (via unity, then MB), it was the only thing on screen. I had no game loading, just the SecurityPanel, which was pretty cool, except it felt out of place, as well as being just the only thing on my screen.

Rob suggested I “Hide” it until I needed to show it. I attempted to follow those directions, but then soon four myself with 300+ errors on my screen; needless to say I couldn’t test anything to see if it works as unity requires to fix all compiling errors (rightfully so!)

In the end I think the Switch statement was the true answer. But I STILL could not figure out where in the code to plug any of it in. If I placed it before the start function (thinking it is part of the initialization part (the part just after I state what I am “Using” such as Public Class, Public Text, Private Enum… etc etc" and apologies if I’m letting you down as a student, but I feel that after a week of trying to figure it out on my own I have gotten no closer. I feel like a pro with the if/else if statements, but I want to take my coding further.

I have “//” comment toggled the lines that have either caused an error in the compiler, or some code that i wanted to play around with (some of it at the very very end is just for testing, but again, am unsure where and how it fits in the whole puzzle.)

I also have something at the top called sprites[] and image as well as a link in the comments above. i was going to attempt adding some images to my game to spice it up a little. I have no even begun to mess around with I because I fear i might have a stroke with trying too many different things before figuring out the syntax or system. If you have any suggestions for that task ahead i welcome any and all of them. If you think by the time I figure out the secureCode problems I have I should be fine with it, then Ill give it a whirl when that time comes.

Ill try this thing here:

Expected: I wanted to be able to allow the user to input a number such as 123, or 345, or 710(not letters/KeyCode) as a code to open the cell doors. If they failed they would be sent to a death state that I have set up.

Trials: As I tried many options(listed above) I failed at most of them, but i found that its very difficult to get MB (or unity?) to understand that i need numbers (or int?) not letters for a securityCode.

What Happened: A mess that is the the thread i linked above.

I think you are in Europe, which means its about 9AM there. It isn’t of absolute importance that I finish this assignment ASAP, but the sooner I do finish, the sooner I can give myself headaches with the block breaker class (which I’m excited about, hoping it will be clearer for me by then…)

((PS: the link to gamedev.tv also has links to the previous pastebin link used show what my MB code looked like then.))

Hi, I wish I had time to answer individual queries. I hope you don’t mind but I’ve moved this post to the #unity:S03-text101.

Perhaps one of the @moderators could start the ball rolling on helping you out?

HI @mnemonicon,

I am sorry to hear things haven’t yet quite worked out and I will be happy to help further if you would like?

The project that I put together for you in the Gituhub repository was a fully working example of how you can handle the InputField code, did you download that and give it a try? I don’t mean just looking at the code but actually running it so you can see what each part of it is doing? If not that would be a good place to start.

The reason for putting the little example together like that, was because I didn’t want to just grab your code, make a load of changes to it and leave you in a whirlwind wondering what had just happened, I don’t think you will learn anything that way, but perhaps I needed to explain in more detail or differently, so, if I have brought you close to stroke, please accept my apologies :slight_smile:

Where and how would you like to approach resolving this? Would you like me to make changes to your project so that it does what you want, or, from a clean version of Text101 (say the downloadable version at the end of the section on Udemy) walk you through each of the steps?

Let me know, and if you want to, we can go from there - equally, if you would prefer to get some help from other people I won’t be offended :slight_smile:

Its actually the exact opposite, I feel really bad that I keep bothering you about this problem, and that I don’t fully understand why what I am doing is wrong, it is all still very confusing to me, I’m actually surprised I did as much as I did already. Over the past few days since you’ve sent your very generous replies, I was actually attempting to place them into my code (in addition to the procedures done in Unity) but every time I attempted it, it would riddle my code with errors(the most I saw was like 380-something.). But I digress. I haven’t tried all of the options you posted yet- which is why I haven’t replied. I didn’t want to just ask for an answer if I haven’t even really given it a try- except after what felt like a week of non stop reading and youtubing- I had the thought to ask the professor of the class. (I imagined it was like a class, so I figured to give it a go, especially since hes teaching, I figured if I’m not getting it maybe he could explain it a different way or something. And obviously, I was asking a bit much from someone running a course of many students) I’m not offended by anyone’s actions. And I actually like the way you explained things Rob, I am just - I dunno slow to learning this syntax I guess. I started at number wizard twice already, just to make sure I’m getting the concepts a little more solid. I still don’t see anything that will show me how to do the thing I want it to do, but if i get the basics down, then the answers you gave should be stop on. (When I read and see it on your screen I feels like it makes sense, but until I even know what a class is, and why its different from a function, I didn’t want to take more time from you (that is until I even had something to show for what i was doing)
Now, to make this response even longer, lol. I haven’t had time to sit with the code yet today (and computer froze, so I lost a bit of what I changed) But I’ sure I’ll get it. Its making more sense every time I have to fix an error.

Thank you both, and I’ll be back :slight_smile:

1 Like

Hi @mnemonicon,

This is a long post, sorry…

Its actually the exact opposite, I feel really bad that I keep bothering you about this problem

No need to feel bad at all, I enjoy helping people on the forum and it’s nice to be of use :slight_smile:

I’m actually surprised I did as much as I did already

So, that sounds like something to be very proud of then :slight_smile:

I am just - I dunno slow to learning this syntax I guess.

Everyone will have a different pace to on-boarding new information and I would say that what you are doing is spot on, you’ve got to a point where something isn’t quite making sense, so you have paused until you can work it out - much better in my opinion than ploughing on through and perhaps getting to a stage where you needed to already know this bit to do the next bit.

It often also takes a degree of courage to effectively put your hand up and ask a question, especially on a forum where you present your question to everyone, or at least feel that you are. The thing I normally remind people is that for every one person that has the courage to ask a question, there may be 10, 20 or a hundred other people that actually wanted to know the very same thing but hadn’t quite mustered the courage to ask yet - so potentially, any question by anyone I feel has a lot of value for the community :slight_smile:

I didn’t want to take more time from you

It’s absolutely fine, I am on here most days and do what I can, if I am wrapped up in something else and can’t respond straight away I always try to get back to people as soon as I can - it’s my responsibility for how I spend my time, so not something you need to worry about :slight_smile:

but until I even know what a class is, and why its different from a function

Well, lets tackle that now then, at least with enough information to get you started :slight_smile:


Try to think of a class as a template or a cookie cutter. You define what your thing going to look like but it’s only a template, it’s not the actual thing (or a cookie!) at this time, but you can use it to create a thing . We call what it creates an instance, e.g. an instance of the thing.

Within the template (class) you will most likely define so items to store some values within the instance, we typically call these fields (you’ll see them referred to as class or members variables also). We may also want to expose some / all of those fields, a good practice for this would be via Properties, which allows us to not give direct access to our fields. Our template (class) will most likely also define some behaviours, e.g. what the thing can do, these behaviours are often referred to as methods (functions is also another term but there are some subtle differences which we can cover later).

So, that was all a bit generic, lets talk through a better example. Just for now, we’ll forget about Unity and just talk generically. We’ll have a real world example, something easier to relate to :slight_smile:

We’ll create a class called Car.

public class Car {

}  

There you go, that’s it. Bit boring. Doesn’t really do anything, but we have a template for a Car object. At the moment it isn’t an instance, e.g. there is no Car object, we’re just defining what a Car will look like. This is our car cookie cutter. All Cars will currently look the same.

But cars are not all the same, so, lets expand our class a little bit in order to add some variation;

public class Car {

    // fields
    private int _numberOfDoor = 2;
    private int _numberOfWheels = 4;

}

I have added to private fields (class level variables) which can hold some information. Lets break each of these down so we know what they are doing.

Firstly, they have both been set as private, this is what is called an Access Modifier, it determines the scope of the item and it can be used on classes, fields, methods etc. In this case I have set them both to private which means nothing outside of this class will be able to see / access them.

The next part is the int, this is the Type, just as we are defining our own Type called Car, C# (.Net) has lots of Types that we can already use (int, string, bool etc), int is an abbreviate for Integer, thus, a whole number. Why did I choose an int? Well, our Car is going to need some wheels, and they will be counted in whole numbers (we’re not having half a wheel!), the same applies for doors, we will want at least 1 to get in!

Next is the name of the fields, you may wonder why when I named these fields I placed an underscore in front of them, literally, personal preference. It’s a naming convention I use when I declare fields (class level variables) and this makes them very identifiable when I use them in my code later on. You don’t have to do this, but it is worth sticking to whatever naming convention you use when programming consistently throughout your code, it just makes things easier for you (and anyone else who has the pleasure of reading your code).

Finally, I set the initial / default value of these fields, 2 doors and 4 wheels.

So, we now have a class called Car which, when we create an instance of Car we can store some information relating to that car in it, but we don’t have a way yet to create an instance. Lets expand it a bit more.

public class Car {

    // fields (class level variables)
    private int _numberOfDoors = 2;
    private int _numberOfWheels = 4;       

    // constructor
    public Car() {}

}

Our constructor is public, which means anything else will also be able to see it, e.g. other code / software libraries and so on.

So how do we create an instance of our car? Well we will need something to be our instance, an object, so lets create one and call our constructor;

Car aCar = new Car();

  • In the above line, first we specify the Type for our variable, as per the int earlier, Car is a Type because we have defined it with our class.
  • Next, we give our variable a name aCar, this can be anything you like, aCar, myCar, fastCar, fred - it really doesn’t matter, although it is best to name things in a way that makes sense, again, this makes things easier later.
  • In C# constructors have the same name as the class, and the new keyword is used to invoke the constructor.

Ok, at this point we would have an actual Car object, an instance of our class, it would be called aCar in our code and that is how we could then reference it’s properties and behaviours. But at the moment it doesn’t have any properties, and it doesn’t have any behaviours and the two fields it has are not accessible because someone set them as private!

Lets make these values accessible by adding some properties;

public class Car {

    // fields (class level variables)
    private int _numberOfDoors = 2;
    private int _numberOfWheels = 4;       

    // constructor
    public Car() {}

    // properties
    public int NumberOfDoors
    {
        get { return _numberOfDoors;  }
        set { NumberOfDoors = value;  }
    }

    public int NumberOfWheels
    {
        get { return _numberOfWheels; }
        set { NumberOfWheels = value; }
    }

}

Above you can see that I have added two properties, one called NumberOfDoors which corresponds with the field _numberOfDoors, and likes wise, NumberOfWheels which corresponds with the field _numberOfWheels.

Within each property you will see there is a get and a set, these are accessors which enable us to retrieve a value from the property, or, push a value through our property.

In both cases for the get you can see that we return the corresponding field, so, whatever the value of either doors or wheels will be returned when this property is called. Equally, we could set the number of doors or wheels using this property. Typically it is best practice to not add the set accessor initially, just keep your properties for read only access to your fields and only expose your fields when you really need to.

Examples of using the properties;

Car aCar = new Car();
int wheels;

wheels = aCar.NumberOfWheels;

In the above, we create a new instance of our Car, this is called instantiating. I have also defined a variable called wheels. I then populate wheels with the value of numberOfWheels which is returned from the get accessor of the NumberOfWheels property.

This is a bit of a nodding example as I am populating another variable to show it’s use where as you could just use this in some logic, or displaying to the screen or whatever.

Another example, this time for setting the value;

Car = aCar = new Car();

aCar.NumberOfWheels = 3;

In the above example we instantiate our car object, aCar, and we then set the numberOfWheels field using the NumberOfWheels property via it’s set accessor.

Woah! A three wheeled car!

Lets expand on our car again and give it a state for it’s engine, we can use an enum for this, you will be familiar with both states and enums from the Text101 game, we will also give it a speed and set it’s default state when our object is instantiated;

public class Car {

    // fields (class level variables)
    private int _numberOfDoors = 2;
    private int _numberOfWheels = 4;
    private int _engineState = 0;
    private float _speed = 0f;   

    // enum
    private enum EngineStates { Off, Idle, Accelerating, Decelerating };  

    // constructor
    public Car() {}

    // properties
    public int NumberOfDoors
    {
        get { return _numberOfDoors;  }
        set { NumberOfDoors = value;  }
    }

    public int NumberOfWheels
    {
        get { return _numberOfWheels; }
        set { NumberOfWheels = value; }
    }

}

The EngineStates enum has been set to private as I will only be using this within our Car object, not outside, for now at least, again, try to code defensively, e.g. if things don’t need to be accessible initially, don’t set them to be accessible initially, increase the scope as required or redesign etc.

I’ve added a private field _engineState which will hold the current state of the engine. I have also added another private field speed which is going to store our car’s current speed.

As you will see, our fields are starting to build up and we are setting quite a few default values there, I’m not a big fan of coding this way and personally prefer to use a method (behaviour) which will be responsible for setting the objects default state.

Additionally, in our current example, I have set the _engineState field to equal 0, I can do this because it is an int, but I couldn’t, for example, set it using our EngineStates enum because until our car has been instantiated our enum wont exist.

So I can’t have private int _engineState = EngineStates.Accelerating; for example

So, we will expand our class again but now add some behaviour (a method) for managing the default state of our car when it is instantiated;

public class Car {

    // fields (class level variables)
    private int _numberOfDoors = 2;
    private int _numberOfWheels = 4;
    private int _engineState = 0;
    private float _speed = 0f;   

    // enum
    private enum EngineStates { Off, Idle, Accelerating, Decelerating };  

    // constructor
    public Car() {
        Initialise();
    }

    // properties
    public int NumberOfDoors
    {
        get { return _numberOfDoors;  }
        set { NumberOfDoors = value;  }
    }

    public int NumberOfWheels
    {
        get { return _numberOfWheels; }
        set { NumberOfWheels = value; }
    }

    // behaviours (methods)

    // Initialises the instance of our object
    private void Initialise() {
        _numberOfDoors = 2;
        _numberOfWheels = 4;
        _engineState = EngineStates.Off;
        _speed = 0f;           
    }

}

We now have our first behaviour (method).

I have set it to be private because again, it only needs to be called (at the moment) from our car instance.
It is defined as void because it doesn’t return anything to the calling statement.
I’ve given it the name Initialise, again, this is personal preference, I tend to use the same name for all of my initialising methods, it could just as easily be called “MakeCar” but worth naming your method to something that makes sense from the perspective of that object.

Within our Initialise() method I now set all of our fields, and now can use our EngineStates enum because we have an instance of car. How did we get an instance of the car? Well, if you look at our constructor you will see that I have added a call to the Initialise() method with it. So, when ever our Car class is instantiated, Initialise() will be called, it will now have an enum which we can use.

You would still instantiate it the same way as before;

Car aCar = new Car();

I am conscious of the length of this post, but, hopefully I have broken each part down into small enough chunks that it isn’t too overwhelming. We’ll do just a little bit more and then stop.

I would really like to make this car “go”, making the car move is a behaviour, in the real world you would have behaviours also, a driver would open the door, seat in the seat, fasten a seat belt, turn a key and so on. We will deal with just what the car is going to do from the perspective of the key and two peddles.

A key turning in the car will have the following behaviours; StartEngine, StopEngine, for brevity we will assume that a drive has been sensible and reduced the speed to zero before removing the key!

Expanding our code again;

public class Car {

    // fields (class level variables)
    private int _numberOfDoors = 2;
    private int _numberOfWheels = 4;
    private int _engineState = 0;
    private float _speed = 0f;   

    // enum
    private enum EngineStates { Off, Idle, Accelerating, Decelerating };  

    // constructor
    public Car() {
        Initialise();
    }

    // properties
    public int NumberOfDoors
    {
        get { return _numberOfDoors;  }
        set { NumberOfDoors = value;  }
    }

    public int NumberOfWheels
    {
        get { return _numberOfWheels; }
        set { NumberOfWheels = value; }
    }

    // behaviours (methods)

    // Initialises the instance of our object
    private void Initialise() {
        _numberOfDoors = 2;
        _numberOfWheels = 4;
        _engineState = EngineStates.Off;
        _speed = 0f;           
    }

    // starts engine
    public void StartEngine() {
        _engineState = EngineStates.Idle;
        _speed = 0f;
    }

    // stops engine
    public void StopEngine() {
        _engineState = EngineStates.Off;
        _speed = 0f;
    }

}

StartEngine() is a method which is responsible for starting the car, as such, it sets our engineState field to an appropriate value Idle. We don’t necessarily need to set the _speed to zero here, as we have already done that in our Initialise() method, but that assumes someone using are class will be sensible! We are making assumptions that they would call StartEngine() after Initialise() and not whilst the car is perhaps driving! What this will do is certainly draw attention to what is hopefully a mistake, as the car would stop and be idle but these are some of the things you may need to think about during your design. You could add some logic to only set the engine to Idle if it isn’t already running and so on, but we will just keep this simple for now.

StopEngine() is a method which is responsible for stopping the car, as a such it sets our engineState field to an appropriate value Off and sets the speed to zero. That makes sense, but again, it makes sense if we think about it in the order of “create a car, start the car, stop the car”, what if someone tries to turn it off whilst its moving?! Again, that’s something for another day :slight_smile:

Both of these methods have been set as public because we would want other code to be able to access them, for example;

Car aCar = new Car();

aCar.StartEngine();
// brrrmm... brrrmm
aCar.StopEngine();

Ok, lets get this thing moving! Our real world car has an accelerator and a brake, so those behaviours can also be modelled in our class;

public class Car {

    // fields (class level variables)
    private int _numberOfDoors = 2;
    private int _numberOfWheels = 4;
    private int _engineState = 0;
    private float _speed = 0f;   

    // enum
    private enum EngineStates { Off, Idle, Accelerating, Decelerating };  

    // constructor
    public Car() {
        Initialise();
    }

    // properties
    public int NumberOfDoors
    {
        get { return _numberOfDoors;  }
        set { NumberOfDoors = value;  }
    }

    public int NumberOfWheels
    {
        get { return _numberOfWheels; }
        set { NumberOfWheels = value; }
    }

    public float Speed
    {
        get { return _speed ; }
    }

    // behaviours (methods)

    // Initialises the instance of our object
    private void Initialise() {
        _numberOfDoors = 2;
        _numberOfWheels = 4;
        _engineState = EngineStates.Off;
        _speed = 0f;           
    }

    // starts engine
    public void StartEngine() {
        _engineState = EngineStates.Idle;
        _speed = 0f;
    }

    // accelerate
    public void Accelerate(float speedIncrease) {
        if (_engineState != EngineStates.Off) {
            _engineState = EngineStates.Accelerating;
            _speed += speedIncrease;
        }
    }

    // decelerate
    public void Decelerate(float speedDecrease) {
        if (_engineState != EngineStates.Off && _engineState != EngineStates.Idle) {
            _engineState = EngineStates.Decelerating;
            _speed -= speedDecrease;

            // car has stopped
            if (_speed < 0) {
                _speed = 0;
                _engineState = EngineStates.Idle;
            }
        }
    }

    // stops engine
    public void StopEngine() {
        _engineState = EngineStates.Off;
        _speed = 0f;
    }

}

Ok, we’ve added a few more parts now. Two new methods; Accelerate and Decelerate, both public so that they can be accessed outside of our object, both voids because they do not return anything and both will take in a value through their respective parameters. A Type is defined for the parameter in both cases, float as this is used for our speed, and then a name for the parameter, speedIncrease and speedDecrease respectively.

We have also added a bit of logic to these methods;

Accelerate checks the current state of the engineState field, if it is anything other than Off we can accelerate - kinda makes sense. We then set its state to accelerating and increase _speed by the value of the parameter (speedIncrease) which was passed in.

Decelerate checks the current state of the engineState field to see if it is anything other than Off or Idle, as in both cases it wouldn’t make much sense to be able to decelerate. Again we change the engineState and decrease _speed by the value passed in through the speedDecrease parameter.

We also do an additional check in this method, we test to see if _speed is less than or equal to zero, if it is, the car has stopped, so we change the _engineState to Idle and also set the speed to zero (this caters for someone constantly breaking and making the speed negative).

Now, this is a great opportunity to point out refactoring, e.g. changing your code to make it better and more streamlined. That last if statement in the Decelerate() method could really be a separate method in it’s own right, as there may well be other times we want to check to see if the car has stopped, for now, I will leave it where it is because there isn’t, I would probably also want to make it a little more generic and check things like the current engine state also, but if gives you an idea as you can see that method has started to grow more than the others and this can be a good indication as when to refactor.

So… you have a Car class (template / cookie cutter) which you can use to create an instance of, through its constructor. You can use its properties to both get / set its fields. And you have given it some behaviours (methods) for starting and stopping the engine as well as accelerating and breaking.

The above model isn’t obviously a perfect model of what goes on in a real world car, but I hope what you can see is that you can start very small, as we did with;

public class Car {

}

…and turn it into something much more, fairly simply.

I hope the above helps to cover some of the basics for the things you weren’t too sure about, classes, methods etc.

For practice, take a look around you at some real world objects and see if you can use a simple approach like the above to recreate them in code. A bookcase (width, height, depth). A wall (number of windows, number of doors, colour), a shape (width, height, area), a person (name, age, gender, height, weight, eye colour) - some examples…

If there is anything which isn’t clear please do ask and when you are ready let me know and we will take a look at get that door to open with your security code :slight_smile:

2 Likes

I am currently reading this post. Already I feel my understanding of the language round out a bit. I will respond. Enjoy the time off from me haha! (And thank you, again for all the time you spent into this)

1 Like

Let me know if you have an questions or want any other examples, and/or when you want to look at the security code feature in your game together.

Hmm, okay, so…

Ignoring lines 1-3 for now, I’m to understand it is directly connected to the program Unity. If I was using VisualBasic or I guess even Console, they’d be titled differently. (I think)

Line 5 is a class (you call it cookie cutter, MSDN calls it struct?, I think I understand it as the object that needs describing, my blank canvas so to speak)

My object in this case is what we made in Unity called the TextController. When I hit play in Unity it will ask “Where is TextController?” and then the C# script will be loaded, which is the code all in the curly braces of TextController.MB {*}

Because I only have experience with text based(and your car example) it still feels a little abstract, but its okay, lets just keep going with this for now.

Lines 7 is a field, that is publicly available (meaning its accessible all the time to the program/user?), and is of the variable type Text(green) henceforth known as text(white), whenever (later in my code) use the word text.text it will be calling upon this part of the code?

Lines 10 and 11, while I have not even begun to research how to add images every screen, I imagine it to be in the same vein of text.text “*”, where at each state i can call upon a certain image or sprite (that I will have to upload to my assets folder in Unity?)

public Sprite sprites;

The in Sprites is throwing me off. Does a list go inside in a similar fashion as the private enum classes? (An explanation of this i don’t think is necessary, I don’t want to get more confused at this point, I would like to tackle this after, unless its unwise, which is why i mention it at all) (maybe unrelated- I keep reading Strings and Arguments are in , perhaps this is something, but I am doing what i can to stay focused on baby steps)

Line 13 is a list. The list is of the type States(green), and they are like the library of the various states the user can enter depending on state function and user input. (I feel this is the most easily understood part of the programming in C# for me.)
(enum just short hand for enumerated, or listed)

private enum States {Insert list here, items separated with commas};

Line 21 is also listing a class (which will be held private… you say “which means nothing outside of this class will be able to access/see them.”… the Class States(green) which is labeled/described as myState(white) cannot be accessed by anything outside of the class myState.

on Line 24

void Start(){
text.text = “A game about getting out.\n\n\n” +
“Press X to begin.”;

if 	(Input.GetKeyDown (KeyCode.X))		{myState = States.cell_0;}

}

I have void Start (){}, which denotes that when my program starts (when I hit play in Unity)

void is a keyword that means the program returns nothing. I understand the concept of giving the user nothing, but then later on the states and various text will say void myState(){}(whichever state is currently on screen) and so my confusion starts, if the program is to return to the user with no information(void), how is it that we are describing these states in the void with information that will be shown on screen? Currently I am just accepting it as law, something I may not understand but that I must follow.

The start, as I understand, is where the code begins to start the game. It will take all the information we listed and wrote in and compile it in the proper order and spit out the correct info based on user input. When the Game starts it calls for input at the start and then runs the update function.

On Line 25 I use text.text to call upon the previously described class of Text in the TextController (I really hope I’m close to understanding this correctly) and then it will print on the screen the string of words I put in the parenthesis “A game about getting out.\n\n\n + Press X to begin”. HERE is where logically my brain tells me "Well, its the beginning of the game, if the user wants to start they have to press X. And what better way to show this than with an if function. So I put the function (like I did when detailing the states below), my code builds successfully and i try in Unity. I don’t need to tell you it didn’t work, because I realize that the Start() function is only ran once, at the very beginning. And for some reason** it won’t accept any input, so I attempted to put it in the very beginning of the Update() function, and voila!, X starts you off in cell_0!- mini victory! except not at all, because I realize that EVERY frame the game will see what the user inputs, so if X is pressed, regardless of what frame(state), it will always put the user back to the beginning. This is an excellent way for my to drive my player insane, never being able to reach the end without pressing x, even if accidental.

The update(), every frame will print (myState)(white), so it will show me, on screen in print/text, whatever text is associated with the States(green) corresponding to the private enum States(green) and the functions I attach to them (such an an if, else if, else, or I suppose even switch? (which is another function, I think, that allows multiple outcomes based on user input?) (again, this point is probably too complicated for me to grasp just yet, So far I feel like I have learned a great deal, but am still jumbling terms. I will continue reading and rereading your post until it makes more sense.

I will continue from here after I understand this much of it. lol.

http://pastebin.com/tkub28JR (the current paste if you want/need to see the rest of it thus far.)

Hey @mnemonicon,

If you are looking to get help or advice from a fellow student - then give me a yell. Like if you have some code that you want someone to look over then I am more than willing to try and help. And I’m very good at finding bugs :grinning:. Unlike @Rob though I am not a code jockey. But two heads are better than one. Like, for instance, in the last game Number Wizard UI - I managed to put in a Input field where the user could type in a number. It took some reading on Forums and re-reading the Unity docs a number of times to get it functioning but it did work in the end - you type the right number in a certain number of guesses, hit the submit button it goes to the “Win” Screen.

I’m always adding things to the stock project and feel like I can’t submit something if I don’t think have a feature that I think is necessary. For instance, in the Block Breaker game I added a powerup which gives you the ability to shoot blocks. But I can’t submit it because I think it’s absolutely necessary for me to have the ability to spawn enemies like the original did and I want to have the multiple balls thing like the original until then I won’t consider it finished. And so moved on to Laser Defender.

So, feel free to hit me up.

Regards,
Vaughan.

1 Like

Hey @Vaughan_MacEgan Thank you for checking in on me. Please, be my guest, feel free to read the history of my learning process. My latest post is I am up to.

Thank you!
mne

Also: I just stumbled upon this. http://scottlilly.com/learn-c-by-building-a-simple-rpg-index/lesson-01-1-defining-classes-and-objects-for-the-game/ and so far it isn’t super confusing. I am now using this in conjunction with what Rob explained to me. Lego bricks in my brain are starting to click together a little.

2 Likes

One thing that would help the community greatly to help you @mnemonicon is if you could review this lecture: https://www.udemy.com/unitycourse/learn/v4/t/lecture/3463876 and share your projects on GitHub.

That allows us to download your entire code and see the errors for ourselves, which makes assisting you much easier than doing forensics on snippets that are posted on the forum.

Controlling your projects with Git is a fundamental of software development, and it’s well worth learning. My 11 year old is in the habit now of using Git for every line of code he writes, and it’s a very useful habit.

2 Likes

I made an account, I started a new repository and at that point it became so much new information that I’m starting to feel overwhelmed. I do need the help, learning a new system and program to share in this some what complex way… I thought pastes from pastebin were good to use? If I need to use github to be able to get help then I prob have a whiles to go. (also I have not reached that lecture in the class yet. I have not started block breaker. I really want to get this text adventure down, before I start anything new.) I wish I had the same smarts as your 11 year old then, lol. Anyway, no more BSing, I have to get back to understanding all this explanations and examples.

Thank you for the suggestion, I am sure I’ll be able to make use of it in the future.

1 Like

Fair enough, I know the learning curve is very steep.

There is a good step by step guide here https://unity3d.com/learn/tutorials/topics/cloud-build/creating-your-first-source-control-repository which uses BitBucket rather than GitHub, but it’s effectively the same.

2 Likes

Just downloaded github for mac, rather than read up on classes and functions, I can fully say I have confused myself stupid lol. I can always retry tomorrow.

Always trying,
mne

1 Like

Keep at it mate, one day it will just click.

1 Like

Just downloaded github for mac,[…] I can fully say I have confused myself stupid lol.

The way you phrased that made me chuckle, but I remember using Git for the first time and that soon wiped the smile from my face :slight_smile: I came from a background with a different source control system. What I did find useful however was this course on Udemy;

…it’s free, and the instructor was quick to answer my questions which was really appreciated. He does a range of different Git courses but this was enough to get me started with the basics and be up and running in a day. It focuses mainly on using the command line for typing in everything, I took one look at that and figured someone would have made a client! :slight_smile: I currently use GitKraken, which is incredibly aesthetically pleasing and also offers a free version for non-commercial users. It is available on multiple platforms including Mac;

rather than read up on classes and functions

tut tut! :wink:

I can always retry tomorrow. Always trying,

That’s the spirit… plenty of time and loads of help available.

Out of curiosity, where are you with wanting to have a go at that security code input at the moment? I’ve not lost sight of your request for some help with it but was pretty much waiting for you to come back to me after me Tolkien-esq post on classes/methods :slight_smile:

1 Like

Hey Rob,
Without getting into a very long personal story, my work schedule is literally insanity. I could have no work for weeks, then have weeks of work in two-three days, which would wipe me out for the remainder of the week. When I say I’m reading, i mean like when i have some moments of being awake, I come to GameDev.tv and read your post (over and over) as well as google/search terms and examples. I literally cannot wait to get started on the security code- But if I still haven’t figured out how to get X to start my program (and not just reset the game every time X is pressed) then I think I am still missing enough of the core concept of coding that I couldn’t possibly understand the security code part. I will check into these free tutrotials for Git at some point this weekend.

By what I can see, it appears Git sites are like a team-based Acrobat Reader for code? Where you can post your file, and there is always a master, but can be edited (if allowed) and then commented on. Still very hazy, but that’ll clear up with, I’m sure, with these online classes.

1 Like

Hi,

Absolutely no problem at all, I’m here as and when, I just didn’t want you to think I had forgotten about it, that was all. So there’s no pressure, just give me a shout when you’re ready.

Git is a source control system, Github is a service which provides online repositories, e.g. the place where you store you source code. Each time you make changes to your code locally you can commit those changes and Git keeps a record, so, if you try some new functionality out but it goes horribly wrong (we’ve all done it!), you can get back to a previous revision, in fact, any revision which you have previously committed.

Additionally, you can enable these services to be either private or public, GitHub offers a free service for public repositories, so when it comes to something that is challenging and you want to get some help, you can point people to your repository where they can then download a copy of what you have, this is invariably a lot easier if the problem is a complex one than having little fragments of code provided on the forum, or screenshots etc (although that typically works fine for more straight forward issues).

Hope this is of use and I will look forward to hearing from you in due course. Hope the work situation settles a bit and provides a bit more balance for you :slight_smile:

1 Like

Hey, i know This may be confusing because im pulling from a different thread, but it IS related to my long list of "wha?"
So on:

When you say

Parameters: from I think MSDN

In C#, arguments can be passed to parameters either by value or by reference. Passing by reference enables function members, methods, properties, indexers, operators, and constructors to change the value of the parameters and have that change persist in the calling environment.Jul 20, 2015

Does this mean that anything in the () when added/adjusted/used is a variable, something that can alter the DoSomething method?

Such as DoSomething(TypeThisMessage){}?


But originally my question was with void, You say,

So the only string I understand is the text.text string, and only because I know that strings go inside quotes. I can imagine the multitude of other strings to be used, but that isn’t in my knowledge base for now.

If I am to use a string, the program would return the string to the user? (whatever i put in the quotes?)
But if I had used void then nothing would be returned to the user?

What is IT, and where is IT returning WHAT to?

Privacy & Terms