Starfinder Playlist
  1. #1

    Conditional hiding (control)

    Sorry for the not-programmer language ahead!

    Within the confines of a window-within-a-window I have a button that does this:

    Code:
    function onClickDown()
    	local nodeWin = window.getDatabaseNode();
    	local XP = nodeWin.getChild("skill_xp").getValue();
    	local XPpay = nodeWin.getChild("skill_xptolvl").getValue();
    	local XPnew = XP-XPpay;
    	nodeWin.getChild("skill_xp").setValue(XPnew);
    end
    
    function onClickRelease()
    	local nodeWin = window.getDatabaseNode();
    	local nSkill = nodeWin.getChild("skill_current").getValue();
    	local nSkillnew = nSkill+1;			
    	nodeWin.getChild("skill_current").setValue(nSkillnew);
    end
    Works like a charm the way I have set the window up to serve the parent windowlist.
    Now, I want to hide the button, making it accessible only if the current skill_xp value exceeds or equals the current skill_xptolvl value. But is that at all possible?

  2. #2
    Quote Originally Posted by Lillhans View Post
    Now, I want to hide the button, making it accessible only if the current skill_xp value exceeds or equals the current skill_xptolvl value. But is that at all possible?
    One of many solutions:
    - Add the xml tag <invisible /> to the button.
    - Add this pseudocode to skill_xp

    Code:
        function onValueChanged()
            local nXP = getValue();
            local nCurrentXP = path_to_node.getValue();
    
            if nXP >= nCurrentXP then
                path_to_button.setVisible(true);
            end
        end
    You might also want to call onValueChanged() in onInit().

    If your data is saved to the DB, it's advised to directly call the DB with DB.getValue() and DB.setValue().
    See here for more information: https://fantasygroundsunity.atlassia...s/996644582/DB

  3. #3
    Quote Originally Posted by Zarestia View Post
    One of many solutions:
    - Add the xml tag <invisible /> to the button.
    - Add this pseudocode to skill_xp

    Code:
        function onValueChanged()
            local nXP = getValue();
            local nCurrentXP = path_to_node.getValue();
    
            if nXP >= nCurrentXP then
                path_to_button.setVisible(true);
            end
        end
    You might also want to call onValueChanged() in onInit().

    If your data is saved to the DB, it's advised to directly call the DB with DB.getValue() and DB.setValue().
    See here for more information: https://fantasygroundsunity.atlassia...s/996644582/DB
    Thank you for the quick reply! I probably will want to explore this whole DB thing eventually, for sure. For the time being I am scattering triggers across a multitude of controls.

  4. #4
    Quote Originally Posted by Zarestia View Post
    Having read and re-read the wiki and how
    getPath()
    is implemented in other rulesets and extensions I can't seem to figure out how to grab the path properly.

    specifically:

    function onValueChanged()
    local nodeWin = window.getDatabaseNode();
    local XP = nodeWin.getChild("skill_xp").getValue();
    local XPpay = nodeWin.getChild("skill_xptolvl").getValue();
    local XPinc = nodeWin.getChild().getPath("button_skill_increase" );

    if(XP>=XPpay) then
    XPinc.setVisible(true);
    end
    end
    ...made me feel extra smart for a while but alas
    Last edited by Lillhans; September 9th, 2022 at 08:17.

  5. #5
    You're mixing the concepts of database interactions with UI object interactions. The button_skill_increase is a UI control, not a database node.

    If I was going to write similar code, I would write like this:

    Code:
    function onValueChanged()
        local node = window.getDatabaseNode();
        local nXP = DB.getValue(node, "skill_xp", 0);
        local nXPToLevel = DB.getValue(node, "skill_xptolvl", 0);
    
        local bShowIncButton = ((nXPToLevel > 0) and (nXP >= nXPToLevel));
        window.button_skill_increase.setVisible(bShowIncButton);
    end
    Alternately, you could move the routines up to the window level, like this:

    For both skill_xp and skill_xptolvl fields, add:
    Code:
    function onValueChanged()
        window.onSkillXPUpdate();
    end
    Then, in the window, add this function:
    Code:
    function onSkillXPUpdate()
        local node = getDatabaseNode();
        local nXP = DB.getValue(node, "skill_xp", 0);
        local nXPToLevel = DB.getValue(node, "skill_xptolvl", 0);
    
        local bShowIncButton = ((nXPToLevel > 0) and (nXP >= nXPToLevel));
        button_skill_increase.setVisible(bShowIncButton);
    end
    Regards,
    JPG

  6. #6
    Quote Originally Posted by Moon Wizard View Post
    You're mixing the concepts of database interactions with UI object interactions. The button_skill_increase is a UI control, not a database node.
    Thank you for sorting out the nomenclature!

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
  •  
STAR TREK 2d20

Log in

Log in