Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I am doing a server side game with socketIO and I plan on having to games on the same script using the room function socketIO has. However is there a way for me to include each room in its own script. At the moment I am doing gameType_Function etc... Just so it doesn't get confusing. So I was wondering if I could have them in there own script and include them kind of like phps include() feature.

If there is, would I need to define socketio in them or would that happen on the include?

share|improve this question
    
I can't really tell for sure what you're asking. You can include one module inside another in node.js using require(). – jfriend00 Jul 7 at 21:30
    
So, I have 2 game modes I want on my site. Right now I have the functions and all the code for them in the same script and i'm using socketIOs room functions to send the data to the right users. However its so messy so I was wondering if I could put game mode 1s code in another script and game mode 2s in another script then include them in the socketio script? – jdne Jul 8 at 16:03
    
I'm sure you can organize your code however you want, but we can't really help here if you aren't going to show the relevant code. So, Yes you can split your scripts up into modules. How to do that depends entirely upon your code and if you want us to help you do that, then you have to show us your code. The only generic advice we can offer is to read all about modules in node.js, how they work, how you write them and how you use them. We aren't going to offer a generic tutorial on modules here. That's been written hundreds of times already on the web. – jfriend00 Jul 8 at 16:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.