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 / Displaying a float value - Noob question

Author
Message
RancidRat
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 29th Feb 2008 12:40
I'm just trying to figure out some C++ stuff. I'm wanting to display the camera's X Y and Z position. I'v seen people do this kinda thing:

char text[256];
wsprintf (text , "XPOS %d" , dbCameraPositionX ( ) );
dbText ( 0 , 0 , text );

In other scripting programs I used before, I would use %f to get the float value but It does not seem to work here. How do I display the float value and is this the best way?
Rye
21
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 29th Feb 2008 14:27
char text[256];

while ( LoopGDK ( ) )
{
dbText ( 0, 0, text );
sprintf(text, "PosX: %g", dbCameraPositionX());
}

that works. u need the sprintf in the loop remember. And you char array MUST be big enough to store all the text.
RancidRat
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 29th Feb 2008 19:12
Thanks dude, it works perfectly
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 1st Mar 2008 02:50 Edited at: 1st Mar 2008 02:50
You can also use dbStr( ) to retrieve a string of the float value, then use dbText( ) to display it. So:



...should work.
Rye
21
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 1st Mar 2008 05:16
From a purely performance view...

Chances are, dbstr() is probably a function that has sprintf in it or something. So using it will not be as efficient. Difference will be negligible though.

Its probably better getting used to using C++ things instead of purely relying on DB's commands.
Niels Henriksen
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location: Behind you breathing heavely
Posted: 1st Mar 2008 10:46
Hmm.... I get an buffer overrun ?

Niels Henriksen
Working on a (MMO)RPG right now in LightEngine (thanks kBessa)
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 1st Mar 2008 11:46
Quote: "Hmm.... I get an buffer overrun ?"

The buffer you are outputting to is probably too small.

Rye
21
Years of Service
User Offline
Joined: 30th May 2003
Location: United Kingdom, Blackrod
Posted: 1st Mar 2008 14:46
make sure the array isnt too small. it needs to be able to contain ALL the characters. text[5] will store 5 characters, not 5 lines.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 1st Mar 2008 15:02 Edited at: 1st Mar 2008 15:06
This is why I set up a Namespace that has ONE Char Buffer of 1024bytes - so I have a nice sized buffer and I can use it everywhere.

jfc_common.h - stripped for thread topic


jfc_common.cpp - also stripped to just pertain to this thread



Then I include jgc_common.h everywhere and I can do:



Niels Henriksen
20
Years of Service
User Offline
Joined: 27th Sep 2004
Location: Behind you breathing heavely
Posted: 1st Mar 2008 16:41
@jason - thanks for the tip....it worked

Niels Henriksen
Working on a (MMO)RPG right now in LightEngine (thanks kBessa)

Login to post a reply

Server time is: 2024-11-20 03:45:30
Your offset time is: 2024-11-20 03:45:30