Re: help!

new topic     » goto parent     » topic index » view thread      » older message » newer message

Monty King writes:
> It will recognize a key is pressed,  print the key number, ...
> but will not act on the keypress.

>while 1 do
>   key = get_key()
>   if key != -1 then
>         ?key

>   elsif key = 27 then
>          --what to do if esc pressed
>          gameover = TRUE

>   elsif key = 331 then
>         --what to do if left arrow
>         subtract()--tried to use an in include procedure, it didn't work
 ither.

>   elsif key = 333 then
>         --what to do if right arrow
>         lemx = lemx + 5
>         ?lemx

>   elsif key = 336 then
>         lemy = lemy + 5
>         --down arrow

>   elsif key = 328 then
>         lemy = lemy - 5
>         --up arrow

>   end if
>end while

I think the root cause of all your difficulties is the
following:
>   key = get_key()
>   if key != -1 then
>         ? key

get_key() returns -1 when no key has been pressed.
This means that any key that is pressed will cause you
to execute "? key". And then
the entire if statement is *finished*. You will never test
for key = 331, or any other key. At most one alternative
can be chosen from a chain of if-elsif-elsif-end if

Try changing it to something like:
     if key != -1 then
          ? key
     end if

     if key = 27 then
        ...etc.

     elsif key = 331 then
        ...etc.

     elsif key = ...etc.

     end if


Your concerns about global procedures etc. are probably
due to this "if" problem.

Regards,
    Rob Craig
    Rapid Deployment Software

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu