Difference in a Function Definition

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Difference in a Function Definition

linkreincarnate

So I created a function that creates a hollow cube by differencing two cubes.  For some reason though it wont compile.  I keep getting a syntax error on the first bracket  after the difference function is called.  If I comment out the difference function it works fine.  What am I missing here?  You can use the difference function in a  user defined function right? If not how can I create a function to create an object?


function CreateNonArchedBody(boxLength,
                             boxWidth,
                             boxHeight,
                             boxDepth,
                             boxWallThickness,
                             boxHingeDiameter,
                             boxHingePinDiameter,  
                             boxHingeXOffset,
                             boxHingeYOffset,
                             boxHingeTolerance,
                             pinTolerance,
                             controlArmPinDiameter,                        
                             controlArmHoleXOffset,                        
                             controlArmHoleYOffset) =
   
        difference() {
            cube([boxLength,boxWidth,boxHeight],
                 center = true
                );
            translate([0,0,((boxHeight-boxDepth)/2)])
                cube([boxLength - boxWallThickness,
                      boxWidth - boxWallThickness,
                      boxDepth],
                      center = true
                );
        }
Reply | Threaded
Open this post in threaded view
|

Re: Difference in a Function Definition

kitwallace
This should be a module rather than a function. Just change the keyword and drop the "="
Reply | Threaded
Open this post in threaded view
|

Re: Difference in a Function Definition

linkreincarnate
Oh Thanks that works.  What is the difference between the two?  What determines when you use a function vs a module?
Reply | Threaded
Open this post in threaded view
|

Re: Difference in a Function Definition

Whosawhatsis
Functions in Openscad are functions in the mathematical sense. They return the solution to an equation rather than creating geometry.

On Friday, April 3, 2015 at 00:07, linkreincarnate wrote:

Oh Thanks that works. What is the difference between the two? What
determines when you use a function vs a module?



--
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Difference in a Function Definition

runsun
This post was updated on .
In reply to this post by linkreincarnate
I learned it this way:

a = x;   // x is a parameter, previously defined as x=something;
b = x( ); // x is a function when it's on the right side of =
x( ); // x is a module

So in OpenScad you can have same name x representing 3 different things.
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets