PDA

View Full Version : Resolved Formatting a conditional statement with multiple or's


ryantakers
11-14-2009, 09:26 AM
I am writing a script for a photoshop project and i have hit (another) stumbling block.
It seems so simple, yet i cannot figure out what is wrong. Here is the code in question:
if(A == 1||3||5||7||9||11||13||15||17||19||21||23||25||27||29)
{
app.activeDocument.artLayers.getByName ("A1").visible=true;
}
else
{
app.activeDocument.artLayers.getByName ("A1").visible=false;
}
if(A == 2||3||6||7||10||11||14||15||18||19||22||23||26||27||30)
{
app.activeDocument.artLayers.getByName ("A2").visible=true;
}
else
{
app.activeDocument.artLayers.getByName ("A2").visible=false;
}

The problem is that it makes the layers visible regardless of whether the condition is true or not. The problem lays in the condition, not the response, i have narrowed this down.
It shows dots, in binary based on the number input.
Any help would be immensely appreciated.
Regards,
Ryan

abduraooft
11-14-2009, 11:36 AM
if(A == 1||3||5||7||9||11||13||15||17||19||21||23||25||27||29) You need to use the comparison operator for each item like
if(A == 1|| A== 3|| A==5 ||...) or better to make an array and use the indexOf() function. See https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/indexOf (including compatibility issues and work arounds)

oesxyl
11-14-2009, 01:28 PM
this:
if(A == 1||3||5||7||9||11||13||15||17||19||21||23||25||27||29)
is same as:
if(A > 0 && A < 30 && A % 2 == 1)

and this:
if(A == 2||3||6||7||10||11||14||15||18||19||22||23||26||27||30)
is same as:
if(A > 1 && A <= 30 && (A % 4 == 2 || A % 4 == 3))

best regards

ryantakers
11-14-2009, 07:41 PM
Thankyou both very much for your replies.