arrow key menu

BlitzMax Forums/BlitzMax Programming/arrow key menu

B(Posted 2009) [#1]
I have searched the forums extensively and I was unable to find a thread that dealt
with my problem.

In my current game I am trying to make it so that when you get near a certain spot in opens up a menu in which you can upgrade your stats, however I am having lots of trouble. :(

when you press the down key it skips from the 1st to the 3rd option and misses the 2nd.

I believe this to be a result of it going to the 2nd one, but you cannot lift your finger off the key fast enough for the computer.

I fixed this problem by throwing in a wait function so it just waits a couple tenths of a second. but i wanted to know if there is a better way to do this.

my second problem is that the inc def stat does not seem to work and I have no idea why.

it is probably just a result of me looking at the same code forever and I need a fresh pair of eyes.

also I want to have it so when you hit the down key it goes down and then waits for you to lift your finger back up until you can press it down again to go to the next selection.


any help would be much appreciated!


here is the code and I will upload a .zip folder which contains everything you need to play the game as well. graphics included.



UPDATED TO CODE BOX!


thanks in advanced for all the help.


.zip here

B


GfK(Posted 2009) [#2]
Use KeyHit instead of KeyDown.


Muttley(Posted 2009) [#3]
Or, use a key repeat rate to limit your responses to KeyDown:

Const KEY_REPEAT_RATE:int = 150 ' in ms
Global lastKeyDownTime:int

While(true)
   If KeyDown(KEY_UP) And Millisecs() > lastKeyDownTime + KEY_REPEAT_RATE
      lastKeyDownTime = MilliSecs()
      DoStuff()
   EndIf
Wend



Muttley(Posted 2009) [#4]
PS. I'd also recommend not using Goto.... Ever! ;)


Jesse(Posted 2009) [#5]
just another alternative:


and yes find an alternative to your goto.


Czar Flavius(Posted 2009) [#6]
So many globals :(


B(Posted 2009) [#7]
Thanks for all the help!

I am pretty new to this particular language so I understand that I have been making some big no no's.

if I may ask:

why no globals?
what is an alternative?

why no goto's?
what is an alternative?

should i just have everything in the same loop, and use variables to in a way 'unlock' things in place of using goto's?


plash(Posted 2009) [#8]
why no globals?
I don't think it was said that you should have no globals, it's the way your program is setup that is simply beginner-level.

I think I heard this on the forums.. "If you can't do it without Gotos you must be doing something wrong."
For one, you can't use them in SuperStrict (or Strict?) - which you should be using.

He means 'alternative' as in, find another solution that does not involve using Gotos.


Jesse(Posted 2009) [#9]
here is one way of doing it:


it helps to learn oop, it will make your life so much easier.
if interested. look at the oop tutorial here:
http://www.blitzmax.com/Community/posts.php?topic=59233
have you looked at the programming blitzmax tutorial here:
http://www.blitzmax.com/Community/posts.php?topic=42519
if you have not, I recommend reading this first.


Muttley(Posted 2009) [#10]
@B: With regards to the Globals comment, it's generally considered best practice to avoid them wherever possible. Have a read of this page.

The problem with using goto is that your code can easily end up as a tangled, spaghetti-like mess of code that's extremely hard to debug. Goto is almost never actually required, as the problem can usually be rewritten so that it is a) not needed, and b) easier to read/follow. I don't think I've actually used Goto since the Commodore 64 BASIC days, and even then I used it as a glorified jump table in one specific place in an adventure game I was writing.

As Jesse said, getting your head around some basic OO concepts will make your life a whole lot easier in the long run, so I'd recommend you have a read through the links he posted.

I also recommend getting into the habit of always writing "SuperStrict" on the first line of any BlitzMax code you write (I wish it was the default TBH).

Anyway, I hope this helps. :)

Muttley


B(Posted 2009) [#11]
@Everyone
thanks for all the help ill have to take a look at what SuperStrict means because I have no idea what it is.

i will definitely check out all the links that were provided.

Thanks again for solving my problem with the arrow keys, and i learned how some basic
blitz coding rules along the way.

thanks again! :)

B