[Closed] problem with "if" and "else"
hey,
I’m writing a script that send few renders to backburner from differnt cameras.
In some cameras i wrote a condition that one or more objects are not visible to camera.
The problem begins when i need the same object to be not visible to camera for more then one camera.
What happens then is that only one of the cameras is renders with that object as not visible to camera, and in the other camera the object still renders visible to camera.
The specific code lines are:
if (cams[i].node.name== “Camera04”) then
($Wall_01.primaryVisibility = off)
else
($Wall_01.primaryVisibility = on)if (cams[i].node.name== “Camera05”) then
( $Wall_01.primaryVisibility = off )
else
( $Wall_01.primaryVisibility = on )
Why is it happens?
thanks.
This is because both conditions are always executed, and the LAST one to be executed prevails.
So if your camera is Camera04, it will set the property to OFF, but since the camera is NOT Camera05, the following expression will turn it back ON.
You should change the logic to
- Set the camera visibility of the wall to true
- Check the current camera name and if it matches the condition, set the visibility to false, without an else.
This way, any name that matches a condition will override the previous ON to OFF, but never change back to ON if the camera does not match within the IF’s ELSE expression.
You can write it as
$Wall_01.primaryVisibility = on
if (cams[i].name== "Camera04") or (cams[i].name== "Camera05") do $Wall_01.primaryVisibility = off
or
$Wall_01.primaryVisibility = on
if findItem #("Camera04","Camera05") cams[i].name > 0 do $Wall_01.primaryVisibility = off