|
Is there an ideal, better way to organise scripts? Is it recommended to create many name spaces, or not really? I'm wondering because the way I'm scripting seems very untidy. I hav to search within each script for a while to find certain sections of code. I have lessened a lot of code by writing dynamic methods with parameters so they can be recycled over and over. But I really want any tips anyone has on keeping scripts nicely organised. Is it better to attach individual scripts to many objects, or better to save them as variables in one script? Sorry Im full of questions like this. I just want to know an ideal and efficient way of creating scripts >.< Thanks!
(comments are locked)
|
|
To add to @whydoidoit answer:
Example for Regions can be used every where in the script. They are completely ignored by the compiler but in good editors (I use only Visual Studio but MonoDevelop should support this as well) you can collapse the whole region and it just displays the text behind the region statement. Also keep in mind that you can also collapse any function or class body. Regions can also be used inside a function to seperate parts of code. When using regions, don't overuse them, this will make a search even more complicated. Use exact and descriptive region names. If you search for a piece of code and you don't know in which region you have to look, the names are bad choosen. Also you should check the color highlighting of regions / preprocessor tags. Use a very signalling color (I use plain cyan) so a collapsed region doesn't get lost between the lines. Just in case you can't find where you can collapse a region / function / class, there is a "-" sign infront of the code line. When you collapse a section it turns into a "+" sign A final note: endregion tags can also have additional text behind it. It isn't used somewhere, but for very long regions (or nested regions) it helps to have the same text on both the region and the endregion tag. Thanks a lot for all that! I have been using regions in monodevelop and they are very nice to use. And organising functions isn't a problem. But one thing I've been wondering about is if it is possible and practical to use multiple update functions in one class For example I have a virtual pet AI class in which it controls the pets actions through initiating coroutines based upon the pet's mood and status. When the script Starts, it initiates a void method which tells the script to start a grouped action base upon two enumerations(MoodState1 and moodState2). If the pet is happy and curious then it will start a coroutine called explore. Within that coroutine it activates other coroutines which make up individual actions such as walk in a direction and inspect certain areas. However for the pet to walk, all movement needs to be under the update function which leaves me with all my script being tidy except for a very long update function which I have split into regions, but still can be a hassle.
May 29 '12 at 12:39 AM
Alismuffin
Just call functions from your update function if it helps keep stuff organised. I used a state machine I wrote that actually calls different Update routines based on the current state - I find this very practical - easy to keep all of the state based functions in one region too.
May 29 '12 at 12:45 AM
whydoidoit
(comments are locked)
|
|
Ok, first of all if you are using MonoDevelop it has a search for symbol keyboard shortcut, CMD + . on Mac that lets you start to type a class name, a variable name, anything really and then it auto completes, fantastic way of navigating your solution if you can remember any part of the thing you want to go to. Go to definition when the cursor is over something and return from that with (Mac) CMD+D and CMD+SHIFT+D Its down to style, but I use this method:
And I really miss Extract Class to Own File refactoring from Visual Studio, hopefully it will turn up soon :)
May 28 '12 at 09:25 AM
whydoidoit
Thanks for your tips! Very useful :)
May 28 '12 at 09:34 AM
Alismuffin
Is there a disadvantage to having a great deal of scripts? I'm recreating my game in a cleaner mode and I'm not sure whether I should do different scripts for each UI screen or not Eg: SplashScreenUI.Cs ModeSelect.Cs Options.Cs Etc OR UI.Cs In my original script I used enumerations to cycle through menus
May 28 '12 at 09:45 AM
Alismuffin
I cannot really see a disadvantage. Maybe compile time is longer, but that's made up for by the improvement in development time.
May 28 '12 at 10:59 AM
whydoidoit
Yes, the compiletime can be a little bit longer, but almost neglectable. If you worry about compiling time it's by far more effective to use only one language and don't spread too much into the different compiling groups. If you have a lot editor scripts that aren't in development (so they are finished) you can compile them manually into an assembly, but keep in mind you can't reference other scripts in this case. Btw. All your scripts get compiled into one assembly during compilation (one assembly per compiling group), so seperate scripts doesn't care at runtime since they don't exists ;)
May 28 '12 at 11:26 AM
Bunny83
(comments are locked)
|
