Harry11223344 0 Posted May 15, 2015 Share Posted May 15, 2015 How can I use Vector/Any as a menu entry? The code below doesn't work as it doesn't accept vector value's to populate the menu. static struct { LPCSTR text; bool *pState; bool *pUpdated; } lines[lineCount] = { { ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), false), NULL, NULL } }; How would I use vector/Any to populate the menu? Link to post Share on other sites
c39687 62 Posted May 15, 2015 Share Posted May 15, 2015 (edited) for example if you want it in this format... "X: # Y: # Z: #" LPCSTR menuText = ("X: " + std::to_string(vector.x) + " Y: " + std::to_string(vector.y) + " Z: " + std::vector(vector.z)).c_str(); i build a std::string because concatenation is easy with + operator and then convert to const char* which is same thing as LPCSTR (long pointer to constant string) Edited May 15, 2015 by c39687 Link to post Share on other sites
Fireboyd78 382 Posted May 15, 2015 Share Posted May 15, 2015 (edited) // allocate 128-byte bufferconst char strVec[128];// format string (floats should print with 6 decimal places)sprintf(&strVec, "X: %.6f, Y: %.6f, Z: %.6f\n", vector.x, vector.y, vector.z);// now 'strVec' has your formatted string, and should be able to be converted to LPCSTR! Why not do this instead? Edited May 15, 2015 by CarLuver69 Link to post Share on other sites
c39687 62 Posted May 15, 2015 Share Posted May 15, 2015 (edited) // allocate 128-byte bufferconst char strVec[128];// print formatted string (floats should print with 6 decimal places)sprintf(&strVec, "X: %.6f, Y: %.6f, Z: %.6f", vector.x, vector.y, vector.z);// now 'strVec' has your formatted string, and should be able to be converted to LPCSTR! Why not do this instead? oh cool thanks, i mainly use c# so it was a c# approach Edited May 15, 2015 by c39687 Link to post Share on other sites
Fireboyd78 382 Posted May 15, 2015 Share Posted May 15, 2015 Yeah, I started out with C# as well. I've noticed a lot of people tend to mix up C# practices with C++ and vice versa. Things can get really messy 1 Link to post Share on other sites
thunder_ 1 Posted May 17, 2015 Share Posted May 17, 2015 // allocate 128-byte bufferconst char strVec[128];// format string (floats should print with 6 decimal places)sprintf(&strVec, "X: %.6f, Y: %.6f, Z: %.6f\n", vector.x, vector.y, vector.z);// now 'strVec' has your formatted string, and should be able to be converted to LPCSTR! Why not do this instead? You could, but it's recommended that you use the standard libraries in C++. Also, I can't remember, but I believe sprintf is deprecated. Link to post Share on other sites