lundi 26 mars 2018

lua checking multiple values for equailty

I like to make games in Roblox and I code in lua. Well coding games I find myself asking if a value equals another value a lot and it can make really long lines of code and can be quite repetitive.

For example:

if x.ClassName == 'Shirt' or
x.ClassName == 'Accessory' or
x.ClassName == 'Pants' or
x.ClassName == 'CharacterMesh' then
-- do thing
end

doing that not only can be very messy but is also just asking the same thing over and over again slightly modified.
I was wondering if there was a way in lua to ask if a value equals multiple diferant separate values

For example:

if x.ClassName == ( 'Shirt' or 'Accessory' or 'Pants' or 'CharacterMesh' ) then
-- do thing
end

Aucun commentaire:

Enregistrer un commentaire