Handling data from read files
#1

Hi all

I'm trying to make my own basic script to verify if a user is an admin or not.
The idea is that it'll load a file with the same name as the user, and the file will have a value of either a 1 or a 0.
Te 1 will represent the user as an admin and 0 will be a regular user.

My script can load the file and read it just fine. The problem is once I get the value I can't do anything with it.

Код:
	new name [MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, sizeof(name));
	new string[64];
	new File:user = fopen(name, io_read);
	fread(user, string);
	
	
	if (string[1] == 1){
	printf("Is admin");
	} else {
	printf("Is not admin");
	}
	printf("\n%s",string);
	fclose(user);
The if and else bit won't reconize the value of 'string' being 1, even though printf prints 1 or whatever value I make the file. I'm pretty sure it's just me doing a bad job initializing/calling the veriables.. Been a while since I wrote something more complex than javascript :P

Any tips or help will be greatly appreciated
Reply
#2

pawn Код:
if (string[1] == '1')
since the ascii value of '1' and 1 is different, And arrays start with index 0, not 1
Reply
#3

Quote:
Originally Posted by dice7
pawn Код:
if (string[1] == '1')
since the ascii value of '1' and 1 is different, And arrays start with index 0, not 1
I knew it was the way I was handling variables!! Thanks a ton!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)