C++ Question [message #339983] |
Wed, 09 July 2008 14:21 |
HeavyX101- Left
Messages: 633 Registered: April 2008 Location: WindowsJail=ZipFolder
Karma: 0
|
Colonel |
|
|
I'm just wondering what word stands for "word" in C++.
For example, int stands for numbers.
What word stands for "word" in c++.
Examples:
int preset = atof(Text[1].c_str()); = finds the number from the message.
??? preset = atof(Text[1].c_str()); = finds the word from the message.
This account is no longer being active.
|
|
|
Re: C++ Question [message #339988 is a reply to message #339983] |
Wed, 09 July 2008 14:29 |
dead6re
Messages: 602 Registered: September 2003
Karma: 0
|
Colonel |
|
|
"word" does not exist. There is a replacement called char which is an array. Or however you can look at the STD library for std::string.
int atoi( const char *str );
double atof( const char *str );
long atol( const char *str );
Most of the time you can cast between
int -> double/float
Don't go the other way though as you lose the decimal places.
Let all your wishes be granted except one, so you will still have something to strieve for.
[Updated on: Wed, 09 July 2008 14:32] Report message to a moderator
|
|
|
|
|
Re: C++ Question [message #340000 is a reply to message #339988] |
Wed, 09 July 2008 15:21 |
HeavyX101- Left
Messages: 633 Registered: April 2008 Location: WindowsJail=ZipFolder
Karma: 0
|
Colonel |
|
|
dead6re wrote on Wed, 09 July 2008 17:29 | "word" does not exist. There is a replacement called char which is an array. Or however you can look at the STD library for std::string.
int atoi( const char *str );
double atof( const char *str );
long atol( const char *str );
Most of the time you can cast between
int -> double/float
Don't go the other way though as you lose the decimal places.
|
Thanks for the fast reply, but i didnt find anything that could go in this(HERE) :
Quote: | HERE preset = atof(Text[1].c_str()); = finds the word from the message.
|
Does anyone know it. Reborn could of help if i didnt ***** but thats life.
This account is no longer being active.
|
|
|
Re: C++ Question [message #340008 is a reply to message #339983] |
Wed, 09 July 2008 16:57 |
=HT=T-Bird
Messages: 712 Registered: June 2005
Karma: 0
|
Colonel |
|
|
You should either use (const) char* or std::string. char* is marginally faster, but it's easier to make silly, sloppy, and sometimes exploitable errors with it. BTW, you don't need to call an extra function, as Text[1] is already an std::string and .c_str() gives you a char* from it.
HTT-Bird (IRC)
HTTBird (WOL)
Proud HazTeam Lieutenant.
BlackIntel Coder & Moderator.
If you have trouble running BIATCH on your FDS, have some questions about a BIATCH message or log entry, or think that BIATCH spit out a false positive, PLEASE contact the BlackIntel coding team and avoid wasting the time of others.
[Updated on: Wed, 09 July 2008 17:00] Report message to a moderator
|
|
|
Re: C++ Question [message #340009 is a reply to message #340008] |
Wed, 09 July 2008 17:27 |
HeavyX101- Left
Messages: 633 Registered: April 2008 Location: WindowsJail=ZipFolder
Karma: 0
|
Colonel |
|
|
Ok, this is what i did:
char* preset = atof(Text[1].c_str());
And i got a error:
Error 1 error C2440: 'initializing' : cannot convert from 'double' to 'char *' c:\Westwood\RenegadeFDS\Server\gmmain.cpp 2477
This account is no longer being active.
|
|
|
Re: C++ Question [message #340014 is a reply to message #340009] |
Wed, 09 July 2008 18:26 |
|
saberhawk
Messages: 1068 Registered: January 2006 Location: ::1
Karma: 0
|
General (1 Star) |
|
|
HeavyX101 wrote on Wed, 09 July 2008 19:27 | Ok, this is what i did:
char* preset = atof(Text[1].c_str());
And i got a error:
Error 1 error C2440: 'initializing' : cannot convert from 'double' to 'char *' c:\Westwood\RenegadeFDS\Server\gmmain.cpp 2477
|
atof returns a float or a double...
|
|
|
Re: C++ Question [message #340017 is a reply to message #340014] |
Wed, 09 July 2008 18:31 |
HeavyX101- Left
Messages: 633 Registered: April 2008 Location: WindowsJail=ZipFolder
Karma: 0
|
Colonel |
|
|
Now, i got this:
char* preset = Text[1].c_str();
And the error i got is:
Error 1 error C2440: 'initializing' : cannot convert from 'std::string' to 'char *' c:\Westwood\RenegadeFDS\Server\gmmain.cpp 2477
This account is no longer being active.
|
|
|
Re: C++ Question [message #340113 is a reply to message #339983] |
Thu, 10 July 2008 09:11 |
dead6re
Messages: 602 Registered: September 2003
Karma: 0
|
Colonel |
|
|
I knew someone was going to make that reference to STDs... :S Oh well.
You need to cast the function to become a char*.
Currently you have
char *preset = const char *c_str();
Notice the const? It isn't the same on each side.
Either:
Correctness (Warning: You cannot edit a const char):
const char *preset = Text[1].c_str();
OR:
Casting:
char *preset = (char *)Text[1].c_str();
Let all your wishes be granted except one, so you will still have something to strieve for.
|
|
|
|
|
Re: C++ Question [message #340156 is a reply to message #340143] |
Thu, 10 July 2008 14:08 |
|
saberhawk
Messages: 1068 Registered: January 2006 Location: ::1
Karma: 0
|
General (1 Star) |
|
|
HeavyX101 wrote on Thu, 10 July 2008 15:33 | Anyone knows how to fix it?
|
Don't create a variable if you aren't going to use it. Just use Commands->Create_Object at the start of the line...
|
|
|
Re: C++ Question [message #340168 is a reply to message #340156] |
Thu, 10 July 2008 15:29 |
HeavyX101- Left
Messages: 633 Registered: April 2008 Location: WindowsJail=ZipFolder
Karma: 0
|
Colonel |
|
|
Thanks man, it compiled now. But the game doesnt really work, the preset name i give doesnt deploy.
Anyways, that is my part to fix now. Thanks guys!
This account is no longer being active.
|
|
|
|
Re: C++ Question [message #340319 is a reply to message #340314] |
Fri, 11 July 2008 10:38 |
HeavyX101- Left
Messages: 633 Registered: April 2008 Location: WindowsJail=ZipFolder
Karma: 0
|
Colonel |
|
|
//Made By Ferkhat Shubladze
class presetbuildChatCommand : public ChatCommandClass {
void Triggered(int ID,const TokenClass &Text,int ChatType) {
GameObject *obj = Get_GameObj(ID);
char *preset = (char *)Text[1].c_str();
Vector3 position;
position = Commands->Get_Position(obj);
position.Z += 0;
position.X += (float)(5*cos(Commands->Get_Facing(Get_GameObj(ID))*(3.14 / 180)));
position.Y += (float)(5*sin(Commands->Get_Facing(Get_GameObj(ID))*(3.14 / 180))); // this is gonna be fixed soon
{
Commands->Create_Object(preset,position);
Console_Input(StrFormat("msg WORKS!").c_str());
Commands->Set_Facing(obj, Commands->Get_Facing(obj)-180);
}
}
};
ChatCommandRegistrant<presetbuildChatCommand> presetbuildChatCommandReg("!pbuild",CHATTYPE_ALL,1,GAMEMODE_AOW);
This account is no longer being active.
[Updated on: Fri, 11 July 2008 10:39] Report message to a moderator
|
|
|
Re: C++ Question [message #340354 is a reply to message #339983] |
Fri, 11 July 2008 13:07 |
dead6re
Messages: 602 Registered: September 2003
Karma: 0
|
Colonel |
|
|
class presetbuildChatCommand : public ChatCommandClass {
void Triggered(int ID,const TokenClass &Text,int ChatType) {
GameObject *obj = Get_GameObj(ID);
char *preset = (char *)Text[1].c_str();
Vector3 position;
position = Commands->Get_Position(obj);
position.Z += 0;
position.X += (float)(5*cos(Commands->Get_Facing(Get_GameObj(ID))*(3.14 / 180)));
position.Y += (float)(5*sin(Commands->Get_Facing(Get_GameObj(ID))*(3.14 / 180)));
Commands->Create_Object(preset, position);
Console_Input(StrFormat("msg WORKS!").c_str());
Commands->Set_Facing(obj, Commands->Get_Facing(obj) - 180);
}
};
ChatCommandRegistrant<presetbuildChatCommand> presetbuildChatCommandReg("!pbuild",CHATTYPE_ALL,1,GAMEMODE_AOW);
I would just check where the position is because you are altering it, I've had enough core 4 [intergration of trig functions] this year so I'm not checking it.
My other advice would be to make sure you are sending a valid preset as found in renedit.
Let all your wishes be granted except one, so you will still have something to strieve for.
|
|
|
Re: C++ Question [message #340470 is a reply to message #340354] |
Sat, 12 July 2008 08:59 |
HeavyX101- Left
Messages: 633 Registered: April 2008 Location: WindowsJail=ZipFolder
Karma: 0
|
Colonel |
|
|
Nope, doesnt work.
I think it is still this line:
char *preset = (char *)Text[1].c_str();
It wont read the word/preset name from the message.
This account is no longer being active.
|
|
|