What does this question mark do?

Tamehisa

Member
I'm trying to use Lighting System 2d by Jodo and I can't understand 2nd term of lerp function in one of the line in Demo project.
Code:
light[| eLight.Direction] = lerp(light[| eLight.Direction], dir ? Min_Angle : Max_Angle, 0.01);
This line is in the Step event of obj_rotating_spot_light.
I set Min_Angle = -20, Max_Angle = 20 and show_debug_message(string(dir ? Min_Angle : Max_Angle)) shows 350 190 and 280 250.
I think this change caused by the alarm function in obj_rotating_spot_light. But still don't get what "dir ? Min_Angle : Max_Angle" does.
This might be basic question, but I couldn't find the answer.

I put the link to demo project below.
https://github.com/borup3/Lighting-System-2D-Demos
 

Yal

šŸ§ *penguin noises*
GMC Elder
The ternary operator is a way to condense an "if-else" statement into a single line. The code checks if "dir" is true and if so uses the min angle, otherwise the max angle. I'd imagine it's used when you're outside of the angles the arc covers, and the code checks on WHICH SIDE you're outside and picks the appropriate angle.
 
Top