Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[Sugarcube] Split StoryInit across multiple files

As I build up my inventory system and other "reference" data my StoryInit file is getting unwieldly large, is there a way to have it source from multiple files so I can split things up for better organization (and it'd be really nice if it also helped with narrowing down errors, but I accept that might be a pipe dream).

There's also the possibility I am doing things very wrong and there's some other preferred way to include data that will be used throughout the story other than the StoryInit file.

On a similar note - can I split up the Javascript file? It, too is beginning to get excessively large.

Comments

  • edited March 2017
    This would be really nice to know. From what I understood there's supposed to be a built in "setup" object in SugarCube. This should only store constants and things that don't change throughout the game.

    Other than that, what I do is: I Store only the relevant variables in StoryInit that are displayed in my first passage (submenus, UI bars and the passage) and then I start to move the variables (primitives as well as objects) to different passages.

    Say I have a HouseEntrance passage: I setup the variables here that have something to do with the house. The name, the containers inside the house, rewards, items, characters, etc. Now, these things are only relevant if the the player has reached the house otherwise this passage never triggers and the variables will not be set.

    If you have and intro to your story you could split up your variables nicely.

    Other things I like to do to organize my story better, is to have multiple passages that only contain widgets. For instance I have a widget for InventoryWidgets, QuestWidgets, NPCWidgets, CombatWidgets, etc.

    About splitting JS, no idea. I tend to copy and paste the whole thing into Notepad++ and do the editing there. Especially for CSS, which has horrible syntax highlighting for the Dark Theme, that dark purple is nasty and hard to see.
  • @psy
    When asking a question you also need to also state the version of Story Format you are using, as answers can be different for each one.

    psy wrote: »
    ...my StoryInit file ... multiple files ...
    If when you say file you actually mean passage then you can use the <<display>> macro (replaced by the <<include>> macro in v2.15.0) to insert the contents of child initialisation passages into a parent StoryInit special passage.

    The following three passage example shows one way to spread initialisation across multiple passages, the example is written in Twee Notation.
    :: Start
    Var 1: $var1
    Var 2: $var2
    
    :: StoryInit
    <<set $var1 to "value1">>
    <<display "InventoryInit">>
    
    :: InventoryInit
    <<set $var2 to "value2">>
    

    re: @Disane's comment about spreading the initialisation of the story variables across the passages of your story so that it occurs closer to were the variables are first used.

    Although you can do that I personally would not recommend doing so because it results in you needing to remember where you initialise a particular variable if you need to change its default value at a later point or can't remember of a variable name is spelt, where as if all variables are initialised in StoryInit there is only one place to look. (or related locations if using the technique shown in the example)
  • edited March 2017
    @greyelf
    if you need to change its default value at a later point or can't remember of a variable name is spelt

    Well, it would be nice to have type assitants like a suggestion list (an Inteli-sense kind of thing implemented in the Twine editor, also syntax highlight for the Story script would be nice too). Maybe some time down the line :)

    Well, I tend to copy every script that describes a passage into one text file and leave comments at the begining and end so I can see where the passage starts and ends. This way Notepad++ has "full code coverage" over the whole Story, even JS and CSS and this way it can suggest the correctly spelled variable names to me.

    I guess this could be nicely combined with the things you said above. I really appreciate the suggestion. It seems to be a better solution than what I described. Then again, I'm new here, but I learn fast and initiating a conversation about these things is always a good start.

    Does the example you presented work in Sugarcube 2? (SC 2.14 and 2.15?)
    I got a bit confused about the <<display>> and <<include>> macros... you mentioned there. Are they necessary? Eventhough you refer to :: Start and :: InventoryInit when you set your variables?

    I'll definitely try this out!
  • Disane wrote: »
    ...Inteli-sense ... syntax highlight...
    In theory the CodeMirror text editing widget used by the Passage Editor has support for both of these features, but the developer of each Story Format (major version) needs to supply the code to actually implement them for that story format. Currently only Harlowe (1.x and 2.x) has implemented syntax highlighting.
    Disane wrote: »
    Well, I tend to copy every script that describes a passage into one text file and leave comments at the begining and end so I can see where the passage starts and ends.
    What you doing is basically re-inventing Twee Notation, which I used in my previous three passage example.
    Disane wrote: »
    Does the example you presented work in Sugarcube 2? (SC 2.14 and 2.15?)
    Yes. (although you could of just tested that yourself *smile*)
    Disane wrote: »
    I got a bit confused about the <<display>> and <<include>> macros... you mentioned there. Are they necessary? Eventhough you refer to :: Start and :: InventoryInit when you set your variables?
    Based on this statement/question I am guessing you missed the part where I said the previous example contained three passages and that I was using Twee Notation (which I supplied a link to for those unaware what that is).
    eg. The three passages in the example are named Start, StoryInit, and InventoryInit; and the lines directly below the decoration of each passage is the content of that passage.
  • Oh, I see. Nice, but how do you import the .txt or .tw file into Twine? I don't remember Twine having an option for that or maybe I just missed that one.
  • edited March 2017
    Disane wrote: »
    I don't remember Twine having an option for that...
    Twine 1.x supports either:
    a. Importing the Twee source file and creating a project from it
    b. Including the content of a Twee source file in an existing Story Project via the StoryIncludes special passage.

    You can also build/compile Twine Story HTML files using command line tools as explained in the Using external IDE? thread.
  • greyelf wrote: »
    @psy
    :: Start
    Var 1: $var1
    Var 2: $var2
    
    :: StoryInit
    <<set $var1 to "value1">>
    <<display "InventoryInit">>
    
    :: InventoryInit
    <<set $var2 to "value2">>
    


    That works great!, Thanks!
Sign In or Register to comment.