[Solved] What if I want to cheat?

Someone may say higher when their number is actually lower. The wizard will detect this when the min == max and the user says its guess is wrong, or when the max < min. The Wizard says, “You’ve made an error. Let’s start over.” and makes his first guess.
The problem is that the last answer you gave is taken as the reply to the first guess. It seems that it’s been stored and when StartGame() is run, it reads the old keypress. Is there a way to clear that? I tried Input.ResetInputAxes() in various places throughout my code, but it doesn’t make any difference.
As long as you play fair, the game runs fine, so this isn’t really a [help] question. And I’m sure eventually we’ll get around to things like this. Just looking for some information, really.
(Incidentally, I AM using GetKeyDown, not GetKey.)

Well, that depends on whether it stores the keypresses in a queue that gets
cleared as it processes the presses, but it sounds like the update routine
is just reading the last keypress again, which doesn’t make sense, since
otherwise it would be continually doing that all the time when Update is
run. I think we’ll need you to post the code for this one.

Yep.

You could get the user to actually enter the number that they have thought of, store it, check the final answer against it - but then of course you’d just have the opposite - a human accusing the game of cheating.

You could also consider disabling the higher / lower buttons when the edge case are met, e.g. you can’t go any lower, and you can’t go any higher.

Regarding the “it seems that it’s been stored” etc… the sequence goes like this;

  • Player picks a number, let’s say 985

Turn 1

  • Game
    min = 0
    max = 1000
    guess = 500

  • Player
    Clicks Higher

Turn 2

  • Game
    min = 500
    max = 1000
    guess = 750 (min + max) / 2

  • Player
    Clicks Higher

Turn 3

  • Game
    min = 750
    max = 1000
    guess = 875 (min + max) / 2

  • Player
    Clicks Higher

Turn 4

  • Game
    min = 875
    max = 1000
    guess = 938 (min + max) / 2

  • Player
    Clicks Higher

Turn 5

  • Game
    min = 938
    max = 1000
    guess = 969 (min + max) / 2

  • Player
    Clicks Higher

Turn 6

  • Game
    min = 969
    max = 1000
    guess = 985 (min + max) / 2

At this point the game has now guessed the player’s number, the player should indicate this.

This was a noddy example which didn’t take into account the player choosing other options, or the +1 thing, but it should demonstrate what is being remembered, it’s simply the last guess being used, in this case, as the new value for min. If the player had chosen lower at any point then the value of max would have been changed accordingly.

At any point the player shouldn’t be able to choose a lower number than the value of min, or a higher value than max. If the game whittles it all the way down to the very end with no other numbers possible to provide and was to then ask the player “is this your number”, if the player indicated “no” the game could legitimately state that they were cheating.

I made a workaround for this problem.
Instead of starting over when there is an error, I print a message and tell the user to "Press ‘R’ to start over."
When the user presses ‘R’, I run StartGame(). The last key pressed is now “R” instead of the last key pressed being an arrow key. So Update waits for a reply.
BTW, with the way I modified the code, it IS possible for min to be > max, but ONLY if the user has made an error (or cheated.) I no longer increase max before starting; instead when the user says “higher”, I set min to guess + 1, and when the user says “lower”, I set max to guess - 1.
Thanks for your help.

Privacy & Terms