Background:
--------------
I have a 'command line' parser script that is nothing but global functions. I wrote it so it is entirely reusable and I use it for all my voice activated objects. I want to place this script in my object and call the functions in this script from another script in the same object.
BottomLine:
--------------
Allow cross script function calls within the same object. But only if the function is implicity declared as being in the object scope, rather than the script scope.
This is for the purpose of increasing script reuse and encouraging reusable object (well script) design.
Implementation Details:
---------------------------
Put a scope modifier on functions in a script. The lack of a modifier indicates 'private'. This function is only callable within the scope of this script.
Adding 'public' before the function, e.g. 'public vector VectorLibDoSomething(vector vVectorIn)' would make it available to all scripts within this object.
Example Case:
-----------------
I have a set of functions that I use in all my 'voice activated' objects.
These functions parse a 'message' coming in from the Listen event, and return a list broken down like this:
'object', 'command', 'arg1, 'arg2' . . .
An example message coming in looks like this:
'SlidingDoor SetAutoClose 10'
The program flow using these functions goes like this:
--------
Listen([listen event args go here])
{
//if owner . . .
//parse the incoming message
lList = VoiceLibParseMessage(message);
//if valid command for this object
if ( VoiceLibIsValidCommand(lList, glObjectCommands)
//perform this action
ObjectCommandsExecute(lList);
}
Currently, I have to copy and paste the functions into every script I need them in. Why can I not declare them as public, and put the script into the object?
This would make it more like a function library.
Inherent Problems With This Proposal:
--------------------------------------------
1. People set globals in the 'public' function, then call it from 3 different scripts in the object.
This is so obviously bad design practice I can't fathom anyone actually doing it, but it does open this up.
My .02