Starfinder Playlist
  1. #1
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075

    “Breaking up” lua files?

    I have, for example. A char_main.lua associated with the record_main.xml or whatever. It has handlers for everything all in one.

    I would prefer some times to separate conceptually maybe all the saving throw handlers from maybe where it calculates/updates encumbrance or whatever just randomly picking examples.

    What is the recommended practice for any who have done something like that? Do you have a char_main.lua which calls other base.xml names scripts like ManagerSaves.lua etc like using proxy concept? Ex in CharmainnLevelUpdateSaves(arg) it calls inside that method ManagerSaves.onLevelUpdateSaves(arg) ?

    I don’t care about actually separating via encapsulation as much as seeing “less” at a time and more focused (helps me think) so if I could have, I’d be happy to just have in the top of the managerchar.lua file some “include ManagerSaves.lua” constrict? But I seem to recall no includes. But I’ve been away from my pet project for 3.5 months and I have actual memory problems in RL

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,362
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  3. #3
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Yeah, this was my memory: Window/Control/Global - but thanks cos the link is good to review.

    There is at the top of the xml:
    Code:
    <root>	
    	<windowclass name="charsheet_main">
    		<script file="campaign/scripts/char_main.lua" />
    So that is the Windows-connected (one instance per window) of the (char_main.lua) lua script.

    Then at the controls:
    Code:
    			<number_savingthrow name="savingthrowbase" 
    				source="defenses.saves.default.base">
    				<anchored>
    				   <top parent="label_savingthrow" anchor="bottom" offset="10" />
    				   <right parent="frame_classlevel" anchor="right" offset="-12" />
    				</anchored> 
    
    is derived from:
    	<template name="number_savingthrow">
    		<number>
    			<frame name="frame_charsheet_savingthrow" offset="7,5,7,5" />
    			<anchored width="32" height="20" >
    				<top parent="**MISSING ANCHOR**" anchor="bottom" offset="5" />
    				<right parent="savingthrowbase" />
    			</anchored> 
    			<nokeyedit />
    			<rollable />
    			<script file="campaign/scripts/char_saves_sw.lua" />
    	</number>
    	</template>
    So EACH Saving throw control element has its own copy of the lua script (char_saves_sw.lua)


    So, the code that I want to be called, I can put in char_main.lua but I wanted to not clutter it up too much with too many disparate "areas of responsibility", I would like to delegate the work to files of related code. So, as I said in my original question - I'd be happy to have include statements if they were allowed. They are not

    So, I was wondering if there were tricky ways. From reading the doc page, I do not SEE any "tricks" that might be cleaner than:


    Call the Window script: char_main.lua that script delegates/sends a reference to the controls in question to a method in another global script that ONLY handles stuff related to X (e.g., Saving Throws)

    Again - just trying to have smaller LUA files with more associated code concentrations. If it doesn't work or have issues, sure, I can toss the kitchen sink into char_main.lua.

    (Now sitting at an airline counter per after 2nd canceled flight. Yay... at least have my laptop to work on)

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,362
    You can't include additional scripts within XML or controls. You can layer scripts (based off layered rulesets) but this gets very complex and I would *not* recommend it.

    So you have the two options you mention - the window level script (one instance of the script per window) or the global script package if you want to remove code from the control script. The thing to remember about Global packages is that there is only one instance of them, so you have to pass in either the main DB node or the window instance you're working on (best practice is to operate against DB nodes, not GUI controls/windows) and then do generic scripting accessing FG APIs on those objects.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in