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 / dbPrint prob

Author
Message
Let the game begin
12
Years of Service
User Offline
Joined: 31st May 2011
Location: India
Posted: 17th Sep 2011 17:29
here's a line of my code

dbPrint("Hello World");

It works well but not the way i want it to be. I want the next print to simply be appended in front of it and not on the next line.
I read about it in the Dark GDK documentation which says that if I place a semi-colon in front of it, then the next print statement will be placed right in front of the previous statement. It was vague because I think adding a semi-colon would terminate the statement there. In a nutshell, I didn't get it. I need somebody to help me

This is TDM (i.e. The Dark Man).
Lord_Migit
13
Years of Service
User Offline
Joined: 3rd Apr 2011
Location: Dundee, Scotland
Posted: 17th Sep 2011 18:59
I'm still new at this engine but i mite be able to help. Firstly i find it a lot easier to use the text commands as they have more control.

dbText() will allow you to specify, in X and Y co-ordinates, where you want the text to appear. You can also do a few other things to it like make it opaque, change font, size, bold & italic etc.

As for dbPrint, i believe if you use dbSetCursor() then you can choose the X and Y co-ordinates that dbPrint will output to next. It has 2 parameters: void dbSetCursor ( int iX, int iY )

Hope this helps, let us know how you get on.

"Knowledge is Power"
Let the game begin
12
Years of Service
User Offline
Joined: 31st May 2011
Location: India
Posted: 18th Sep 2011 04:28
@ Lord_Migit
I know about it but I want to do the same with only dbPrint(). You should read a little about the description of this command in the DGDK documentation. Then you'll know what I am trying to say.
Here's a little program.
int i,j;
for (i=1; i<=5; ++i
{
for (j=1; j<=i; ++j
{
dbPrint(dbStr$(j));
}
dbPrint(" ");
}

Now I want it to print:-
1
12
123
1234
12345

But as you may have guessed, it won't do so. It because the statement which says dbPrint(dbStr$(j)); will simply append the next print on the next line which I don't want, instead it should place the next print in front of it. You may help me by writing the code in a better way.

This is TDM (i.e. The Dark Man).
Dar13
15
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 18th Sep 2011 07:17 Edited at: 18th Sep 2011 07:18
I think this is what you are trying to do.



Note: Uses the standard libraries for C++(the std::string class in particular), and I delete the 'str' variable to prevent a memory leak.

Let the game begin
12
Years of Service
User Offline
Joined: 31st May 2011
Location: India
Posted: 18th Sep 2011 18:45
@ Dar 13
I tried to paste your code in the main DGDK loop, but the following errors occured

I guess I mite be making a mistake somewhere. So, it would be good if you send me the complete code. Thank you.

This is TDM (i.e. The Dark Man).
Dar13
15
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 18th Sep 2011 21:06
Revised:


As I don't use DarkGDK anymore, this should work but I'm not sure.

Mr Bigglesworth
16
Years of Service
User Offline
Joined: 4th Mar 2008
Location:
Posted: 19th Sep 2011 05:49
@Let the game begin
You may have to change your project to "Multi-Threaded /MD" in "Project Settings -> C/C++" to get the standard library to work correctly.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 19th Sep 2011 15:45
Dbprint automatically appends a new line char to the end of the string. Use dbprintc instead. I'm pretty sure that's the one you need...

jtk
Let the game begin
12
Years of Service
User Offline
Joined: 31st May 2011
Location: India
Posted: 19th Sep 2011 18:49
@JTK
Thanks for the suggestion of dbPrintC. My program is working very well now.

@Dar 13
I understand your program now. Since I am new to here, I didn't know about operator overloading that you've done in your code snippet. Well, thanks anyway.

Now it's time to close this thread

This is TDM (i.e. The Dark Man).
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 19th Sep 2011 20:35 Edited at: 20th Sep 2011 07:09
@Dar13: To prevent memory leak, delete[] str should be used, with square brackets. However, it would be better to eliminate dbStr from the program.

@Let the game begin: You can use Dark GDK commands to achieve the printout you want, but it's also easy to do with native C/C++ commands and character arrays. I would use the language itself where possible.

Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 20th Sep 2011 07:10
Edited the above post to recommend sprintf instead of itoa. (Just remembered that itoa is compiler-specific, and besides, it's good if you remember sprintf the next time you need a formatted string output.)
Let the game begin
12
Years of Service
User Offline
Joined: 31st May 2011
Location: India
Posted: 20th Sep 2011 09:48
@Mireban

Thanks for the suggestion but I was asking about the Dark GDK - specific commands instead of the c++ inbuilts. Well thanks anyway.

This is TDM (i.e. The Dark Man).
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 20th Sep 2011 19:07
You will find that if you use the C++ sprintf() function, it is more reliable and safer than trying to use DGDK strings. DGDK strings tend to have a bad habit of causing memory leaks.


Is just the same as Mireben has suggested.

My tip is to use C/C++ use of strings, whether it be char (easier to learn) or std::string and avoid any of DGDK string manipulation commands.

Warning! May contain Nuts!

Login to post a reply

Server time is: 2024-05-04 08:13:22
Your offset time is: 2024-05-04 08:13:22