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 / Variables within Strings

Author
Message
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 9th Dec 2007 03:01
I'm having some trouble. I started using DarkGDK today, and I decided I'd code a quick Pong clone. (everyone's favorite starting project!)

In C++, back in the days of DOS, Turbo-C++, and Borland's CONIO, we could write strings with variable markers within a string to be printed, and then list variables, in order of appearance, after the string. Example: (because more than likely, no one will have followed that)

Which would have then printed: "Hello subject 7"

I assumed the same would work with DarkGDK, however there's a plethora of problems. A direct attempt to do so with dbPrint ends up like this:

The error it returns makes sense, saying there are too many arguments for dbPrint, which takes only one. The comma makes it think there are two! The same problem will happen with dbText and presumable dbCenterText. (I didn't bother to try dbCenterText)

I haven't the slightest idea how to get around this. Ideas?
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 9th Dec 2007 03:16
You could use dbStr( int ) to turn your integer into a char* and append that onto the "Hello subject " string.

"It's like floating a boat on a liquid that I don't know, but I'm quite happy to drink it if I'm thirsty enough" - Me being a good programmer but sucking at computers
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 9th Dec 2007 03:22
Could you give a code example? I'm not sure how to append strings with other strings.
tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 9th Dec 2007 04:01 Edited at: 9th Dec 2007 04:02
Give this a try.



In Visual Studio you get the handy function OutputDebugString() which will output the debug window (bottom of VS).

SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 9th Dec 2007 04:33 Edited at: 9th Dec 2007 04:36
That works beautifully! Thank you.

One other problem, with the while loop I'm using to keep the play going, if I don't have the condition as LoopGDK(), the program doesn't terminate until, apparently, it receives the message WM_PAINT from windows. In DBPro you can break do loops and while loops with 'exit,' but this command doesn't exist in DGDK. So how would I go about getting the while loop to break if "winner==1"?

EDIT: When I talk about 'while conditions,' I mean the condition specified with the while command, here it needs to be:

(to work properly)
And I'd like it to be:

Just to clarify.
tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 9th Dec 2007 05:42
I think this is what you want:


SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 9th Dec 2007 05:47 Edited at: 9th Dec 2007 05:49
Ah! That's perfect! I actually thought of using break before, but I never tested it. I assumed it wouldn't work, because the only time I had used break before was with switch(). Thank you, yet again!

The final source for the app is below, I don't know if you're interested in how it turns out. It's super-basic, and the system for adjusting angles is sub-par.

tparkin
17
Years of Service
User Offline
Joined: 28th Mar 2007
Location:
Posted: 9th Dec 2007 09:56
Glad to have helped. You seem fluent in C (C++?) but just needed some refreshing. I don't have time to try out your pong game but the code looks good. I highly recommend using OOP and taking advantage of C++ constructs. I don't know if it's just the forums, but putting your collision checks in one long line like that makes it a pain to read - now and later when you go back to it.

Welcome to DarkGDK. You've made some great progress for your first day!
Deagle
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location: Finland
Posted: 9th Dec 2007 16:59
You could do it this way too:


Deagle aka D-Eagle
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 9th Dec 2007 17:17
I've been working with C/C++ for around 9 years now, but only with Windows for a few months, and DarkGDK since yesterday...

That's an interesting idea, Deagle, I hadn't thought of that!

Login to post a reply

Server time is: 2024-11-19 18:41:57
Your offset time is: 2024-11-19 18:41:57