Page MenuHomeFeedback Tracker

Add IN multiple values check operator
Feedback, NormalPublic

Description

Please provide the following when creating the Ticket:

Game Version number: 1.2.0.66
Modded?: (Yes/No) No
Issue Description:

Please provide IN operator that would allow to check multiple values similar to how it works in Arma 3/SQL/C# new[] {"val1", "val2", "val3"} replacing these

if (damageContext.damageType == EDamageType.COLLISION || damageContext.damageType == EDamageType.FIRE || damageContext.damageType == EDamageType.REGENERATION)
     return;

with more elegant

if (damageContext.damageType in (EDamageType.COLLISION, EDamageType.FIRE, EDamageType.REGENERATION))
     return;

Details

Severity
Feature
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General
Steps To Reproduce

Please include reproduction steps here!!!!

Event Timeline

Socrates created this task.Jun 25 2024, 3:57 PM
Geez changed the task status from New to Feedback.Jun 25 2024, 7:36 PM

that's SQF syntax… in Enfusion we do

if (damageContext.damageType & (EDamageType.COLLISION | EDamageType.FIRE | EDamageType.REGENERATION))
     return;

:-)

otherwise, a bit more bruteforce would be

ref array<EDamageType> m_aForbiddenDamageTypes = { EDamageType.COLLISION, EDamageType.FIRE, EDamageType.REGENERATION };

// ...

if (m_aForbiddenDamageTypes.Contains(damageContext.damageType))
	return;

that's SQF syntax… in Enfusion we do

if (damageContext.damageType & (EDamageType.COLLISION | EDamageType.FIRE | EDamageType.REGENERATION))
     return;

:-)

it works differently - it was unable to move further with non-collision, non-fire and non-regen damage types.
About the array way - well, it would be great if there was an ability to avoid additional allocation here (especially in frequently called functions as damage event handlers).

LouMontana added a comment.EditedJul 2 2024, 10:32 AM

ah, correct - they are not flags (1 2 4 8 16), just enum values (0 1 2 3 4), my bad on this one
doing x in [a, b, c] in SQF also creates and allocates an array (in C# too)

but no, there is no easy shortcut in Enfusion - it may be a bit boilerplate, but it's the most efficient

Yeah, this is why I'm proposing thing from OP. :)
It's an compilable scripting language anyway, so compiler could handle this synthax sugar and unfold it in an ordinary || manner.

In C#, one would use the is, or, and operators with braces which the compiler lowers into comparison checks.
example for C#:

csharp
if (damageContext.damageType is EDamageType.COLLISION or EDamageType.FIRE or EDamageType.REGENERATION)
     return;

Note in the lowering process on the right side, the compiler attempts to use any possible optimisation to skip unnecessary checks. In this case it does a bounds check since two of the enum options were adjacent.
https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA+ABATARgLABQGAzAATakDCpA3oaQ+WRiqQLIAUAlLfY/wBEAhgFshAcxiUIAOwAuMBHNIATURKmyFS0gF5SMmAHdutVeskAVAJ4AHGHtIBRYWKt2YAOkoB5ADJ+AJIAyoE+AHKkAL4A3Hz8DACWAGakHGpumvKKcp4ZGjb2pIkAzs6uBR7e/kGhEaTQ5RYwhV4AYoEASk4NUE2ZrZ7dAOJO4U6dAIKWYeFc8Qn8GADscQT8UYSbBIQUFZLS2Tp064wk/ZVF+e5FNKSScjGkJTCP0VuEhDAyAK4iFzcHCd+OEIk4ADQLXwBEKzSGnBgdbrw/htSYw8LDFGMEZjCbTOELSZsHzDACqwXhUSAA