Bug or I messed up?

Problem: after the very first click on either “it’s higher” or “it’s lower”, the script will pick a random number between 1 and 1000. Second, third click etc. it will behave normally.

Example:

Run game (scene 1). The script randomizes a number, 730. User clicks “it’s higher”, script guesses next number 321.

Once again, guesses 2, 3, 4 etc. work fine, the problem is specifically with just the first guess.

This seems to happen, because the min and max are defined as 1 and 1000 before the user clicks “it’s lower” or “it’s higher” for the first time.

If you look at the video 5:28 (when Rick clicks play) and he gets the number 535, if you look at the “Number Wizard (Script)” components min and max values in the inspector, they are 1 and 1001 before Rick clicks anything.

Does this not mean Rick has the exact same bug? (not reproduced in video by pure chance).

I skimmed over the code in git.hub and compared to my code, looks 1:1.

So did I mess up somewhere or is this in fact a bug?

That already doesn’t sound right.

Not sure I understand this. You’re saying the minimum is 1, the maximum is 1001 and when Rick started the game it gave a guess between those two values which was 535? Again, that sounds right to me.

If you’d like to share your project files I will be happy to take a look so I can play-test a bit too and understand the problem.

The forum will allow uploads of up to 10MB, if your project files (zipped) are larger than that you would need to use a service such as Google Drive or Dropbox, and then share the URL.

1 Like

EDIT: very sorry, attached the wrong project… Fixed.

Number Wizard UI.zip (6.4 MB)

Sorry that it’s so poorly formatted :slight_smile:

Hopefully you can determine if there is something wrong with the code.

Thanks!

To explain what I mean referencing the video:

This is a screenshot from the lesson taken at 5:31

guess = 535
min = 1 (as we can see from the inspector)
max = 1001

Let’s say Rick proceeds to click “HIGHER”.

The script will run:

    public void OnPressHigher()
    {
        NextGuess();
        min = guess + 1;
    }
    void NextGuess()
    {
        guessValue();
    }
void guessValue()
{
    guess = Random.Range(min, max + 1);
    guessText.text = guess.ToString();
}

immediately the first thing that will happen:

guess = Random.Range(min, max + 1);

and since min = 1, max = 1001, new guess might come out as…

guess = 200.

But it should not go from 535 to 200 after clicking “higher”?

Will take a look now and respond in a few minutes, expecting a call too but will respond as soon as possible :slight_smile:

1 Like

Okay, I fixed it!

The order of this piece of code was wrong:

        NextGuess();
        max = guess - 1;
        NextGuess();
        min = guess + 1;

It needed to be:

        max = guess - 1;
        NextGuess();
        min = guess + 1;
        NextGuess();

Sorry to waste your time Rob, and once again, thanks for the help! :slight_smile:

Time to get a rubber duck…

1 Like

lol, I had just got as far as opening the project.

Glad you have managed to resolve it yourself, that’s great - well done.

Not a waste of my time, and yeah, a duck is good! :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms