ID:143084
 
Code:
for(var/v in l)
world << "Hit check [v]"
switch(v)
if("Fly")
msg(a, b, " - [a.name] could not be hit")
return
if("Dig_Attack")
msg(a, b, " - [a.name] could not be hit")
return
if("Bounce_Attack")
msg(a, b, " - [a.name] could not be hit")
return


for(var/v in l)
world << "Hit check [v]"
switch(v)
if("Fly" || "Dig_Attack" || "Bounce_Attack")
msg(a, b, " - [a.name] could not be hit")
return

Problem description:
The first example of code displays "Bounce_Attack" to the world, and stops the person from being hit.
The 2nd example of code show "Bounce_Attack" but does not prevent the person from being hit.

Why is if(value || value || value) not a valid way of checking if the switch value is the same as 1 or more other values?

Thanks
The compiler evaluates "Fly" || "dig_attack" || "bounce_attack" and uses that as the thing to check against.

"fly" is true, "dig_attack" is true, and "bounce_attack" is true, so you've got the equivalent of:

switch(v)
if(1)...


I believe you're looking for commas, but I'm not certain - look up the switch statement in the DM reference. It should have some mention of them.

for(var/v in l)
world << "Hit check [v]"
switch(v)
if("Fly", "Dig_Attack", "Bounce_Attack")
msg(a, b, " - [a.name] could not be hit")
return
In response to Jp
Yeah, exactly what I needed, after so many years and never needed that "," untill now, thanks!