Values in OpenSCAD

OpenSCAD has a different paradigm compared to traditional programming languages, as it’s primarily used for creating 3D models. However, we can demonstrate similar concepts using OpenSCAD’s scripting capabilities.

// OpenSCAD doesn't have a built-in print function, so we'll use echo() for output
// Strings can be concatenated with the str() function
echo(str("open", "scad"));

// Integers and floats
echo("1+1 =", 1+1);
echo("7.0/3.0 =", 7.0/3.0);

// Booleans and logical operators
echo(true && false);
echo(true || false);
echo(!true);

// In OpenSCAD, we typically use these values to create 3D objects
// Here's a simple example using some of these values
cube_size = 1+1;
cylinder_height = 7.0/3.0;
show_sphere = true && false;

cube(size = cube_size);
translate([3, 0, 0]) cylinder(h = cylinder_height, r = 1);
if (show_sphere) {
    translate([6, 0, 0]) sphere(r = 1);
}

OpenSCAD has various value types including strings, integers, floats, and booleans. Here are a few basic examples:

  1. Strings: OpenSCAD doesn’t have a + operator for strings. Instead, we use the str() function to concatenate strings.

  2. Integers and floats: These work similarly to other languages. OpenSCAD supports basic arithmetic operations.

  3. Booleans: OpenSCAD supports boolean values and logical operators as you’d expect.

In OpenSCAD, these values are typically used to define parameters for 3D objects. The echo() function is used to print values to the console, which is useful for debugging.

To run this OpenSCAD script:

  1. Save the code in a file with a .scad extension (e.g., values.scad).
  2. Open the file in OpenSCAD.
  3. The console output will show the echo() statements.
  4. The 3D viewer will display a cube and a cylinder (the sphere won’t be shown because show_sphere is false).

Note that OpenSCAD is primarily a 3D modeling scripting language, so its usage and output differ significantly from general-purpose programming languages.