Select to view content in your preferred language

What is the reason for using underline in CGA rule?

1796
4
Jump to solution
07-24-2021 02:19 AM
Hadi_yousefi
Emerging Contributor

Hello friends - what is the reason for including underline for some expressions in CGA rule?n the image below, I marked it with a red box. very thankunderline.png

 

0 Kudos
2 Solutions

Accepted Solutions
ElliotHartley
Frequent Contributor

Hi!  The underscore here is sort of an informal way many CityEngine professionals indicate that this is a CGA function rather than an attribute.  Functions return a value and can be used multiple times, I for example use them often for metric calculations or to look up data.  You can read more here.

You'll find that CGA can be formatted in a variety of ways (unlike say python).  What some of us CityEngine users have started to do is make it easier to understand code by adopting informal syntax.  You'll see most code from Esri starts with what files it requires (rule or assets), then attribution, then the rules.  It's good practice to format it like this, but it isn't necessary! 

View solution in original post

CherylLau
Esri Regular Contributor

The underscore is not necessary for cga to work.  The function could also be named getInitialRightLanes, and the code would work exactly the same.

Sometimes programmers will adopt a convention which may be something that many people follow or something more unique that only that one programmer follows.  It depends on the author.

Often, I would say, in ESRI.lib, prefixing a name with an underscore _ means that the function or variable is designed to be private, or in other words, created only for internal use within that one cga file.  But, this doesn't mean that it can't be accessed by a file that imports; access is not restricted in cga.  This is because cga doesn't have the concept of private functions or variables.  In the end, in cga, it's just a name, just like any other name, whether it starts with an underscore or not.

View solution in original post

0 Kudos
4 Replies
ElliotHartley
Frequent Contributor

Hi!  The underscore here is sort of an informal way many CityEngine professionals indicate that this is a CGA function rather than an attribute.  Functions return a value and can be used multiple times, I for example use them often for metric calculations or to look up data.  You can read more here.

You'll find that CGA can be formatted in a variety of ways (unlike say python).  What some of us CityEngine users have started to do is make it easier to understand code by adopting informal syntax.  You'll see most code from Esri starts with what files it requires (rule or assets), then attribution, then the rules.  It's good practice to format it like this, but it isn't necessary! 

Hadi_yousefi
Emerging Contributor

very thank  dear Elliot 

 

0 Kudos
CherylLau
Esri Regular Contributor

The underscore is not necessary for cga to work.  The function could also be named getInitialRightLanes, and the code would work exactly the same.

Sometimes programmers will adopt a convention which may be something that many people follow or something more unique that only that one programmer follows.  It depends on the author.

Often, I would say, in ESRI.lib, prefixing a name with an underscore _ means that the function or variable is designed to be private, or in other words, created only for internal use within that one cga file.  But, this doesn't mean that it can't be accessed by a file that imports; access is not restricted in cga.  This is because cga doesn't have the concept of private functions or variables.  In the end, in cga, it's just a name, just like any other name, whether it starts with an underscore or not.

0 Kudos
Hadi_yousefi
Emerging Contributor

very thansk dear CherILau 👍

0 Kudos