Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / GDK Newbie

Author
Message
Vicious Cat
16
Years of Service
User Offline
Joined: 17th Nov 2008
Location: The Halls of The Mountain King, Scotland
Posted: 18th Nov 2008 01:03
Hi,
I am a newbie to VS/GDK, but have been (amateurly) coding for <hrrumph>ty years.
(VBA is now my main method).
I have just spent more time than I should trying to write a simple program to print out the scancode of keys pressed. I have it now working after a fashion, but:
The whole thing would have been a lot easier if each keyword had a small example of how to use it. (This is actually not a GDK thing - VS Express has no examples). Maybe I'm spoilt by the VBA help files?
Anyway - first point, I was lucky to read in a forum post that the dbStr$() in the documentation was actually dbStr() - a simple (checked) example would have saved me so much time (and I have NO spare leisure time) that it's not even funny. So cheers for that.
Now my Question:
[code // turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
int SC=1;
char* SCStr="Hi";
dbText(0,0,SCStr);
dbSuspendForKey();
// our main loop
while ( LoopGDK ( ) )
{
dbCLS();
SC=dbScanCode();
SCStr= dbStr(SC);
dbText(0,0,SCStr);

dbSync ( );
}

// return back to windows
return;
The main loop now works OK.
However the bit at the top (meant to say "Hi" until a keypress) just sits there and does nothing (until a keypress, when the loop works)
Can anyone point me in the direction of a clue Please?

Cheers
Sid
(PS - sorry if the code snippet thing doesn't work - I'm still trying to get used to it)
Swordsman
16
Years of Service
User Offline
Joined: 12th Nov 2008
Location: Wigan, England
Posted: 18th Nov 2008 01:57
dbSuspendForKey() stops all activity until a keypress is detected. If you are trying to do what I think you are, and repeat the word Hi over and over until a keypress, you first need to put it inside a while or do...while loop.
Even if you did this, it would just overwrite itself over and over at the same screen position (as you used dbText(X Coords on screen, Y Coords on screen, YOUR VAR HERE))
You should use dbText(YOUR VAR HERE), it will do what you want it to, but you cannot set text positions using it.



By the way, a note about code tags. You can use them by sticking

[code} <--closing square bracket here instead of curly

/*
......Code here...
*/

[/code}<----another closing square bracket.


Welcome to the wonderful world of GDK! Be prepared for some sleepless nights full of coding. If we can help with anything else, just post
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 18th Nov 2008 02:42
Any text goes through a double buffer procedure, so you are required to feed these changes to the screen with update commands.

This part of your code:
Quote: "char* SCStr="Hi";
dbText(0,0,SCStr);
dbSuspendForKey();"


should be:
Quote: "char* SCStr="Hi";
dbText(0,0,SCStr);
dbSync ( );dbSync ( );//must be done twice because of double buffering
dbSuspendForKey();"
Vicious Cat
16
Years of Service
User Offline
Joined: 17th Nov 2008
Location: The Halls of The Mountain King, Scotland
Posted: 18th Nov 2008 10:55
Thanks - I've got it working with the double buffer thing.
I also tried with the While loop, as it seemed slightly more elegant to me, but it's complaining about While not taking a Void argument.
Still I have my solution, so thanks again, and no doubt I will be asking another newb question in the next few days

SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 18th Nov 2008 22:18
dbSuspendForKey() doesn't return a boolean condition. What you need to do is something like this:



My site, for various stuff that I make.
Swordsman
16
Years of Service
User Offline
Joined: 12th Nov 2008
Location: Wigan, England
Posted: 19th Nov 2008 17:55
Quote: "dbSuspendForKey() doesn't return a boolean condition. What you need to do is something like this:"


Sorry for the bad advice, could have swore I read dbSuspendForKey() returned on termination. Doh.

Login to post a reply

Server time is: 2024-11-25 07:55:13
Your offset time is: 2024-11-25 07:55:13