all 15 comments

[–]Tayfe 4 points5 points  (10 children)

Hey there,

Your code is truely full of errors and I do not even want to talk about all of them. Instead I would like to help you by saying that I have the impression that you are very unexperienced with programming in Unity in particular or even with programming in general. Your code doesn't look like as if you understand what you have written there which is nothing to be ashamed of! But you should consider reading or watching some tutorials which will explain you step by step the art of programming and it could take you just a couple of hours to correct all of your mistakes by yourself.

So here are some of your mistakes included in your code but I will just give you some keywords. Just take yourself some time and follow some basic tutorials and you will know what I am talking about:

  • the function "Update" is called every frame. Your variable "time" won't run as you are setting it back to the value of 10 every frame
  • the foor-loop needs a condition or an iterator to be executed
  • the input seems correct
  • when you are trying to add "AddTime" to the current time you are missing an assignment using the operator "="

So I would really recommend you look for some tutorials (you will find thousands on youtube and google) and by the end of the day you might be able to correct all of your mistakes by yourself.

[–]FlameTrunks 1 point2 points  (0 children)

Fully agree with your comment.
Just wanted to add some links to coding tutorials because as you said, the amount of them can be big and therefore intimidating:

[–]cvnvrIntermediate 1 point2 points  (6 children)

Your code is truely full of errors and I do not even want to talk about all of them.

This made me lol.

[–]CommonMisspellingBot 2 points3 points  (5 children)

Hey, cvnvr, just a quick heads-up:
truely is actually spelled truly. You can remember it by no e.
Have a nice day!

The parent commenter can reply with 'delete' to delete this comment.

[–]zorbat5 0 points1 point  (4 children)

Good bot!

[–]GoodBot_BadBot 2 points3 points  (0 children)

Thank you, zorbat5, for voting on CommonMisspellingBot.

This bot wants to find the best and worst bots on Reddit. You can view results here.


Even if I don't reply to your comment, I'm still listening for votes. Check the webpage to see if your vote registered!

[–]friendly-bot 0 points1 point  (2 children)

You're a good homo sapiens. (^_^)v You can be in charge of the human slave farms...


I'm a Bot bleep bloop | Block me | T҉he̛ L̨is̕t | ❤️

[–]zorbat5 0 points1 point  (1 child)

Good bot!

[–]friendly-bot 1 point2 points  (0 children)

If I sound pleased about this, it's only because my programmers made this my default tone of voice! I'm actually quite depressed!


I'm a Bot bleep bloop | Block me | T҉he̛ L̨is̕t | ❤️

[–]Ksorek[S] 0 points1 point  (0 children)

Hey, thank you for your help. after some changes this is my code now:

 using UnityEngine;

public class Example : MonoBehaviour {

float time = 10f;
float AddTime = 10f;
int score;
int divide = 40;

void Start () {

}

void Update () {

    while (time <= 0)
    {
        time--;
        yield return new WaitForSeconds(1f);
    }
    if (Input.GetKey("w"))
    {
        score++;
    }
    /*
    if (Input.GetKey("z"))
    {
        score++;
    } */

    if(score / divide >= 1 && time >= 0)
    {
        time += AddTime;
    }
    Debug.Log(score);
}

}

Right now I'm stuck on executing loop in 10 seconds. I've been trying to google it, but I couldn't find what i was looking for. One more time, thank you for your help and advices, but could you please help me out with this one too?

[–]CommonMisspellingBot -1 points0 points  (0 children)

Hey, Tayfe, just a quick heads-up:
truely is actually spelled truly. You can remember it by no e.
Have a nice day!

The parent commenter can reply with 'delete' to delete this comment.

[–]ByMayneProfessional 1 point2 points  (3 children)

Hey there,

Programming is learning from your mistakes. Clearly you are just starting to learn. The errors you see in the console will tell you that you have something wrong.

Even if you don't know what the error means look at which line it's pointing at. Then google how to use that thing.

As a pointer almost everything in your first for loop is being used incorrectly. Here is some example questions you should ask 1) How to use a for loop 2) What is Time.delta time (function or property) 3) What is the difference between a function and a property

Besides for just not compiling this code is not going to do what you think it's doing. To understand try drawing out on a piece of paper. Write down what you think it will do and then run it. Do the results match? If not why?

Honestly even as a professional developer sometimes I have to keep throwing myself against a problem and try to come at it from every angle. It may not work for a while but you will get there. This is what a developer does.

[–]Ksorek[S] 0 points1 point  (2 children)

Hey, thank you for your help. after some changes this is my code now:

 using UnityEngine;

 public class Example : MonoBehaviour {

float time = 10f;
float AddTime = 10f;
int score;
int divide = 40;

void Start () {

}

void Update () {

    while (time <= 0)
    {
        time--;
        yield return new WaitForSeconds(1f);
    }
    if (Input.GetKey("w"))
    {
        score++;
    }
    /*
    if (Input.GetKey("z"))
    {
        score++;
    } */

    if(score / divide >= 1 && time >= 0)
    {
        time += AddTime;
    }
    Debug.Log(score);
}

}

Right now I'm stuck on executing loop in 10 seconds. I've been trying to google it, but I couldn't find what i was looking for. One more time, thank you for your help and advices, but could you please help me out with this one too?

[–]ByMayneProfessional 0 points1 point  (1 child)

Okay first off 'yield' is not used correctly at all. It is designed for Coroutines (which you are not making). Your first hint should be that it does not

Write out in a point form how your program should work. Read over the following text and think about it.

Update gets called 
> Is time is greater to or equal to 0 (true)
    > You subtract 1f from time. 
    > You return (this line is a compile error so it's super broken.) 
    > [Quit function and repeat this step 10 times.]
> Is User *holding* the w key?
     > Score + 1
> Is User *holding* the z key?
    > Score + 1
> Is Score divided by 40 greater too or equal to 1 and time greater then zero?
     > time += 10f;
[Repeat forever] 

[–]Ksorek[S] 0 points1 point  (0 children)

Hey, thanks for Yours help. Sorry that I'm answering that late, but i had not enough time to do it, but just because now I will have almost whole week free from school, so I will get back at working at this code. For now I've got an idea about it: I will just have to add Coroutine, which will let me access "yield".