Bennu Game Development

English Forums => Helpdesk => Topic started by: Sslaxx on May 15, 2011, 08:42:57 PM

Title: Waiting for a keypress to end the program does not end correctly.
Post by: Sslaxx on May 15, 2011, 08:42:57 PM
So, on my quest to understand BennuGD I have this:/*
  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?
Title: Re: Waiting for a keypress to end the program does not end correctly.
Post by: FreeYourMind on May 15, 2011, 08:56:59 PM
The say is for the console, do you have console on ubuntu execution ?
Title: Re: Waiting for a keypress to end the program does not end correctly.
Post by: Sslaxx on May 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.
Title: Re: Waiting for a keypress to end the program does not end correctly.
Post by: Sandman on May 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.
Title: Re: Waiting for a keypress to end the program does not end correctly.
Post by: Sslaxx on May 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.