Jump to content
Kmeld

Could you please explain what this means? (C# ?)

4 posts in this topic Last Reply

Highlighted Posts

Posted:
Last Online:  
 

Hi,

I tried to read this but I must say I am still unable to fully understand what exactly and how it does.

Could someone please explain in descriptive way how this variable definition works?

float num = (distanceMultiplier == 0f) ? 0f : (0.01f / distanceMultiplier);

I know it defines a float variable num and it is somehow dependent on the value of distanceMulitiplier abut I am (so far) not able to resolve this definition.

 

Also if anyone can explain what "distanceMultiplier" is used for in Cities Skylines code this would make it more easy for me.

Cris.

Share this post


Link to post
Share on other sites
Posted:
Last Online:  
 

This is a conditional expression

written another way

     if the distance multiplier = 0  then

       make num=0

     else

       make   num = 0.01/DistanceMultiplier

      end if

this is done to prevent a divide by zero exception on DistanceMultiplier which should be non-zero to mean anything. I presume distance multiplier is just something used to scale some distance for rendering something 

Share this post


Link to post
Share on other sites
  • Original Poster
  • Posted:
    Last Online:  
     

    Thanks,

    what does " ?" stands for?

    is it something like "reverse notation" of "if"

    and " : " stands for "else".

     

     

     

    Share this post


    Link to post
    Share on other sites
    Posted:
    Last Online:  
     

    yes its just a shortcut way to express a conditional assignment as a one liner 

    ? is more or less if this is true      and the : is more or less else

     A = (B==0) ? C : D;

    is  if B=0 is true then A=C else A=D

    Share this post


    Link to post
    Share on other sites

    Sign In or register to comment...

    To comment in reply, you must be a community member

    Sign In  

    Already have an account? Sign in here.

    Sign In Now

    Create an Account  

    Sign up to join our friendly community. It's easy!  

    Register a New Account


    ×

    Thank You for the Continued Support!

    Simtropolis depends on donations to fund site maintenance costs.
    Without your support, we just would not be in our 24th year online!  You really help make this a great community. *:thumb:

    But we still need your support to stay online. If you're able to, please consider a donation to help us stay up and running. This helps sustain a platform where we can share our community creations for years to come.

    Make a Donation, Get a Gift!

    Expand your city with the best from the Simtropolis Exchange.
    Make a Donation and get one or all three discs today!

    STEX Collections

    By way of a "Thank You" gift, we'd like to send you our STEX Collector's DVD. It's some of the best buildings, lots, maps and mods collected for you over the years. Check out the STEX Collections for more info.

    Each donation helps keep Simtropolis online, open and free!

    Thank you for reading and enjoy the site!

    More About STEX Collections