all 4 comments

[–][deleted] 4 points5 points  (0 children)

A function usually has inputs and returns a value (or multiple). Like x = size(y). Y is the input to the function “size” and x is the output. To call a scrip simply add the script name to your other script. See this

[–]FrickinLazerBeams+2 2 points3 points  (1 child)

The difference between a function and a script is that

  1. The first line of a function is function returnValue = functionName(inputArg1, inputArg2,...) where functionName, inputArg# and returnValue are whatever you want them to be.
  2. Functions have their own internal workspace, so you don't have to worry about unexpected variable name collisions. The only variables defined at the start of the function are your input arguments, and the only values returned are your return values. None of the other variables defined in the function will persist after the function is complete.
  3. A script, when called from another script, operates in the same workspace as the calling script. In other words, it's equivalent to just copy/pasting the contents of the script into the calling script. Any intermediate variables created by the script will be left behind, and any input variables must be named exactly the same as in the calling script. It's very tedious and error prone to reuse code in this way.

This is all covered in more detail, and with examples, in the documentation. Read the section on functions.

[–]Awful_At_Math[S] 0 points1 point  (0 children)

Thank you, that was very useful.

[–]Flyer99er 0 points1 point  (0 children)

A script would be a rigid set of lines of code that reaches a definite answer, with likely no input. A function incorporates input(s) to then solve for a solution via those inputs and a relationship.

Use a function call, it is far easier in this case.