ShaZe@Posted: Sun Nov 29, 2009 1:06 am :
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



parsonsbear@Posted: Sun Nov 29, 2009 1:49 am :
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.)



ShaZe@Posted: Sun Nov 29, 2009 8:38 am :
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... :(



Ivan_the_B@Posted: Sun Nov 29, 2009 8:25 pm :
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.



ShaZe@Posted: Mon Nov 30, 2009 2:02 am :
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



ShaZe@Posted: Sun Nov 29, 2009 1:06 am :
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



parsonsbear@Posted: Sun Nov 29, 2009 1:49 am :
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.)



ShaZe@Posted: Sun Nov 29, 2009 8:38 am :
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... :(



Ivan_the_B@Posted: Sun Nov 29, 2009 8:25 pm :
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.



ShaZe@Posted: Mon Nov 30, 2009 2:02 am :
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



ShaZe@Posted: Sun Nov 29, 2009 1:06 am :
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



parsonsbear@Posted: Sun Nov 29, 2009 1:49 am :
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.)



ShaZe@Posted: Sun Nov 29, 2009 8:38 am :
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... :(



Ivan_the_B@Posted: Sun Nov 29, 2009 8:25 pm :
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.



ShaZe@Posted: Mon Nov 30, 2009 2:02 am :
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