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 / Is there a way to position dbInput ?

Author
Message
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 9th Dec 2010 04:54 Edited at: 9th Dec 2010 04:58

I would like to position my dbInput to right after "Name:"

Also how would I make it so after you press enter it moves on with the program (so if you type no more will appear), something like after the dbInput put like
"if( dbKeyState(28) == 1) {"
then just move on with my program and add an extra "}" at the end?

Thanks.

Always program as if the person maintaining your program is a psychopath that knows where you live
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 9th Dec 2010 05:20
Sorry, but I don't think that's do-able. You'll need to create your own text input code, then send it to a char*, which can then send it to dbText().

http://ref.darkgdk.us/ <- Online DarkGDK Refernece. More content coming soon.
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 9th Dec 2010 05:45
How would I create my own input?

Always program as if the person maintaining your program is a psychopath that knows where you live
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 9th Dec 2010 07:54 Edited at: 9th Dec 2010 07:59
There is a dbSetCursor command that positions the text cursor, so - according to the help - the next dbPrint will use that position. Maybe it works for positioning dbInput cursor as well, try it out.

I once wrote a text input function that stores the typed characters and watches for Backspace as well. It would also solve positioning because you can use dbText to output the input string. There are two versions of the function here, in two posts of mine, if you are interested:

http://forum.thegamecreators.com/?m=forum_view&t=160546&b=22
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 9th Dec 2010 19:58 Edited at: 9th Dec 2010 20:03
Thank you, the set cursor thing worked.
This is my new code:


But after I press enter when i have my name it shows numbers instead of letters. I also tried char instead of int and also numbers. Whats wrong?

Always program as if the person maintaining your program is a psychopath that knows where you live
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 9th Dec 2010 23:07
Get rid of that "dbStr()", What it does is convert any number to a string with the number as the string's value.

Ex:

the number 42 becomes "42", as a string. Just put "x" in there as the parameter.

http://ref.darkgdk.us/ <- Online DarkGDK Refernece. More content coming soon.
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 9th Dec 2010 23:46 Edited at: 10th Dec 2010 02:23
Oh wow cuddle bunniezzz 12 it worked, i thought it was needed to stop an error. Thanks.
Now another, I want it so after I press enter it says "Hello (name)"
This comes up with a few errors, so how do I make it work?


Ohh and with this code (I still need help with the one above though) I want if my name is "Brett" to say "woohoo!" but if not then for it to end the program. No matter what i do it says "woohoo!"


Always program as if the person maintaining your program is a psychopath that knows where you live
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 10th Dec 2010 17:49 Edited at: 10th Dec 2010 17:51
You can't just write variables after each other like "Hello "x, that doesn't work. If you want to write two strings after each other, you need either two dbText cmmands, or you need to use string concatenation commands (like strcat) to join the two strings into a temporary string buffer (char array).

http://www.cplusplus.com/reference/clibrary/cstring/strcat/

There are two problems with this one:


First, comparison is double equal sign like this: ==. Be always careful of that. If you just put one equal sign, that makes the variable equal to the second value, so the "if" condition will always be true.

Second, even if you correct the code to double equal sign, it will not work because you can't compare two strings this way. Writing x == "Brett" will compare the pointers to the strings, not the contents of the strings. (In that case, the pointers will never be equal, so the code will be bad the opposite way.) You need to use a string comparison function, like strcmp:

http://www.cplusplus.com/reference/clibrary/cstring/strcmp/
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 10th Dec 2010 23:53
OK, mireben, I tried this and it doesnt work. It just freezes after the name is shown.


Always program as if the person maintaining your program is a psychopath that knows where you live
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 11th Dec 2010 10:40
You are mixing together your program and the usage example given on the C++ site. It would have been enough to correct the string comparison in the original code:



And if you want to display "Hello, name!" then there are a few solutions, this is one:



Note that there is no length check here, so if the typed-in string is very long, it will overrun the buffer and cause an error. To make this safer, you can use strncat which has an additional parameter, the maximum number of characters to be copied:



Other solutions can be:
- using several dbText or dbSetCursor + dbPrint commands to print out the parts of the string one by one, but that's not very beautiful or practical,
- using sprintf (or sprintf_s) with %s pattern to put a string inside another,
- using std::string class and put parts of the strings together using the + or += operator or the built-in functions of that string class, but then you need a bit longer syntax to pass the string to dbText.

You can read more on the usage of different string functions on cplusplus.com.
CocaCola
14
Years of Service
User Offline
Joined: 23rd Mar 2010
Location: CocaCola.x CocaCola.y CocaCola.z
Posted: 12th Dec 2010 22:46 Edited at: 12th Dec 2010 22:51
I am trying this code:


I type in Brett, when I get to the Hello, Brett! part it says "Hello, BrettBrett!"


EDIT: huge mistake, put two of them, haha, fixed.


Always program as if the person maintaining your program is a psychopath that knows where you live
jhonebill
13
Years of Service
User Offline
Joined: 16th Dec 2010
Location:
Posted: 16th Dec 2010 10:05
great pal it work also.. regards..

jhonebill

Login to post a reply

Server time is: 2024-11-19 16:28:22
Your offset time is: 2024-11-19 16:28:22