Weird str_to_num problem

Posted By: Leonardo

Weird str_to_num problem - 06/16/08 14:35

I'm trying to make an account system for a small MP application, but I ran into a very weird problem today smile
Here's the code:

Code:
If(str_len(username_str) > 5 && str_len(password_str) > 5 && player == null)
	{
		str_cpy(id_str,player_name);
		str_clip(id_str,6);
		client_id1 = str_to_num(id_str);
		player = ent_create("arrow.pcx",vector(1000,1000,1000), mp_entity);
		sleep(1);
		player.ID = client_id1;
		send_skill(player.ID,0);
		str_cpy(login_command,id_str);
		str_cat(login_command,"*");
		str_cat(login_command,username_str);
		str_cat(login_command,"*");
		str_cat(login_command,password_str);
		send_string(login_command);
	}


username_str, password_str and id_str are strings, client_id1 is a variable... what I'm trying to do, is get a unique client ID by clipping 6 characters off of the string "player_name", then turning it into a variable using str_to_num and then send it to the newly created player entity.
Now, the problem is - client_id1 isn't the same as id_str!! No matter what I do, client_id1 just looks like a random number every time! But id_str is correct - if player_name is, for example, Client8141723, then id_str is 8141723...
I have checked every line of my code, I don't have variables with the same name, or something like that, so what's wrong?
Posted By: testDummy

Re: Weird str_to_num problem - 06/16/08 18:50

1. over flow problem for var type
--see max value for var (999,999.999?)
--sample var in post was > 8 million (not 6 chars)?
--difficulty in counting digits?
----might be typical for scope
2. variables may change on sleep, wait, etc.
3. performance: ? no short circuit (&&, &&, &&)
--do separately and skip if false?


Posted By: Leonardo

Re: Weird str_to_num problem - 06/16/08 19:02

That is just great.... the thing about programming is that - it's not the big problems that make me mad, it's these small, insignificant little things that just drive me crazy!!
But thank you, the over-flow problem was the right one smile
© 2024 lite-C Forums