Jump to content
kuplion

[HELP NEEDED] addAction condition with an OR statement for multiple items.

Recommended Posts

I'm trying to add an addAction to all players that have a chemlight. I can get the condition to work when specifying only a single chemlight, but when specifying more than one, the condition doesn't work.

 
This doesn't work:
player addAction ["Attach Chemlight","Custom\Chemlights\attachChemlight.sqf",true,0,false,true,""," 'Chemlight_green' || 'Chemlight_red' || 'Chemlight_blue' || 'Chemlight_yellow' in (magazines player)"];
This does work (for the green chemlight):
player addAction ["Attach Chemlight","Custom\Chemlights\attachChemlight.sqf",true,0,false,true,""," 'Chemlight_green' in (magazines player)"];
I've tried both || and OR but neither work. I also can't seem to get && to work (was just testing it to see if I could make it reliant on more than one chemlight before it would show the action).

Share this post


Link to post
Share on other sites

This doesn't work:

player addAction [\\"Attach Chemlight\\",\\"Custom\Chemlights\attachChemlight.sqf\\",true,0,false,true,\\"\\",\\" 'Chemlight_green' || 'Chemlight_red' || 'Chemlight_blue' || 'Chemlight_yellow' in (magazines player)\\"];
Sadly that's not how the || or && operators work. The condition field is expecting a return value of either true or false. The statements either side of the || need to evaluate to a boolean (true or false).

So youd need to make it check for each type of Chemlight separately like this:

"('Chemlight_green' in (magazines player))|| ('Chemlight_red' in (magazines player))|| ('Chemlight_blue' in (magazines player)) || ('Chemlight_yellow' in (magazines player))"
That way each statement either side of the operator || is returning either a true or false value.
  • Like 1

Share this post


Link to post
Share on other sites

Cleaner version would be:

"{_x in (magazines player)} count ['classname', 'classname',...] > 0"
  • Like 3

Share this post


Link to post
Share on other sites

This doesn't work:

player addAction [\\"Attach Chemlight\\",\\"Custom\Chemlights\attachChemlight.sqf\\",true,0,false,true,\\"\\",\\" 'Chemlight_green' || 'Chemlight_red' || 'Chemlight_blue' || 'Chemlight_yellow' in (magazines player)\\"];
Sadly that's not how the || or && operators work. The condition field is expecting a return value of either true or false. The statements either side of the || need to evaluate to a boolean (true or false).

So youd need to make it check for each type of Chemlight separately like this:

"('Chemlight_green' in (magazines player))|| ('Chemlight_red' in (magazines player))|| ('Chemlight_blue' in (magazines player)) || ('Chemlight_yellow' in (magazines player))"
That way each statement either side of the operator || is returning either a true or false value.

 

 

Ah!! Thank you, I was working to the logic that as long as one of them was present, it would return true. Thank you for your help. :)

 

Cleaner version would be:

 

"{_x in (magazines player)} count ['classname', 'classname',...] > 0"

 

Thank you for your help. :) Would this method be more efficient than the method above by dangerousdiz_ , or will it have little to no effect?

Share this post


Link to post
Share on other sites

JShock's version is how I would have done it. My suggestion was to highlight the issue with how you were using the operator ||.

While they both do the same operation, the variant with {_x }count is cleaner (performing a single command over and over is better done in a loop than writing out each iteration) and easier to adapt. As to speed Im not sure whether it would make much difference.

  • Like 1

Share this post


Link to post
Share on other sites

JShock's version is how I would have done it. My suggestion was to highlight the issue with how you were using the operator ||.

While they both do the same operation, the variant with {_x }count is cleaner (performing a single command over and over is better done in a loop than writing out each iteration) and easier to adapt. As to speed Im not sure whether it would make much difference.

 

Brilliant, thank you for the feedback and for the mini lesson in how conditions work. It's all working now! :D

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

×