Skip to main content
Participant
August 1, 2006
Question

Too many functions!!!

  • August 1, 2006
  • 1 reply
  • 390 views
While developing a large FMS application, main.asc has become more than a bit lengthy. The bulk of the file is taken up by the custom client functions that are created anonymously under the onConnectAccept function.

(ex
newClient.myFunction = function(param1, param2) {
//do stuff
}

I tried splitting some of the (hundreds of) functions into seperate files then I used load() under the onConnectAccept function. I think since these functions are created during runtime, the load function is not appropriate (triggered on compile time). Is there some way to split these functions into seperate files?
    This topic has been closed for replies.

    1 reply

    August 2, 2006
    Instead of adding the function to the client object in the onConnectAccept, you could add them to the client prototype.

    Client.prototype.myFunction = function(p1, p2){
    // do stuff
    }

    That way, you can put the client functions in a separate .asc file and load them at the top of your main.asc without problem
    mikeDohAuthor
    Participant
    August 2, 2006
    If I need to reference a newClient property (clientName for example) withing the Client.prototype functions, do I have to refer to the property like so: Client.prototype.clientName. (will this work?)
    August 2, 2006
    Yes... it will work. The client object automatically resolves to the client calling the function (like magic). So, your client function might look like this:

    Client.prototype.returnUsername = function(){
    return this.userName;
    }