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 thank
Solved! Go to Solution.
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!
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.
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!
very thank dear Elliot
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.
very thansk dear CherILau 👍