Select to view content in your preferred language

What do brackets () in a rule name mean?

661
3
Jump to solution
03-25-2022 01:35 PM
AlexKweya
New Contributor III

I'm yet to grasp what brackets mean in a rule name. Could someone explain the logic? For example, this rule taken from CityEngine Tutorials 7:

 

Wall(walltype)-->
	// dark bricks with dirt
	case walltype == 1 : color(wallColor)
	texture(wall_tex) set(material.dirtmap, dirt_tex)
	projectUV(0) projectUV(2)
	// bright bricks with dirt
	case walltype == 2 : color(wallColor)
	texture(wall2_tex)
	set(material.dirtmap, dirt_tex)
	projectUV(0) projectUV(2)
	// dirt only	
	else : color(wallColor)
	set(material.dirtmap, dirt_tex)
	projectUV(2)

 

What does Wall(walltype) mean? Why is the "walltype" in brackets?

Any benefits for such?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
plfontes
Occasional Contributor

Hi,

You can think that rules work like function do in other programming languages.

The information within brackets are parameters you give to the rule to do something with it. So with this parameter you can carry information from one part of your rule file into a rule that will perform another operation. The name of that parameter (walltype) is just a variable that will inherit the value you pass to the rule.

For example: You can "call" the rule Wall() and at the same time you can specify to what specific wall you want that to do the operation by adding the walltype parameter.

In the case of the Tutorial 7 you mentioned, the parameter will determine the type of brick texture to load. If you call the rule as Wall(1),  the parameter 1 will be pass into to the rule as the walltype variable. The "Wall(walltype) -->" than rule can be actually read as Wall(walltype = 1) and so the following case walltype == 1 will be run.

If you google search for function parameters in other languages, the logic is the same.

Hope this helps clarify the syntax.

View solution in original post

3 Replies
plfontes
Occasional Contributor

Hi,

You can think that rules work like function do in other programming languages.

The information within brackets are parameters you give to the rule to do something with it. So with this parameter you can carry information from one part of your rule file into a rule that will perform another operation. The name of that parameter (walltype) is just a variable that will inherit the value you pass to the rule.

For example: You can "call" the rule Wall() and at the same time you can specify to what specific wall you want that to do the operation by adding the walltype parameter.

In the case of the Tutorial 7 you mentioned, the parameter will determine the type of brick texture to load. If you call the rule as Wall(1),  the parameter 1 will be pass into to the rule as the walltype variable. The "Wall(walltype) -->" than rule can be actually read as Wall(walltype = 1) and so the following case walltype == 1 will be run.

If you google search for function parameters in other languages, the logic is the same.

Hope this helps clarify the syntax.

AlexKweya
New Contributor III

It does help. Thank you!

And it became clearer in Tutorial 9 too, just in case anyone's wondering.

0 Kudos
JonasObertuefer
Esri Contributor

Hi,

In addition to the tutorials i would recommend to check out the cga essentials in the help, there you will find a section where this logic is explained too: Rule with parameters 

0 Kudos