[Solved] Trying to get Up Arrow and Down Arrow to set min and max range, and guess higher or lower. Is it possible?

Hey. So I’m actually well in to Section 7 at the moment, but as I’ve been going I’ve been forgetting some more basic concepts, or I never fully grasped them to begin with, and been pushing on regardless. So I’ve decided I should redo some of the older sections, starting with Number Wizard. I’ve gotten to the end of the section, and I decided this time to have a go at the challenge of having the player choose the minimum and maximum range. So here’s the code:

It’s a bit limited but, as you can (hopefully) see, the max begins at 6000, the min begins at 4000, and you can increase or decrease them incrementally by 100. The problem I’m having is, I want Up Arrow and Down Arrow to be used to select the range at first, then, when the game begins, to be used to say if the number is higher or lower as usual. Same with Return. I want Return to be used to set the range and begin the game, and then to be used to declare the answer correct. So I created one method for selecting the number range (NumberSelect), and another for playing the game (InGame). I hoped having them separate, and having the InGame method be called only when pressing Return for the first time, would stop the the key commands from clashing with each other. But at the moment, when the game starts, Up and Down Arrow do things in both methods the same time (changes the range and sets higher or lower), and Return simply restarts the game.

Now, I can of course get around this by replacing Up Arrow, Down Arrow and Return with Right Arrow, Left Arrow and Space, which I have done. So I can get it to work, but I figured it would be useful to know if it is possible to get the same key to do different things in the same script. So is it even possible? And if so, how? Thank you! Hope that all makes sense.

You could had simple boolean to switch your states and add conditions in the update method.

If (gamestart) { use this method }
Else { use this othermethod }

Aw I should have thought of that. Got it working now. Thanks!

This is the code now, if anyone’s interested: https://gist.github.com/anonymous/099ecf03e3a875a13430f3089c57a973

1 Like

Privacy & Terms