Jump to content
  • Advertisement
Sign in to follow this  
PhilipNguyen

Please Delete this post, my problem was solved

This topic is 4352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im adding a heathmeter to this fps im working on. I know for sure that this is the only part that the compiler doesnt like. float health = m_playerManager->GetLocalPlayer()->GetHealth(); char healthcasted = (char) health; m_scoreBoardFont->Render(healthcasted, 30, 0, 0xFFFF7700); I know render takes char, so i casted it and it says error C2664: 'Font::Render' : cannot convert parameter l from 'char' to 'char *' I'm a noob so im sorry. Thankyou for any responses. [Edited by - PhilipNguyen on August 18, 2006 7:13:25 PM]

Share this post


Link to post
Share on other sites
Advertisement
not really a rendering problem, the function you're calling is expecting the first parameter to be a char *, and you're passing it a char. you can either pass the address of the variable using the address of operator (&) or you can pass it a true character pointer.

Share this post


Link to post
Share on other sites
Quote:
Original post by PhilipNguyen
Im adding a heathmeter to this fps im working on. I know for sure that this is the only part that the compiler doesnt like.

float health = m_playerManager->GetLocalPlayer()->GetHealth();
char healthcasted = (char) health;

m_scoreBoardFont->Render(healthcasted, 30, 0, 0xFFFF7700);

I know render takes char, so i casted it and it says
error C2664: 'Font::Render' : cannot convert parameter l from 'char' to 'char *'

I'm a noob so im sorry. Thankyou for any responses.


Even then, casting a float to a char doesn't really give you any information. If healthcasted needs to be a string, ie. char* you better use sprintf.

untested:

float health = m_playerManager->GetLocalPlayer()->GetHealth();
char healthcasted[6] // expecting 100.0 at most

//now put the float into the string using format 3.1 => 0.0 to 100.0
sprintf(healthcasted, "%3.1f", health);

m_scoreBoardFont->Render(healthcasted, 30, 0, 0xFFFF7700);


hope that works for you.

Share this post


Link to post
Share on other sites
Morpheus, I changed this line of code
m_scoreBoardFont->Render(&healthcasted, 30, 0, 0xFFFF7700);
The screen displayed a bunch of characters, like BQBS3

Limitz, I changed the program like you said and it compiles but crashes when i get into the game state. It says the heathcasted is corrupt

Thankyou for responding

Share this post


Link to post
Share on other sites
&healthcasted is a char**


#include <sstream>

std::stringstream health<<m_playerManager->GetLocalPlayer()->GetHealth();
m_scoreBoardFont->Render(health.str(), 30, 0, 0xFFFF7700);


[edit]
it may require
std::stringstream health;
health<<m_playerManager->GetLocalPlayer()->GetHealth();

Share this post


Link to post
Share on other sites
Quote:
Original post by PhilipNguyen
Morpheus, I changed this line of code
m_scoreBoardFont->Render(&healthcasted, 30, 0, 0xFFFF7700);
The screen displayed a bunch of characters, like BQBS3

Limitz, I changed the program like you said and it compiles but crashes when i get into the game state. It says the heathcasted is corrupt

Thankyou for responding


are you sure you removed the & before healthcasted in the Render function using my method? It should do the same as dmail's code...

Greetings

EDIT: ofcourse you did, you said it compiled... silly me :)
EDIT: is that your own renderfunction? if it sais it is corrupt because it gets its input in the format 100.0 and you need 100 you may replace %3.1f by %3.0f.

Share this post


Link to post
Share on other sites
Render() seems to take a null-terminated string of characters, and draws those. If you don't know what a null-terminated string is, you should probably go learn (check out a basic C tutorial, or the function strcpy(), for example).

The reason you get lots of characters when passing the pointer to the character, is that there is no null after the character to terminate the string. Further, the character itself is a single ASCII character with the value you're setting it to -- not the characters that make up the number you want to render. For that, you need sprintf().

Thus, your code should look like this:


float health = m_playerManager->GetLocalPlayer()->GetHealth();
char buf[30];
sprintf(buf, "%.1f", health);
m_scoreBoardFont->Render(buf, 30, 0, 0xFFFF7700);


This will print health with one decimal of precision.

Share this post


Link to post
Share on other sites
Quote:
Original post by dmail
&healthcasted is a char**

*** Source Snippet Removed ***


He's creating a char called healthcasted. &healthcasted is therefore the address of the variable healthcasted, i.e. a char *, not a double pointer. If healthcasted was a char *, then you'd be right.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!