Jump to content
Sign in to follow this  
lkincheloe

[solved] Non-Combatant script issue

Recommended Posts

I'm working on a script that allows for players to be non-combatants on a belligerent side (i.e. not civilian), however while expanding to nested If statements I have encountered an Error missing ) issue in the else statement, it's perplexed me and I think a rubber duck debug is in order.

 

private ["_noncomState", "_wArray"];

_noncomState = player getVariable "var_lk_noncom";

_wArray = weapons player;

if (count _wArray == 0) then

	{

	if (_noncomState == false) then
	
		{
		
		player setCaptive 1.44; hint "You are a non-Combatant!"; player setVariable ["var_lk_noncom", true]
		
		} else [];
	
	}

else

	{

	if (_noncomState == true) then
	
		(
		
		player setCaptive 0; hint "You are a Combatant!"; player setVariable ["var_lk_noncom", false]
		
		) else [];

	};

This is the error that's produced:

16:36:46 Error in expression <te == true) then

(

player setCaptive 0; hint "You are a Combatant!"; player se>
16:36:46   Error position: <; hint "You are a Combatant!"; player se>
16:36:46   Error Missing )
16:36:46 File C:\Users\Lynn\Documents\Arma 3 - Other Profiles\Kinch\missions\n..., line 29
16:36:46 Error in expression <te == true) then

(

player setCaptive 0; hint "You are a Combatant!"; player se>
16:36:46   Error position: <; hint "You are a Combatant!"; player se>
16:36:46   Error Missing )
16:36:46 File C:\Users\Lynn\Documents\Arma 3 - Other Profiles\Kinch\missions\n..., line 29
16:36:46  Mission id: 4964a4130cdf29b09d84b46e8d2333956209f5c6

 

The error points to if (_noncomState == true) as being the culprit, however being formatted identically to the first part is confusing me. The script is initialized from a sequence starting from InitPlayerLocal.sqf, and the intent of the variable var_lk_noncom is to give the script something to check against so that the SetCaptive command isn't spammed every time a player's inventory changes state.

 

Suggestions?

Share this post


Link to post
Share on other sites

There maybe something I've missed as I'm looking from my phone, but i think you've overcomplicated things;

 

if (_nonComState) then {

    //true code

    } else {

    //false code

};

https://community.bistudio.com/wiki/if

 

Ok, so looking at it from the PC the second if.then statement isn't formatted identically. You've used ( ) where they need to be { }. But still:

if (_nonComState) then {
	//true code
	player setCaptive true;
	hint "You are a non-Combatant!";
	player setVariable ["var_lk_noncom",true];
	} else {
	//false code
	player setCaptive false;
	hint "You are a Combatant!";
	player setVariable ["var_lk_noncom",false];
};

 

  • Like 1

Share this post


Link to post
Share on other sites

Thank you Beno, with your info I was able to work out what was causing the script to fail. I kept the added complexity (the variable check) since I don't want to hammer a server with SetCapture changes every time a player's inventory changed in some way.

  • Like 1

Share this post


Link to post
Share on other sites

removealleventprivate ["_noncomState", "_wArray"];

_noncomState = player getVariable "var_lk_noncom";

_wArray = weapons player;

if (count _wArray == 0) then
{

    if (_noncomState isEqualto false) then
    
    {
        player setCaptive 1.44; hint "You are a non-Combatant!"; player setVariable ["var_lk_noncom", true];
        
    } else {};
    
} else {

        if (_noncomState isEqualto true) then
        { 
            player setCaptive 0; hint "You are a Combatant!"; player setVariable ["var_lk_noncom", false];
        } else {};

    };


// I believe should work, or

removealleventprivate ["_noncomState", "_wArray"];
_noncomState = player getVariable "var_lk_noncom";
_wArray = weapons player;
if (count _wArray == 0 && _noncomState isEqualto false) then
{
    player setCaptive 1.44; 
    hint "You are a non-Combatant!"; 
    player setVariable ["var_lk_noncom", true];
} else {
        player setCaptive 0; 
        hint "You are a Combatant!"; 
        player setVariable ["var_lk_noncom", false];
    };
    


// Seems neater with the same if statements
 

Share this post


Link to post
Share on other sites
5 hours ago, lkincheloe said:

Suggestions?

If you're not doing anything in the else part of the if statement, just leave it out.

Also don't confuse any of the brackets and use a script editing program with sqf syntax highlighting to avoid those errors in the future.

Can recommend Poseidon which has all the functionality you could ever want.

 

When working with booleans you can easily get rid of if then checks when all you want is a simple state switch from true to false, same for the if condition.

When checking for a variable that contains boolean you can simply use the variable, no need to compare it to bool like this:

//bad practice
_something = true;
if (_something == true) then {
	//stuff
};

//way better
_something = true;
if (_something) then {
	//stuff
};

I can see no point in checking the "var_lk_noncom" variable, since it does exactly the same as a captive check, unless I'm missing something.

_wArray = weapons player;  
_hints = ["You are a Combatant!","You are a non-Combatant!"]; 
_state = (_wArray isEqualTo []);
player setCaptive _state;
hint str (_hints select _state); 
//will set player captive when no weapons are found, also displays appropriate hint

No point in arguing about spamming setCaptive command since, as you stated, this snippet will run from initPlayerLocal.sqf it will only run once.

If you plan on putting this inside an inventory EH like "Take" then you can simply check if the object taken is of a weapon category and then run your captive snippet.

Using engine script commands is always preferred to using remoteExec or other means, especially when a command already is argument local, effect global, like setCaptive.

 

Cheers

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  

×