Doom3world

The world is yours! Doom 3 - Quake 4 - ET:QW - Prey - Rage
It is currently Sat May 25, 2013 3:17 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Returning the length of a string?
PostPosted: Sun Nov 29, 2009 1:06 am 
Offline
picked up 100 armour

Joined: Wed May 16, 2007 10:36 pm
Posts: 147
Hello everybody, I have been trying to find out how to return the length of a string, I am still a newb in C++, so sorry in advance for my dumb questions.

I am currently using "const char* name;" to declare my string variable but I will probably change to "char* name;" as I thinks the const keyword will make it unchangeable.

I have seen method using the strlen function, but this function is not implemented in D3/Q4. It also seem like I absolutly need to set a character limit to my string.... Also, I have seen thoses idStr but they seem even more harder to understand, and I thinks I would probably need to constantly need to covert from char* to idStr and vice versa if I was to use that class.

Did anybody found a way to get the size of a string stored in a char* variable?

I am kinda lost in that C++ world right now, lol :P

_________________
http://www.g-modders.com


Top
 Profile  
 
 Post subject: Re: Returning the length of a string?
PostPosted: Sun Nov 29, 2009 1:49 am 
Offline
Last man standing
User avatar

Joined: Fri Jan 07, 2005 12:27 am
Posts: 1050
Use the idStr class' Length method, it returns int. (that is if you want to know how any characters it has, rather than how much memory it consumes.)


Top
 Profile  
 
 Post subject: Re: Returning the length of a string?
PostPosted: Sun Nov 29, 2009 8:38 am 
Offline
picked up 100 armour

Joined: Wed May 16, 2007 10:36 pm
Posts: 147
Ahh Thanks! I was close to find it, unfortunally, everytimes I was searching the common length, I was typing lenght, which explain why I never found this function during my search. At least I have learn my lesson, at the same, time, it corrected my bad english vocabulary.

I might have another question tough.

Is it possible to use the function .GetString, to get a string from within the player.cpp, or player.h. It seem we can only grab strings from entitys ... :(

or

Is there a way to make idStr array works. I have tryed multiple ways to get it work, but each time, I encoutered this damn "Error C2108: subscript is not of integral type". GrrRrr

I was doing something like
Code:
idStr temp = SZString[i];
int stringSize = temp.Length();


But yeah, Like I said, the error as stated previously always appear, like if it was impropely done... :(

_________________
http://www.g-modders.com


Top
 Profile  
 
 Post subject: Re: Returning the length of a string?
PostPosted: Sun Nov 29, 2009 8:25 pm 
Offline
Last man standing
User avatar

Joined: Fri Apr 22, 2005 11:55 pm
Posts: 1180
Quote:
Is it possible to use the function .GetString, to get a string from within the player.cpp, or player.h. It seem we can only grab strings from entitys

I assume you are referring to the GetString function of the idDict class (the one used for spawnargs).
You can use it wherever you want as long as you are doing things right.

idEntity class has the "idDict spawnArgs" variable, so you can call that function on it.
idPlayer class inherits from idEntity, so it has the spawnArgs variable as well.


About the code you posted, make sure "i" is an int.

_________________
Fragging Free - a frantic Doom3:ROE single-player modification.


Top
 Profile  
 
 Post subject: Re: Returning the length of a string?
PostPosted: Mon Nov 30, 2009 2:02 am 
Offline
picked up 100 armour

Joined: Wed May 16, 2007 10:36 pm
Posts: 147
Oh nice find over there, I didn't thought about the [i] that would absolutly require to be an integer, maybe that was the source of the problem.

Otherwise,if that wasnt the problem, I will try but my variable somewhere inside the idPlayer class, I will probably find out where it is really soon, and see what kind of results I can now get. Thanks for giving me a light on this dark path once again! :P

Edit : AHhHHhH! It seem to work, it was just that damn i, Ahhh, thats what happen when you become too used to use float for any integer/float while scripting. Thanks a lots Ivan :P

_________________
http://www.g-modders.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group