Jump to content
Sign in to follow this  
G4meM0ment

Error Generic error in expression in a if statement

Recommended Posts

I used execVM in the init to call this script, it's used to indetify the players and execute different scripts for each player.

_playerArray = ["p1", "p2", "p3", "p4", "dummy1"];
_playerCounter = 0;
while {(_playerCounter  +1) < (count _playerArray)} do {
if ((_playerArray select _playerCounter) == player) then {
//		if(_playerCounter == 0) then {
//			execVM "Scripts\Player\p1 start.sqf";
//		};
	if(_playerCounter == 1) then {
		execVM "Scripts\Player\p2 start.sqf";
	};
	if(_playerCounter == 2) then {
		execVM "Scripts\Player\p3 start.sqf";
	};
	if(_playerCounter == 3) then {
		execVM "Scripts\Player\p4 start.sqf";
	};
	if(_playerCounter == 4) then {
		execVM "Scripts\Player\p1 start.sqf";
	};
};
_playerCounter = _playerCounter +1;
};

The problem I get this errror...

Error in expression <f ((_playerArray select _playerCounter) == player) then {
hint "Is Player";
i>
 Error position: <== player) then {
hint "Is Player";
i>
 Error Generic error in expression

Absolutly now clue whats wrong... sorry if it's just a dump careless mistake.

Thank you for the help :)

Greets Julian

Share this post


Link to post
Share on other sites

Try

_playerArray = [p1, p2, p3, p4, dummy1];

They can't be strings.

Share this post


Link to post
Share on other sites
Try

_playerArray = [p1, p2, p3, p4, dummy1];

They can't be strings.

I figured the problem out, yes you were right, and it needed to be if ( vehicle .... == player).

But now I got a new problem I want to use this script to check if a player joined or if an script is needed to handle this unit.

I use it in the init.sqf with the statement if(!isServer) exeitWith{}; but it don't works my debug just tells me "reached main" but it doesn't seems to reach the while loop.

May you have an idea what's going wrong?

_playerArray = [dummy1, p2, p3, p4];
_playerCounter = 0;
//Variables to check if this unit is a player or not and which player
_sec_player = 0;
_third_player = 0;
_fourth_player = 0;
_p1isP = 0;
_p2isP = 0;
_p3isP = 0;
_p4isP = 0;
//stands for newcomer this counter counts until 300 after that 2 units will die
_nc = 0;
hint "reached main";
scopeName "main";
while {(_playerCounter  +1) < (count _playerArray)} do {
hint "reached while";
//checks if the unit is a player
if(vehicle (_playerArray select _playerCounter) == player) then {
	//checks which unit is detected and starts his script
	if(_playerCounter == 0 && _p1isP == 0) then {
		hint "Player 1 found";
		execVM "Scripts\Player\p1 start.sqf";
		_p1isP = 1;
		//jumps to the end
		breakTo "end";
	};

	if(_playerCounter == 1 && _p1isP == 0) then {
		execVM "Scripts\Player\p2 start.sqf";
		_p2isP = 1;

		if (_p2isP == 0) then {
			if(_sec_player < 1) then {_sec_player = 1; _p2isP = 1; breakTo "end";};
			if(_third_player < 1) then {_third_player = 1; _p2isP = 1; breakTo "end";};
			if(_fourth_player < 1) then {_fourth_player = 1; _p2isP = 1; breakTo "end";};
		};
	};

	if(_playerCounter == 2 && _p1isP == 0) then {
		execVM "Scripts\Player\p3 start.sqf";
		_p3isP = 1;

		if (_p3isP == 0) then {
			if(_sec_player < 1) then {_sec_player = 2; _p3isP = 1; breakTo "end";};
			if(_third_player < 1) then {_third_player = 2; _p3isP = 1; breakTo "end";};
			if(_fourth_player < 1) then {_fourth_player = 2; _p3isP = 1; breakTo "end";};
		};
	};

	if(_playerCounter == 3 && _p1isP == 0) then {
		execVM "Scripts\Player\p4 start.sqf";
		_p3isP = 1;

		if (_p3isP == 0) then {
			if(_sec_player < 1) then {_sec_player = 3; _p4isP = 1; breakTo "end";};
			if(_third_player < 1) then {_third_player = 3; _p4isP = 1; breakTo "end";};
			if(_fourth_player < 1) then {_fourth_player = 3; _p4isP = 1; breakTo "end";};
	};
};
else {
	//if the unit isn't a player an AI script will be started
	if(_playerCounter == 1 && _sec_player != 1 && _third_player != 1 && _fourth_player != 1) then {
		execVM "Scripts\Player\AI2 init.sqf";
		_p2isP = 0;
		breakTo "end";
	};
	if(_playerCounter == 2 && _sec_player != 2 && _third_player != 2 && _fourth_player != 2) then {
		execVM "Scripts\Player\AI3 init.sqf";
		_p3isP = 0;
		if(_nc > 300) {};//KILL AI SCRIPT
		breakTo "end";
	};
	if(_playerCounter == 3 && _sec_player != 3 && _third_player != 3 && _fourth_player != 3) then {
		execVM "Scripts\Player\AI4 init.sqf";
		_p4isP = 0;
		if(_nc > 300) {};//KILL AI SCRIPT
		breakTo "end";
	};
};
//if anything had been detected the script will jump to this point and repeat to check the next unit
scopeName "end";
_playerCounter = _playerCounter +1;

};
//5 min after the game started unit 3 & 4 will be available to be played by an player after that they get killed
while{_nc <= 300} do {
_nc = _nc +1;
sleep 1;
_playerCounter = 0;
breakTo "main";
};
//simply restarts the script and checks all units again
while {true} do {
sleep 1;
_playerCounter = 0;
breakTo "main";
};

---------- Post added at 20:33 ---------- Previous post was at 20:28 ----------

I need to add that there is no error.

Share this post


Link to post
Share on other sites

I found that too, but there is a problem with the "if(_nc > 300) {};//KILL AI SCRIPT" it says ; is missing.

Share this post


Link to post
Share on other sites

if(_nc > 300) then {};//KILL AI SCRIPT

Share this post


Link to post
Share on other sites

There is still another problem too, if the players 2,3,4 arent used (I tried this out in sp (preview)) the script will never go into the "else"-part of the statement in line 16.

I set these units as playable but it doesnt seems to matter if theyre playable or not...

_playerArray = [dummy1, p2, p3, p4];
_playerCounter = 0;
//Variables to check if this unit is a player or not and which player
_sec_player = 0;
_third_player = 0;
_fourth_player = 0;
_p1isP = 0;
_p2isP = 0;
_p3isP = 0;
_p4isP = 0;
//stands for newcomer this counter counts until 300 after that 2 units will die
_nc = 0;
scopeName "main";
while {(_playerCounter  +1) < (count _playerArray)} do {
//checks if the unit is a player
if(vehicle (_playerArray select _playerCounter) == player) then {    //<---- LINE 16
	//checks which unit is detected and starts his script
	if(_playerCounter == 0 && _p1isP == 0) then {
		execVM "Scripts\Player\p1 start.sqf";
		_p1isP = 1;
		//jumps to the end
		breakTo "end";
	};

	if(_playerCounter == 1 && _p2isP == 0) then {
		execVM "Scripts\Player\p2 start.sqf";
		hint "Player 2 found";

		if (_p2isP == 0) then {
			if(_sec_player < 1) then {_sec_player = 1; _p2isP = 1; breakTo "end";};
			if(_third_player < 1) then {_third_player = 1; _p2isP = 1; breakTo "end";};
			if(_fourth_player < 1) then {_fourth_player = 1; _p2isP = 1; breakTo "end";};
			_p2isP = 1;
		};
	};

	if(_playerCounter == 2 && _p3isP == 0) then {
		execVM "Scripts\Player\p3 start.sqf";
		hint "Player 3 found";

		if (_p3isP == 0) then {
			if(_sec_player < 1) then {_sec_player = 2; _p3isP = 1; breakTo "end";};
			if(_third_player < 1) then {_third_player = 2; _p3isP = 1; breakTo "end";};
			if(_fourth_player < 1) then {_fourth_player = 2; _p3isP = 1; breakTo "end";};
			_p3isP = 1;
		};
	};

	if(_playerCounter == 3 && _p4isP == 0) then {
		execVM "Scripts\Player\p4 start.sqf";
		hint "Player 4 found";

		if (_p3isP == 0) then {
			if(_sec_player < 1) then {_sec_player = 3; _p4isP = 1; breakTo "end";};
			if(_third_player < 1) then {_third_player = 3; _p4isP = 1; breakTo "end";};
			if(_fourth_player < 1) then {_fourth_player = 3; _p4isP = 1; breakTo "end";};
			_p4isP = 1;
		};
	};
}
else {                                                                                                                   //<--- THE ELSE-PART
	hint "else";
	//if the unit isn't a player an AI script will be started
	if(_playerCounter == 1 && _sec_player != 1 && _third_player != 1 && _fourth_player != 1) then {
		execVM "Scripts\Player\AI2 init.sqf";
		_p2isP = 0;
		breakTo "end";
	};
	if(_playerCounter == 2 && _sec_player != 2 && _third_player != 2 && _fourth_player != 2) then {
		execVM "Scripts\Player\AI3 init.sqf";
		_p3isP = 0;
//			if(_nc > 300) {hint "Killed 3"};//KILL AI SCRIPT

		hint "AI 3 found";

		breakTo "end";
	};
	if(_playerCounter == 3 && _sec_player != 3 && _third_player != 3 && _fourth_player != 3) then {
		execVM "Scripts\Player\AI4 init.sqf";
		_p4isP = 0;
//			if(_nc > 300) {hint "Killed 4"};//KILL AI SCRIPT

		hint "AI 4 found";

		breakTo "end";
	};
};
//if anything had been detected the script will jump to this point and repeat to check the next unit
scopeName "end";
_playerCounter = _playerCounter +1;
};
//5 min after the game started unit 3 & 4 will be available to be played by an player after that they get killed
while{_nc <= 300} do {
_nc = _nc +1;
sleep 1;
_playerCounter = 0;
breakTo "main";
};
//simply restarts the script and checks all units again
while {true} do {
sleep 1;
_playerCounter = 0;
breakTo "main";
};

---------- Post added at 23:58 ---------- Previous post was at 23:56 ----------

if(_nc > 300) then {};//KILL AI SCRIPT

Sry I'm not so familiar with that linguistic scripting languages, sorry for that but I just posted the real problem...

Share this post


Link to post
Share on other sites

Can't say I understand the script but if the player is anyone of dummy1, p2, p3, p4 the else can't fire.

That's how it read to me.

Share this post


Link to post
Share on other sites
Can't say I understand the script but if the player is anyone of dummy1, p2, p3, p4 the else can't fire.

That's how it read to me.

Why? I ask if the one who is getting checked is == player if not shouldn't it jump over to else?

Share this post


Link to post
Share on other sites

I think the problem is your using breakto as a goto and I don't think it works that way.

scopeName "end";

_playerCounter = _playerCounter +1;

Hint "this isn't working";

If you add the hint after the scope it never fires, basically the code just seems to freeze.

Maybe switch/case may be better.

Share this post


Link to post
Share on other sites
I think the problem is your using breakto as a goto and I don't think it works that way.

scopeName "end";

_playerCounter = _playerCounter +1;

Hint "this isn't working";

If you add the hint after the scope it never fires, basically the code just seems to freeze.

Maybe switch/case may be better.

Yes switch/case would be better, but it wouldn't fit the scope problem, would it?

I tried this, but it don't works:

scopeName "main";
while {(_playerCounter  +1) < (count _playerArray)} do {
//checks if the unit is a player
if(vehicle (_playerArray select _playerCounter) == player) then {
	//checks which unit is detected and starts his script
	while{_playerCounter == 0 && _p1isP == 0} do {
		execVM "Scripts\Player\p1 start.sqf";
		_p1isP = 1;
		//jumps to the end
		_playerCounter = _playerCounter +1;
		breakTo "main";
	};

	...
}
else {
	hint "else";
	//if the unit isn't a player an AI script will be started
	while{_playerCounter == 1 && _sec_player != 1 && _third_player != 1 && _fourth_player != 1} do {
		execVM "Scripts\Player\AI2 init.sqf";
		_p2isP = 0;
		_playerCounter = _playerCounter +1;
		breakTo "main";
	};
	while{_playerCounter == 2 && _sec_player != 2 && _third_player != 2 && _fourth_player != 2} do {
		execVM "Scripts\Player\AI3 init.sqf";
		_p3isP = 0;
//			if(_nc > 300) then {hint "Killed 3"};//KILL AI SCRIPT

		hint "AI 3 found";

		_playerCounter = _playerCounter +1;
		breakTo "main";
	};
	while{_playerCounter == 3 && _sec_player != 3 && _third_player != 3 && _fourth_player != 3} do {
		execVM "Scripts\Player\AI4 init.sqf";
		_p4isP = 0;
//			if(_nc > 300) then {hint "Killed 4"};//KILL AI SCRIPT

		hint "AI 4 found";

		_playerCounter = _playerCounter +1;
		breakTo "main";
	};
};
};

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×