SA-MP Forums Archive
Handling data from read files - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Handling data from read files (/showthread.php?tid=149354)



Handling data from read files - plutoniumman - 21.05.2010

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


Re: Handling data from read files - dice7 - 21.05.2010

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


Re: Handling data from read files - plutoniumman - 21.05.2010

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!