Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » C++ Question
C++ Question [message #339983] Wed, 09 July 2008 14:21 Go to next message
HeavyX101- Left is currently offline  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 Go to previous messageGo to next message
dead6re is currently offline  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 #339990 is a reply to message #339988] Wed, 09 July 2008 14:42 Go to previous messageGo to next message
N1warhead is currently offline  N1warhead
Messages: 319
Registered: May 2006
Location: On the Pc
Karma: 0
Recruit

dead6re wrote on Wed, 09 July 2008 16: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.



Hmm STD Library?

AIDS
HIV
HEP B
HEP C
herpes
sars
I am sure there is more lol.


www.cncmodders.com All your C&C Modding Tutorials/Downloads/Forums, etc! Conquering the C&C universe with a rush of MEDS and MRLS!
Re: C++ Question [message #339999 is a reply to message #339983] Wed, 09 July 2008 15:07 Go to previous messageGo to next message
GrimmNL is currently offline  GrimmNL
Messages: 120
Registered: June 2005
Location: Netherlands, Almere
Karma: 0
Recruit
lol Big Grin

Xfire account: GrimmNL
http://members.lycos.nl/signature/grimm
Re: C++ Question [message #340000 is a reply to message #339988] Wed, 09 July 2008 15:21 Go to previous messageGo to next message
HeavyX101- Left is currently offline  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. Sad


This account is no longer being active.
Re: C++ Question [message #340008 is a reply to message #339983] Wed, 09 July 2008 16:57 Go to previous messageGo to next message
=HT=T-Bird is currently offline  =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 Go to previous messageGo to next message
HeavyX101- Left is currently offline  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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
HeavyX101- Left is currently offline  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 Go to previous messageGo to next message
dead6re is currently offline  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 #340114 is a reply to message #340113] Thu, 10 July 2008 09:33 Go to previous messageGo to next message
HeavyX101- Left is currently offline  HeavyX101- Left
Messages: 633
Registered: April 2008
Location: WindowsJail=ZipFolder
Karma: 0
Colonel
Thanks Very Happy That helped me alot now Smile
Anyways, the line i'm using it for got error. I dont think that i used the "preset" thing right Razz

	GameObject *object = Commands->Create_Object(preset,position);



Error	1	error C2220: warning treated as error - no 'object' file generated	c:\Westwood\RenegadeFDS\Server\gmmain.cpp	2487


Plus a warning:
Warning	2	warning C4189: 'object' : local variable is initialized but not referenced	c:\Westwood\RenegadeFDS\Server\gmmain.cpp	2487


It would be nice if you would help, but if you dont know, then it is ok.


This account is no longer being active.
Re: C++ Question [message #340143 is a reply to message #340114] Thu, 10 July 2008 13:33 Go to previous messageGo to next message
HeavyX101- Left is currently offline  HeavyX101- Left
Messages: 633
Registered: April 2008
Location: WindowsJail=ZipFolder
Karma: 0
Colonel
Anyone knows how to fix it?

This account is no longer being active.
Re: C++ Question [message #340156 is a reply to message #340143] Thu, 10 July 2008 14:08 Go to previous messageGo to next message
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 Go to previous messageGo to next message
HeavyX101- Left is currently offline  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 #340314 is a reply to message #339983] Fri, 11 July 2008 10:19 Go to previous messageGo to next message
dead6re is currently offline  dead6re
Messages: 602
Registered: September 2003
Karma: 0
Colonel
Post your source?

Let all your wishes be granted except one, so you will still have something to strieve for.
Re: C++ Question [message #340319 is a reply to message #340314] Fri, 11 July 2008 10:38 Go to previous messageGo to next message
HeavyX101- Left is currently offline  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 Go to previous messageGo to next message
dead6re is currently offline  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 Go to previous message
HeavyX101- Left is currently offline  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.
Previous Topic: Steath effect skin
Next Topic: DUB Hummer
Goto Forum:
  


Current Time: Wed Nov 13 19:30:22 MST 2024

Total time taken to generate the page: 0.01420 seconds