//global scope, this variable will have a value of 20 everywhere global = 1; example(); module example(parm = global) { //Module scope, this variable will be true everywhere mod_scope = false; translate([20,0,0]) if(mod_scope) { //The control blocks can bring a new variable into //scope. if_scope will have a value of 20 in the cube //parameter if_scope = 1; cube(if_scope); if_scope = 20; }else { //This is a new set of curly brackets and a new scope //The following line is an error when mod_scope = false sphere(if_scope); } for(i=[1:3]) { //This is the for loop scope. There are actually three //new scopes here, one for each pass of the loop. //In every pass for_scope will have a value of i * 30 for_scope = i * 2; translate([3*for_scope,0,0]) cylinder(r=for_scope, h = i*10); for_scope = i * 30; } translate([0,0,50]) { //Here is an example of creating a new scope on the fly. //As in every other case the cylinder "sees" a value //of 15. //NOTE: if there were more than one solid in this scope //they would be unioned with an implied union new_scope = 2; cylinder(r=10, h = new_scope); new_scope = 15; } intersection() { //A new scope opening due to a combine. //The variable cube_side has the value of 10 everywhere //That includes the definition of sphere_r cube_side = 2; sphere_r = 0.7 * cube_side; cube([cube_side,cube_side,cube_side], center=true); sphere(r=sphere_r); cube_side = 10; } mod_scope = true; }