PDA

View Full Version : STR DEFINE to INTEGER


mysticssjgoku4
06-09-2010, 19:35
So this is irritating. Why doesn't this work, and is there an alternative?


#define A_SG_Marines_3_val "30"

new g_Scans_Needed = str_to_num(A_SG_Marines_3_val);
new g_Scans[33][g_Scans_Needed];

wrecked_
06-09-2010, 19:39
Define it as an integer? o.o

Bugsy
06-09-2010, 19:40
So this is irritating. Why doesn't this work, and is there an alternative?


#define A_SG_Marines_3_val "30"

new g_Scans_Needed = str_to_num(A_SG_Marines_3_val);
new g_Scans[33][g_Scans_Needed];


#define A_SG_Marines_3_val 30

new g_Scans[33][A_SG_Marines_3_val];

mysticssjgoku4
06-09-2010, 19:43
#define A_SG_Marines_3_val 30

new g_Scans[33][A_SG_Marines_3_val];

I need that define as a string.

Bugsy
06-09-2010, 19:43
I need that define as a string.

Tell me why and Ill give you a solution.

mysticssjgoku4
06-09-2010, 19:53
The function I use requires a string for the entire system of plugins I am coding, and I don't feel like editing through 1000's of lines of code changing it over, and unnecessarily converting over each number to a string before use just because I need just this one define as an integer.

Bugsy
06-09-2010, 19:56
The function I use requires a string for the entire system of plugins I am coding, and I don't feel like editing through 1000's of lines of code changing it over, and unnecessarily converting over each number to a string before use just because I need just this one define as an integer.

#define g_Scans_Needed 30

new A_SG_Marines_3_val[ 3 ]
new g_Scans[33][ g_Scans_Needed ];

public plugin_init()
num_to_str( g_Scans_Needed , A_SG_Marines_3_val , 2 );

mysticssjgoku4
06-09-2010, 19:59
#define THENUMBER 30

new TheVar[ 33 ][ THENUMBER ];
new A_SG_Marines_3_val[ 3 ]; //Use this for all other functions that need the string

//plugin_init
num_to_str( THENUMBER , A_SG_Marines_3_val , 2 );

Hmm. Thanks, ill mess around and figure something out I suppose. I am trying to keep the system uniform in style.

ConnorMcLeod
06-10-2010, 01:25
Problem is that you can only use str_to_num(A_SG_Marines_3_val) in a function, and other problem is that you can only set an array size with a const.
That's why Bugsy took the problem in the other way, so you build the string from the const integer instead of retrieve the integer from the string.

Alucard^
06-10-2010, 07:00
Use Bugsy code, is better than mine, cuz my code is only an example starting with string (only to understand why your code doesn't work):


new const A_SG_Marines_3_val[] = "30";

new g_Scans_Needed = str_to_num(A_SG_Marines_3_val);
new g_Scans[33][g_Scans_Needed];


Also, maybe the num_to_str() is useless, depends on where you will use the string num... where? maybe in the function that you want to the num as string, you can use %d.

Sry for my english.

fysiks
06-10-2010, 17:39
Use Bugsy code, is better than mine, cuz my code is only an example starting with string (only to understand why your code doesn't work):


new const A_SG_Marines_3_val[] = "30";

new g_Scans_Needed = str_to_num(A_SG_Marines_3_val);
new g_Scans[33][g_Scans_Needed];


Also, maybe the num_to_str() is useless, depends on where you will use the string num... where? maybe in the function that you want to the num as string, you can use %d.

Sry for my english.

You cannot declare and array size with a non-constant variable (g_Scans_Needed). Your code will not compile.

Alucard^
06-10-2010, 18:02
So "new const" fix the problem? sry for not test this but, i have to go now xd, cya.

Bugsy
06-10-2010, 18:13
Just use what I posted above, it is the best way to do what you're trying to do. new const x = str_to_num() will not work if that's what you were going to try.