5E Character Create Playlist
  1. #1

    Calling of function in a separate .lua script file

    Hi

    I have a question about scripting in FG.

    I have defined a function in a lua file of the charsheet directory of the ruleset I'm working on.

    I want to call that function onInit and onValueChanged of a attributecheckbonus "widget". But I have to use the same function on 2 other attributescheckbonus since 3 attributes are included in the calculation of the function.

    How can I call that function, (lets call it calcMentalLimits) from 3 attributes on the onInit and onValueChanged without copy pasting the same code 3 places in the script block of the attributecheckbonus widget?

    I already put the code in a script .lua file but don't know how to reference it correctly at the right location to be able to use the function without having a name of function (nil) message...

    Thanks

  2. #2
    Add a <script name="GameSystem" file="scripts/manager_gamesystem.lua" /> into base.xml.

    Then you can use GameSystem.calcMentalLimits. You add that in the base.xml. If you are doing a lot of this type of work I personally suggest Ruleset Wizard. I use it exclusively.

    Jason

    Edit: My first option was incorrect. Turns out Ruleset Wizard had been helping me by creating a name mapping that allowed it to work.
    Last edited by jharp; August 17th, 2021 at 00:23.

  3. #3
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,408
    Quote Originally Posted by jharp View Post
    If for example the LUA filename is named "external.lua" then you can call it with external.calcMentalLimits().
    That won't work. You can't just refer to a LUA file in that way.

    Quote Originally Posted by jharp View Post
    <script name="GameSystem" file="scripts/manager_gamesystem.lua" />

    Then you can use GameSystem.calcMentalLimits. You add that in the base.xml.
    Yes, this will work - these are known as Global Script packages.


    @Nilliom - there are three ways to call LUA functions - in controls, window instances (window classes) or via Global Script Packages - these are described here: https://fantasygroundsunity.atlassia...#Using-Scripts

    It sounds like you're wanting to call a function that is attached to a control. In which case you can use <GUI hierarchy path>.<control name>.<function name> - maybe something like window.attributecheckbonus.myFunction

    The issue could be if you can't reliably traverse the GUI hierarchy from where your code is running.

    Whereas it's possible to call the onInit and onValueChanged functions externally, it's not recommended as these are called at specific times in the control's life via a system generated event. If you want to run some code outside of these events then it's best to have these in custom functions within the control's LUA script and then call these externally and also from within the onInit/onValueChanged event handlers if they share the same code.
    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!

  4. #4
    Thanks it works

    I have some questions for you about Ruleset Wizard.

    For me it would end up costing 73$ Canadian to buy that software, which I find to be a steep price so I would like to know what I would buy, especially for a beta software.

    Can we use it to update an existing ruleset?
    Is it easy to use?
    Is it complete, that you can do everything needed in a ruleset?
    Is it stable, does it crash often or scrap your work?

    Thanks for your help

  5. #5
    It would be best to post your questions related to that program in it's own thread:
    https://www.fantasygrounds.com/forum...nt-environment

    That way you can get speedier answers and the developer also watches that thread.
    Dominic Morta
    Ruleset Developer
    Smiteworks

    How to zip up your campaign if the Developers ask for it-How to zip up your campaign if the Developers ask for it

    How to provide an Unity Connection issue?-Connection Issues and What to Provide

    Unity Updater issue?-Updater Issues

    Classic and Unity Port Forwarding?-Fantasy Grounds Connections Explained

    Comcast or Cox ISP User?-Comcast XFinity and Cox Users

    Have a suggestion?-Feature Request

  6. #6
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,685
    Blog Entries
    1
    No IDE will build everything for you.
    Is it complete? What does that mean? You can do everything within the tool but you must still write some code and you must still understand how FG rulesets work.

    Updating an existing ruleset might be easy or it might be very complex.
    If you want to change the font of the name field thats easy on the other hand the range of your changes could be nearly infinite.

    I have had it crash twice and I lost the 5 or 10 mins of work I had been working on.
    I have once had a file get corrupted but I dont know if it was RW or something else that caused it.

    I have written several full rulesets inside the RW - I think its a great tool.

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
  •  
5E Product Walkthrough Playlist

Log in

Log in