5E Character Create Playlist
  1. #1

    Update a linked field from another one

    Hi all,

    Here is a little problem I have... that need a little help !

    I'd like to update the load fields of my charsheet when the strength ability is updated.
    I've wrote this little piece of code in the charsheet_inventorylist.lua file.

    function calculateLoads(strength)
    local data = loaddata[strength];

    encumbrance.lightload.setValue(data.light);
    encumbrance.mediumload.setValue(data.medium);
    encumbrance.heavyload.setValue(data.heavy);
    encumbrance.liftoffground.setValue(data.heavy);
    encumbrance.liftoverhead.setValue(data.heavy);
    encumbrance.pushordrag.setValue(data.heavy);
    end

    -- Carrying capacity
    loaddata = {
    [1] = {
    light = 3, medium = 6, heavy = 10
    },
    [2] = {
    light = 6, medium = 13, heavy = 20
    }
    }

    The problem is : how do I call my function in an Update event of the strength field and is it the best way to do it ?

    Surely it's an easy one, but can't get it work !!!

  2. #2

  3. #3
    I saw this thread... write this... but I have questions :

    <script>
    function onInit()
    getDatabaseNode().onUpdate = calculateLoads;
    end

    function calculateLoads(source)
    local data = loadsdata[source.getValue()];
    window.getDatabaseNode().getChild("encumbrance.lig htload").setValue(data.light);
    end
    </script>

    1 - I use a "table" of values in another file. Is this going to work correctly or is there anything else I have to do ? How can I reach it ?
    2 - The strength field already have an onInit() function in the template "abilityscore", witch is a genral one for all the ability scores. Is my onInit() function will add to the existing one ? Don't think so...

    In fact, I have an error message in the console when running it : "attemp to index global 'loadsdata' (a nil value)"

    Sorry for all the questions... I'm just beginning with FG2 and lua !
    Thanks for your help...
    Last edited by sbocquet; March 30th, 2008 at 19:42.

  4. #4
    Foen's Avatar
    Join Date
    Jan 2007
    Location
    Suffolk, England
    Posts
    2,007
    How close is the ruleset to d20? Does it share the same basic layout (main vs inventory tab) and same rough database structure?

    Cheers

    Stuart

  5. #5
    Hi,

    My ruleset is very very close to the original d20 (same database, same tabs). In fact, I've just translate it in French, and deleted the spells tab and code, because my adventures will take place in the modern world without magic or FX abilities (based on the Jeremiah story).

    In fact, I think that I'm close to it, but can't reach my reference table loadsdata in my lua file to catch the datas.

    If some are interested, I will post it later...

    Here is my code :

    <numberfield name="encumbrancelightload" source="encumbrance.lightload">
    ...
    ...
    ...
    <script>
    function onInit()
    source = window.getDatabaseNode().getChild("abilities.stren gth.score");
    source.onUpdate = update;
    update();
    end

    function update()
    local data = loadsdata[source.getValue()];
    setValue(data.light);
    end
    </script>
    </numberfield>

  6. #6
    Ok, got it work...

    If someone is interested, I can post the solution here...

    Thanks for your help,
    Stéphane

  7. #7
    Oberoten's Avatar
    Join Date
    May 2006
    Location
    Älvsbyn, Sweden
    Posts
    2,622
    Solutions are always of interest.
    For your Ars Magica needs :
    https://fgrepository.com




    Atque in perpetuum frater, Ave atque vale.

  8. #8
    So, here is the solution...

    charshett_encumbrance.lua
    Code:
    function onInit()
    	source = window.getDatabaseNode().getChild("abilities.strength.score");
    	source.onUpdate = update;
    	update();
    end
    
    function update()
    	local data = loadsdata[source.getValue()];
    	window.encumbrancelightload.setValue(data.light);
    	window.encumbrancemediumload.setValue(data.medium);
    	window.encumbranceheavyload.setValue(data.heavy);
    	window.encumbranceliftoverhead.setValue(data.heavy);
    	window.encumbranceliftoffground.setValue(data.heavy*2);
    	window.encumbrancepushordrag.setValue(data.heavy*5);
    end
    					
    -- Carrying capacity
    loadsdata = {
    	[1] = {
    			light = 3, medium = 6, heavy = 10
    		},
    	[2] = {
    			light = 6, medium = 13, heavy = 20
    		}
    and so on...
    }
    and I've added that line in the charsheet_inventory.xml
    Code:
    <numberfield name="encumbrancelightload" source="encumbrance.lightload">
    ...
    	<script file="scripts/charsheet_inventoryencumbrance.lua"/>
    	<readonly/>
    ...
    </numberfield>
    and the <readonly/> tag on all the fields that now don't need to be updated (to be perfect, you also need to rearrange the tab order between the fields in order that the loads fields cannot be selected by the keyboard too ).

    Simple... once you got it works ! lol

  9. #9

    Join Date
    Apr 2008
    Location
    Virginia Beach
    Posts
    3,096
    Question for sbocquet:
    Shouldn't the encumbrance also be affected by strength damage? I think you'd have to make a computed field, like effected strength that never gets displayed and base encumbrance on an update of that field (which, in turn, gets updated on a change to strength or strength damage).

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
  •  
Dungeons & Dragons 2024 Core Rulebooks Pre-Order

Log in

Log in