Fantasy Grounds Merchandise
  1. #1

    Could use some help with my LUA Scrip code

    Hello everyone,

    I'm working on creating a rule set using the Ruleset wizard for the XML part, but I'm having an issue with my LUA script. So I have a window where my players will be able to create custom spells for my game system, and this window facilitates that part.

    So I'm trying to do it mechanically, when the player clicks a checkbox for the "random turns" line of the window, the Lua script takes the value of -8 from one number field and places it in the total number field. But I keep getting this error.

    Attachment 64130

    I am still very unfamiliar with Lua, so I may be missing an elementary step in making this script work.

    Attachment 64131

    Here is my current script.

    function onValueChanged()
    local infoGet = window.getDatabaseNode();
    local RTcheck = infoGet.getChild("r_t_check").getValue();
    local ptsDef= infoGet.getChild("defaul_score").getValue();
    local ptsVal = infoGet.getChild("2_base_pts_num_fie").getValue();
    local putPTS = infoGet.getChild("2_tol").setValue(ptsVal);

    if RTcheck == 0 then
    RTcheck = ptsDef
    elseif RTcheck == 1 then
    RTcheck = ptsVal
    end
    end

    Any insight is welcomed, thank you for your time

  2. #2
    Let's start by cleaning up the code:
    Code:
    function onValueChanged()
    
    local infoGet = window.getDatabaseNode(); local RTcheck = DB.getValue(infoGet, "r_t_check", ""); -- Not sure of data type but you can change "" to 0 for a nil return local ptsDef= DB.getValue(infoGet, "defaul_score", ""); -- Same as above local ptsVal = DB.getValue(infoGet, "2_base_pts_num_fie", ""); -- Same as above local putPTS = DB.setValue(infoGet, "2_tol", "string", ptsVal);; -- Assuming a string type here
    if RTcheck == 0 then
    RTcheck = ptsDef
    elseif RTcheck == 1 then
    RTcheck = ptsVal
    end
    end
    The error is pointing to either not finding the control or the database does not have that child. With the above it will check the database for the child of the parent node and if it's nil, it will return an empty string. You can basically put what you want here, but I would suggest keeping it the same data type. If it's not a string, you would replace "" with 0 and when you set the value it would be "number" instead of "string". This is just based off the error you posted. I would suggest checking out CoreRPG and the other provided rulesets for examples of pulling data from the database or controls. There is also the dev portal on the wiki that will provide more details on client API's: https://fantasygroundsunity.atlassia...eveloper+Guide
    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

  3. #3
    Also, the discord has a coding_help channel you are free to ask away in and we can help in real time.

    https://discord.gg/7y2Fs6yq
    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

  4. #4
    Thank you for the help and sources.

  5. #5
    I appreciate your help earlier.

    I decided to go in a different direction. The player will have a number field where they can insert a number, which will multiply the score. The total is input in another field.

    Here is the new error code I'm getting.
    error.jpg

    This is the code
    function onValueChanged()
    local nodeWin = window.getDatabaseNode(); -- This is looking up the window
    local buyPTS = DB.getValue(nodeWin, "1_buy", 0); -- This is getting the value from the player
    local ptsTOT = math.floor(10*buyPTS); -- This is calculating the score value against the player's input

    nodeWin.getChild("1_tot").setValue(ptsTOT); -- This is placing the results of the previous line in the "Pts cost" number field
    end

    Any insight would be helpful.

  6. #6
    nodeWin.getChild("1_tot").setValue(ptsTOT);

    -->

    DB.setValue(nodeWin, "1_tot", "number", ptsTOT);
    Last edited by Moon Wizard; April 28th, 2025 at 22:27.
    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

  7. #7

  8. #8
    I would suggest checking out the wiki for more information on using the API's and such for the program
    https://fantasygroundsunity.atlassia...s/996644582/DB
    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

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 Character Create Playlist

Log in

Log in