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 / Creating a simple chat with DarkGDK?

Author
Message
ErDa
16
Years of Service
User Offline
Joined: 17th Feb 2008
Location:
Posted: 23rd Sep 2009 13:38
I've been trying to set up a simple client in DarkGDK, that should let the user write in a chatmessage, and send it to the server to display it to all clients connected, as seen in any online game. My main problem is creating the actual chat function in the DarkGDK client. I've tried using both dbEntry() and dbInput(), but they do not quite serve the correct function. dbEntry() halts the program to while the user inputs whatever. dbInput() gives me the same problem. I'm probably just being very stupid about this, but I can't seem to think of a solution to this.
Marsh0
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 23rd Sep 2009 18:44
I am also attempting to get some user input, it is very annoying. My only thought is capturing all keys that the user inputs then display that to the screen. If he presses backspace then remove 1 from the end of the string.
ErDa
16
Years of Service
User Offline
Joined: 17th Feb 2008
Location:
Posted: 23rd Sep 2009 22:22
Won't work if anyone connects with an AZERTY keyboard, etc.
ErDa
16
Years of Service
User Offline
Joined: 17th Feb 2008
Location:
Posted: 24th Sep 2009 20:18
I take it the reason noone wants to answer my question is because I worded it wrong, or perhaps you think I want you to write the whole code for me. I'll be more specific I guess.

1. The only thing that's come close to working for me is dbText(x,y,dbEntry()); which displays the text just fine, while everything else runs smoothly in the background aswell. This along with dbClearEntryBuffer() lets me input whatever I want, however it does not allow the backspace button. I guess a work-around could be storing the input in an array, then re-drawing all but the last character to simulate a backspace effect. This seems more complicated than it should have to be, is there an easier way?

This leads to question 2. Where/how is the dbEntry data stored, and how can I access it? I need the users input data to be able to send it to and from a server application.
entomophobiac
21
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 24th Sep 2009 21:59
dbEntry() loads whatever is held by the windows system, as it makes sure that no input is missed out. It's a buffer in the operative system itself.

To use it efficiently, you must reset it after it's been referenced, by calling the function dbClearEntryBuffer(). If you don't, whatever you type will simply be piled on top of whatever you typed before.
ErDa
16
Years of Service
User Offline
Joined: 17th Feb 2008
Location:
Posted: 24th Sep 2009 22:54
It's still abit unclear, you're basically saying there's no way to store that information in a variable? If I can't do this I cannot create a backspace function for it either, or send it with multisync. So what are my options here? As someone mention above I could write a function that manually takes the user input and converts it to char's with an array of scancodes = chars. However this poses another problem, not everyone uses the same keyboard layout (so you'd need an array for every single keyboard layout or something crazy like that?). What are my alternatives here?
puppyofkosh
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 24th Sep 2009 23:00
I was recently looking at this:

http://www.codeproject.com/KB/dialog/w32inputbox_1.aspx

Its probly not exactly what you want but its better than nothing.

You could also try "DirectInput" its part of the directx sdk I think.
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 24th Sep 2009 23:34 Edited at: 24th Sep 2009 23:56
to make a program run more smothly I would not use dbentry(); but rather I would see if a key was pressed you can see if a key is pressed by peeking to see if its pressed or use dbKeyState which I have not used but it looks like a good function. then add that as a sprite or add it to the existing char *. To make this work though and have the user able to go back up in his text and edit it. I would use a link list of chars and insert it in if the user is at a certain point of text. The program will move on and not wait. Then use pob back if back space was pressed. This would be time time consuming so just use d3dfunc to get input.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 24th Sep 2009 23:36 Edited at: 24th Sep 2009 23:38
dbEntry returns a pointer to a string. You can copy that string into a char array if you want. This thread contains a conversation about dbEntry, maybe that will shed some light on its behaviour.

http://forum.thegamecreators.com/?m=forum_view&t=151965&b=22

EDIT: You can also experiment with the dbInKey function as an alternative to dbEntry. Maybe that doesn't wait for input but I'm not sure.

I think you won't be able to avoid handling backspace yourself. What if you try a mixed solution? If there is no printable input character but you detect a keypress, then check the scan code. Just thinking aloud.
entomophobiac
21
Years of Service
User Offline
Joined: 1st Nov 2002
Location: United States
Posted: 25th Sep 2009 11:24
dbEntry is actually quite nice for doing this. What I meant was that you need to save the text to another variable and then clear the buffer.

What this does mean, however, is that you'll also have to parse the entry, because it will contain symbols for the Return-key and for other keys as well -- not just letters or numbers.
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 25th Sep 2009 13:03
There should be an alternate version of the function (in DBPro you just supply an additional '1' parameter). Don't clear the buffer until you actually have the string you want to send - otherwise backspaces won't be processed.
ErDa
16
Years of Service
User Offline
Joined: 17th Feb 2008
Location:
Posted: 25th Sep 2009 16:39 Edited at: 25th Sep 2009 18:14
Alright, got it mostly working thanks alot! Benjamin the backspace version is not present in DGDK, so I'm going to have to find a work-around (unless it's un-documented?).

Edit: Bleh, I'm out of ideas on this one too. I thought it would be as simple as comparing the input I got from backspace(which would be  (or 0x8, tried both), it doesn't print through dbText, but that's what my compiler tells me it's storing) to the user input, but it's not working. D:
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 25th Sep 2009 17:16
All you have to do is clear the entry buffer every time you get it then when you have it just append it to your input string. but first check for the ascii value of backspace if it is then don't append it just take off the last character. its not that hard.

New Site! Check it out \/
ErDa
16
Years of Service
User Offline
Joined: 17th Feb 2008
Location:
Posted: 25th Sep 2009 19:13
No, I know what to do, I just don't know HOW to do it. I'm inexperienced with DGDK and C++ in general, so no reason to get cocky.
Serial Velocity
16
Years of Service
User Offline
Joined: 24th Aug 2008
Location:
Posted: 25th Sep 2009 19:24 Edited at: 25th Sep 2009 19:38
Perhaps you could keep an int saying how many characters there are, and if you type a character its adds 1 to this, and if you press backspace its takes 1 away from this.

When you press backspace, convert the last character into a null terminator (Something like Text[charCount] = "/0";) and the character after into "". Just an idea but it may work.

Psuedo-Code:


ErDa
16
Years of Service
User Offline
Joined: 17th Feb 2008
Location:
Posted: 26th Sep 2009 02:18 Edited at: 26th Sep 2009 02:25
Yeah, I know what to do, just not how. Also someone really needs to fresh up ye good ol' documentation, it's pretty outdated.

At the risk of sounding like an idiot I'm going to have to ask how i'm supposed to compare dbGetEntry() to an integer (namely 0x8).
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 26th Sep 2009 17:14 Edited at: 26th Sep 2009 17:36
user SushiBox brings this up
[href]
http://forum.thegamecreators.com/?m=forum_view&t=139811&b=22
[/href]
why not use scancode and cheak if it is 14 or not.
Why does scancode return 14 instead of 8 that is my question?

Go through yourself at a wall.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 26th Sep 2009 20:01
Quote: "Why does scancode return 14 instead of 8 that is my question?
"


Because 14 represents the key being pressed, not the character associated with it. Most keys have more than one meaning depending on whether Shift/Ctl/Alt/etc. are pressed at the same time. Alpha keys can be upper or lower case versions of a character. Numeric keys have more than just numeric characters associated with them. Pretty much any of the control character related keys don't have alternate characters associated with them on the keyboard but you can use the fact that the modifier keys are pressed at the same time to have your program behave differently when backspace is pressed.

What if you wanted to check if F5 was pressed? What is the ASCII code for F5? Since there isn't one you have to rely on the scan code of the key. Not so strangely, if I start counting keys from left to right on the number row of my keyboard, starting with the `/~ key, backspace happens to be key number 14. It may not be in that exact same position on another keyboard but it will always have scan code 14. Then you have the issue of scan codes vs. non-ASCII characters in other languages. The A in ASCII stands for "American".

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
ErDa
16
Years of Service
User Offline
Joined: 17th Feb 2008
Location:
Posted: 26th Sep 2009 22:04
Awesome, thanks for the ideas guys! It's more or less working perfectly now, except for one tiny thing that I really don't care about, but if someone has an easy fix why not? It basically seems to save more than 1 character to a char in the array? So I must assume it's not actually storing the individual characters in the array? What I mean is that if I mash 3 buttons at once, it'll register as one input. And if I backspace immediately after, it'll remove all 3 letters. Anyways here's the code, in chase someone else wants it:

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 27th Sep 2009 14:20 Edited at: 27th Sep 2009 14:22
Comments: First, you call dbGetEntry() three times when one call would be enough. Repeated function calls decrease performance. (In the worst case, they may even give you different results - although the probability of that is pretty low -, since the function is re-executed so the input is re-read again.) The function returns a char* which you can store in a variable and use that.

Second, when using a Dark GDK function which returns a char*, you must delete[] the returned string to avoid memory leaks. If you look at the thread that I referred already in my previous post:

http://forum.thegamecreators.com/?m=forum_view&t=151965&b=22

Have a look at the code posted by Michael P. That shows you how to delete the returned string (using the stored char pointer). That's where I learned this important info too.

Same applies, by the way, to the dbStr function. That also causes memory leak if you do not delete the returned string. For debug prints, it's easier to use sprintf with a character array.
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 28th Sep 2009 03:42 Edited at: 28th Sep 2009 03:42

this is it with sprites

Go through yourself at a wall.
ErDa
16
Years of Service
User Offline
Joined: 17th Feb 2008
Location:
Posted: 28th Sep 2009 23:55


I'll just use this to convert text to sprites, seems alot easier, but it's pretty limited.

Login to post a reply

Server time is: 2024-10-01 14:43:26
Your offset time is: 2024-10-01 14:43:26