Autor Tema: Waiting for a keypress to end the program does not end correctly.  (Leído 1208 veces)

Sslaxx

  • Newbie
  • *
  • Mensajes: 34
  • Karma: 0
So, on my quest to understand BennuGD I have this:
Código: [Seleccionar]
/*
  LinuxLander/BennuGD
*/

import "mod_say"
import "mod_key"

Const
 MoveBaseStart = 3; // The starting value for moving the vertical base.
End

Declare Process Test ()
 Private
 End
 Public
 End
End

Global
 int GameState = 0; /**< 0 = playing, 1 = win, -1 = went off edges of screen, -2 = missed the base. */
 int PlayerX = 0; /* The player's X location. */
 int PlayerY = 0; /* Player's Y location. */
 int BaseX = 0; /* As for the player... */
 int BaseY = 0; /* ...but detailing the base's location. */
 int MoveBaseX = 0; /* Controls the horizontal movement of the base. */
 int MoveBaseY = MoveBaseStart; /* Vertical base movement. */
 Test ItsATest;
End

Process Main ()
Public
 int a = 0;
Private
Begin
// ItsATest ();
 // Each of these three will give different process IDs.
 Test ();
 Test ();
 Test ();
 While (!key (_space))
  frame (500);
 End
OnExit
 say ("Thanks for playing!");
End

Process Test ()
Begin
 say (id);
 frame;
OnExit
 say (id + " is done.");
End

On execution, it waits for escape to be pressed, but (under Ubuntu 11.04) it doesn't do anything. It displays an escape code for escape, but that's it. I suspect I'm missing or have misunderstood something, but I'm not entirely sure what. Any pointers?
Stuart "Sslaxx" Moore.

FreeYourMind

  • Hero Member
  • *****
  • Mensajes: 5682
  • Karma: 128
    • GECA soft
Re: Waiting for a keypress to end the program does not end correctly.
« Respuesta #1 en: Mayo 15, 2011, 08:56:59 pm »
The say is for the console, do you have console on ubuntu execution ?

Sslaxx

  • Newbie
  • *
  • Mensajes: 34
  • Karma: 0
Re: Waiting for a keypress to end the program does not end correctly.
« Respuesta #2 en: Mayo 15, 2011, 09:20:42 pm »
The program runs and displays what it should (from the command line) until it gets to the part where it waits for a keypress, if that's what you're asking about.
Stuart "Sslaxx" Moore.

Sandman

  • Sr. Member
  • ****
  • Mensajes: 298
  • Karma: 48
Re: Waiting for a keypress to end the program does not end correctly.
« Respuesta #3 en: Mayo 15, 2011, 11:16:43 pm »
This is because they key() command only checks the GUI input, not the input on the terminal. However, having a mod_key dependency on a specific gui module may arguably be incorrect, depending on the semantics. I guess it should be added, though, because this is not clear. For the sake of the example, try importing mod_wm as well. This will make sure a window pops up. If you press space in that window, the program behaves like you would expect.
-- Sandman

Sslaxx

  • Newbie
  • *
  • Mensajes: 34
  • Karma: 0
Re: Waiting for a keypress to end the program does not end correctly.
« Respuesta #4 en: Mayo 15, 2011, 11:32:15 pm »
Ah, gotcha. I had an inkling it might have been something along those lines, but wasn't sure what it'd have been. I shall see what that does, thanks!

Works as hoped for, cheers.
« última modificación: Mayo 16, 2011, 03:22:50 pm por Sslaxx »
Stuart "Sslaxx" Moore.