Jump to content

Script Length Limit


Gunshot08

Recommended Posts

Howdy all!

 

I was working on a very extensive script for a customizable house and apparently I ran out of characters to use. Is this an issue with the in-program CK editor that can be avoided by writing and compiling the script in another editor, or does Skyrim limit the length of a single script to a certain size? Is there any way around this limit if the latter is the case?

 

I can always break the script into several smaller ones but I'd rather have it all in one to save time and design of my in game space.

Please let me know what the deal is and if anyone else has run into this problem.

 

Thanks!

Link to comment
Share on other sites

I don't know of any limits on script size, however as a programmer I very strongly urge you to refactor that script into several smaller ones. It may seem like more of a hassle than simply writing one giant one, but trust me when I say that having functionality broken out into separate, bite-size files makes maintenance and future development a lot easier!

 

It may seem like a good idea right now to keep everything in one centralized location, however when you put it aside and then come back to it later a single 10,000-line script is a royal nightmare, especially when compared with 5 2,000-line scripts or 10 1,000-line scripts. I say this from years of experience -- that 10,000-line script is not a good idea!!

Link to comment
Share on other sites

I actually know that's what I should do, but in this instance I'm not certain how, and I'm not even sure it's necessary. My script is currently only 1039 lines long (33,700 characters), and although it's not finished, there's probably about 150 lines of annotation for personal use while I continue writing the script.

 

If I do need to break up my script, can I execute a script from inside another script? Right now I have a workbench which is the activator, which opens up a menu upon activation. The menu houses multiple sub-menus, the script for which contains code to check for items and remove items when a choice is selected (i.e. 10 iron to make a cow, etc). I have build options for both exterior and interior items, so I can always break the script in half between interior and exterior if need be.

 

Any suggestions?

Link to comment
Share on other sites

Yes, you can call other scripts from your scripts. For example, in my upcoming mod Lichdom, my 11 scripts (so far) frequently make calls to one another, e.g. the script sitting on the player watching for them entering bleedout calls the script on the "status quest" to perform the "lich death" check, which in turn calls the relevant function to transform the player into the correct lich state (which is actually part of that same script, but could easily be moved to another).

 

There's a few ways to do it:

 

FileName.FunctionName()

Probably the most straightforward, doesn't require any imports or anything, and works just like using the Game or Utility scripts.

 

 

Import Filename
; ... snip ...
FunctionName()

Personally I don't like doing this, as I feel it breaks the encapsulation that treating scripts as objects give you, but it works.

 

 

(QuestProperty as ScriptFileName).FunctionName()

I use this frequently, because most of my scripts are attached to quests that I already have properties for anyway. For example the aforementioned bleedout check is done more-or-less like this (recounted from memory, as I don't have the scripts in front of me at work):

 

Event OnEnterBleedout()
    (Lich01 as Lich_StatusScript).LichDeath()
EndEvent

 

If you don't already have lots of functions in your script, identify sections of code that logically could be turned into functions (e.g. that 10-line section that calculates the new value of your variable). Then start moving functions out into other scripts. Keeps your script files nice and tidy, which makes your life a heckuva lot easier when it comes time to track down bugs users are reporting!

 

1,000-line files aren't all that bad, but I dislike it when my scripts get even half that long. YMMV, though, and for the most part (i.e. barring any technical limitations) script length is mostly a matter of personal choice.

Link to comment
Share on other sites

Thank you both very much. I guess I'll get my Notepad++ ready to work with psc and pex, and when I'm done I'll most likely export some code into separate scripts and just call them in the original. (Personally I like to have it all in one place before divvying it up haha).

 

Thanks again!

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...