SA-MP Forums Archive
String comparison - 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: String comparison (/showthread.php?tid=248402)



String comparison - Anteino - 13.04.2011

I got this code:

Код:
#include <a_samp>
#include <YSI/y_ini>
#include "../include/gl_common.inc"
#include <string>

#define FILTERSCRIPT
#define COLOR_WHITE 0xFFFFFFFF

new PlayerName[MAX_PLAYER_NAME], Password[MAX_PASSWORD];

INI:playerlist[](playerid, name[], value[])
{
    INI_String(PlayerName, Password, sizeof(Password));
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[]){
    new idx;
    new cmd[256];
	cmd = strtok(cmdtext, idx);

    if(strcmp("/ls", cmd, true) == 0){
		GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
	    INI_Load("playerlist.ini", true, playerid);     // if set to true, playerid will be passed over to INI:playerlist[...
	    SendClientMessage(playerid, COLOR_WHITE, Password);
	    if(strcmp(Password, "") == 0){
			ShowPlayerDialog(playerid, 30, 1, "Register", "To register you must first give in the first name of your character.", "OK", "Cancel");
			return 1;
	    }
	    else{
	        ShowPlayerDialog(playerid, 33, 1, "Login", "Please give in your password.", "OK", "Cancel");
	        return 1;
		}
	}
    return 0;
}
So when the string Password is empty you'll get the register dialog, however when Password contains "somepass" or any other text it will still show the register dialog. I've tried to edit Password manually but nothing seems to work. The SendClientMessage will allways show the password in the playerlist.ini so I think the error lies int strcmp?

EDIT: I defined MAX_PASSWORD in <a_samp>


Re: String comparison - JaTochNietDan - 13.04.2011

Comparing to an empty string will always return false, so that snippet of code won't work, instead of strcmp use strlen, for example:

pawn Код:
if(strlen(Password) == 0)



Re: String comparison - Anteino - 13.04.2011

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Comparing to an empty string will always return false, so that snippet of code won't work, instead of strcmp use strlen, for example:

pawn Код:
if(strlen(Password) == 0)
OH MY F.. god
waarom ben ik daar niet op gekomen !!
maar bedankt