Jump to content

I suck at C++, any ideas ?


Scias

Recommended Posts

Hello Scias.

 

What you are trying to do:

Add an int to a string, then add a string to the end of the string that has the int added to it.

 

What you are actually doing:
Adding an int value to a string, then adding a string value to that int value.

 

What you can do is use std::stringstream to create a string then append values to it as such:

std::stringstream locStr;

locStr << "Character Location X: " << X << " Y: " << Y " Z: " << Z;
handler->SendSysMessage(locStr.str().c_str());

This will print the floats with their decimals, if you only want the integer value you can cast it to int like before.

 

You also have the option of using sprintf which will fill a buffer with a string and place the arguements based on the va_list implementation.

char posBuff[255];
sprintf(posBuff, "Character Location X: %f Y: %f Z: %f", X, Y, Z);
handler->SendSysMessage(posBuff);

If the handler is the ChatHandler implementation found in skyfire, then just use the PSendSystemMessage instead as it supports formatted strings.

handler->PSendSysMessage("Character Location X: %f Y: %f Z: %f", X, Y, Z);

And just so you know, if you're casting to an int, use %i instead of %f.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.