1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

What does this question mark do?

Discussion in 'Programming' started by Tamehisa, Aug 31, 2019.

Tags:
  1. Tamehisa

    Tamehisa Member

    Joined:
    Aug 31, 2019
    Posts:
    3
    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
     
  2. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,989
    In this context, it is the ternary operator. You can find more information about it on the Language Features manual page.
     
    Tamehisa likes this.
  3. Tamehisa

    Tamehisa Member

    Joined:
    Aug 31, 2019
    Posts:
    3
    Thanks TsukaYuriko, I understand what this does.
     
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,214
    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.
     
    Tamehisa and TsukaYuriko like this.
  5. Tamehisa

    Tamehisa Member

    Joined:
    Aug 31, 2019
    Posts:
    3
    Thanks Yal. It's nice and clear explanation.
     

Share This Page