SA-MP Forums Archive
if statement - invalid expression assumed 0 - 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)
+--- Thread: if statement - invalid expression assumed 0 (/showthread.php?tid=580082)



if statement - invalid expression assumed 0 - NoahF - 02.07.2015

Код:
	if(getCheckpointType(playerid) != CP_BurgerShotMain && getCheckpointType(playerid) != CP_CluckinBellMain &&
	getCheckpointType(playerid) != CP_Ammunation && getCheckpointType(playerid) != CP_GayDarMain &&
	getCheckpointType(playerid) != CP_ZeroMain && getCheckpointType(playerid) != CP_MistysMain &&
	getCheckpointType(playerid) != CP_GYM && getCheckpointType(playerid) != CP_School &&
	getCheckpointType(playerid) != CP_WangCars && getCheckpointType(playerid) != CP_Train &&
	getCheckpointType(playerid) != CP_Barbers && getCheckpointType(playerid) != CP_PizzaMain &&
	getCheckpointType(playerid) != CP_ZipMain && getCheckpointType(playerid) != CP_VictimMain &&
	getCheckpointType(playerid) != CP_BincoMain && getCheckpointType(playerid) != CP_CityHallMain &&
	getCheckpointType(playerid) != CP_Jizzys && getCheckpointType(playerid) != CP_Urban &&
	getCheckpointType(playerid) != CP_Church && getCheckpointType(playerid) != CP_DF &&
	getCheckpointType(playerid) != CP_Zombotech && getCheckpointType(playerid) != CP_Bank &&
	getCheckpointType(playerid) != CP_Mint -- The error is here. Invalid Expression - Assumed 0
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You are not in the checkpoint of anywhere you can rob.");
	    return 1;
	}



Re: if statement - invalid expression assumed 0 - Virtual1ty - 02.07.2015

You forgot to close the outer opening round bracket :
Код:
	if(getCheckpointType(playerid) != CP_BurgerShotMain && getCheckpointType(playerid) != CP_CluckinBellMain &&
	getCheckpointType(playerid) != CP_Ammunation && getCheckpointType(playerid) != CP_GayDarMain &&
	getCheckpointType(playerid) != CP_ZeroMain && getCheckpointType(playerid) != CP_MistysMain &&
	getCheckpointType(playerid) != CP_GYM && getCheckpointType(playerid) != CP_School &&
	getCheckpointType(playerid) != CP_WangCars && getCheckpointType(playerid) != CP_Train &&
	getCheckpointType(playerid) != CP_Barbers && getCheckpointType(playerid) != CP_PizzaMain &&
	getCheckpointType(playerid) != CP_ZipMain && getCheckpointType(playerid) != CP_VictimMain &&
	getCheckpointType(playerid) != CP_BincoMain && getCheckpointType(playerid) != CP_CityHallMain &&
	getCheckpointType(playerid) != CP_Jizzys && getCheckpointType(playerid) != CP_Urban &&
	getCheckpointType(playerid) != CP_Church && getCheckpointType(playerid) != CP_DF &&
	getCheckpointType(playerid) != CP_Zombotech && getCheckpointType(playerid) != CP_Bank &&
	getCheckpointType(playerid) != CP_Mint) // you missed a ')' here
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You are not in the checkpoint of anywhere you can rob.");
	    return 1;
	}
Also I suggest you save that "checkpoint type" in to a variable rather than calling the function "getCheckpointType" X times.
Like this:
Код:
	new cp_type = getCheckpointType(playerid);
	if (cp_type != CP_BurgerShotMain && cp_type != CP_CluckinBellMain &&
	    cp_type != CP_Ammunation && cp_type != CP_GayDarMain &&
	    cp_type != CP_ZeroMain && cp_type != CP_MistysMain &&
	    cp_type != CP_GYM && cp_type != CP_School &&
	    cp_type != CP_WangCars && cp_type != CP_Train &&
	    cp_type != CP_Barbers && cp_type != CP_PizzaMain &&
	    cp_type != CP_ZipMain && cp_type != CP_VictimMain &&
	    cp_type != CP_BincoMain && cp_type != CP_CityHallMain &&
	    cp_type != CP_Jizzys && cp_type != CP_Urban &&
	    cp_type != CP_Church && cp_type != CP_DF &&
	    cp_type != CP_Zombotech && cp_type != CP_Bank &&
	    cp_type != CP_Mint)
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You are not in the checkpoint of anywhere you can rob.");
	    return 1;
	}



Re: if statement - invalid expression assumed 0 - NoahF - 02.07.2015

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
You forgot to close the outer opening round bracket :
Код:
	if(getCheckpointType(playerid) != CP_BurgerShotMain && getCheckpointType(playerid) != CP_CluckinBellMain &&
	getCheckpointType(playerid) != CP_Ammunation && getCheckpointType(playerid) != CP_GayDarMain &&
	getCheckpointType(playerid) != CP_ZeroMain && getCheckpointType(playerid) != CP_MistysMain &&
	getCheckpointType(playerid) != CP_GYM && getCheckpointType(playerid) != CP_School &&
	getCheckpointType(playerid) != CP_WangCars && getCheckpointType(playerid) != CP_Train &&
	getCheckpointType(playerid) != CP_Barbers && getCheckpointType(playerid) != CP_PizzaMain &&
	getCheckpointType(playerid) != CP_ZipMain && getCheckpointType(playerid) != CP_VictimMain &&
	getCheckpointType(playerid) != CP_BincoMain && getCheckpointType(playerid) != CP_CityHallMain &&
	getCheckpointType(playerid) != CP_Jizzys && getCheckpointType(playerid) != CP_Urban &&
	getCheckpointType(playerid) != CP_Church && getCheckpointType(playerid) != CP_DF &&
	getCheckpointType(playerid) != CP_Zombotech && getCheckpointType(playerid) != CP_Bank &&
	getCheckpointType(playerid) != CP_Mint) // you missed a ')' here
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You are not in the checkpoint of anywhere you can rob.");
	    return 1;
	}
Also I suggest you save that "checkpoint type" in to a variable rather than calling the function "getCheckpointType" X times.
Like this:
Код:
	new cp_type = getCheckpointType(playerid);
	if (cp_type != CP_BurgerShotMain && cp_type != CP_CluckinBellMain &&
	    cp_type != CP_Ammunation && cp_type != CP_GayDarMain &&
	    cp_type != CP_ZeroMain && cp_type != CP_MistysMain &&
	    cp_type != CP_GYM && cp_type != CP_School &&
	    cp_type != CP_WangCars && cp_type != CP_Train &&
	    cp_type != CP_Barbers && cp_type != CP_PizzaMain &&
	    cp_type != CP_ZipMain && cp_type != CP_VictimMain &&
	    cp_type != CP_BincoMain && cp_type != CP_CityHallMain &&
	    cp_type != CP_Jizzys && cp_type != CP_Urban &&
	    cp_type != CP_Church && cp_type != CP_DF &&
	    cp_type != CP_Zombotech && cp_type != CP_Bank &&
	    cp_type != CP_Mint)
	{
	    SendClientMessage(playerid,COLOR_ERROR,"You are not in the checkpoint of anywhere you can rob.");
	    return 1;
	}
Thank you, that fixed the problem.


Re: if statement - invalid expression assumed 0 - Suicidal.Banana - 02.07.2015

I would also suggest adding brackets, so the code will never get confused about what you mean (seriouslly, its quite disturbing to me how NOBODY on these forums seems to use brackets to combine statements)

'Bad':
Код:
if (cp_type != CP_BurgerShotMain && cp_type != CP_CluckinBellMain && ...
Good:
Код:
if ((cp_type != CP_BurgerShotMain) && (cp_type != CP_CluckinBellMain) && ...
I could type out some elaborate story, but the gist of it is that making blocks makes it easier to handle your code, it doesnt have to start guessing what you mean with all the comparisons and and statements, and it improves human readability too


Re: if statement - invalid expression assumed 0 - Vince - 02.07.2015

This is just unmaintainable to begin with. Do some research on arrays, please. Ideally, if something is to be changed you'd do it one place, and one place only.