PDA

View Full Version : Conditional hiding (control)



Lillhans
September 4th, 2022, 20:06
Sorry for the not-programmer language ahead!

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


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?

Zarestia
September 4th, 2022, 21:04
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



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.atlassian.net/wiki/spaces/FGCP/pages/996644582/DB

Lillhans
September 5th, 2022, 09:35
One of many solutions:
- Add the xml tag <invisible /> to the button.
- Add this pseudocode to skill_xp



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.atlassian.net/wiki/spaces/FGCP/pages/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.

Lillhans
September 9th, 2022, 08:10
See here for more information: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644582/DB

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 :D

Moon Wizard
September 9th, 2022, 15:59
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:



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(bShowIncBu tton);
end


Alternately, you could move the routines up to the window level, like this:

For both skill_xp and skill_xptolvl fields, add:


function onValueChanged()
window.onSkillXPUpdate();
end


Then, in the window, add this function:


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

Lillhans
September 10th, 2022, 13:41
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!