Thread: Toggling a button via script
-
April 2nd, 2020, 21:11 #1
Toggling a button via script
I have assigned a "Leader" button to CT entries. Clicking it designates that character as the leader of their faction ("friend", "foe", "neutral", etc.)
Only one character can be the leader of a faction. If I click a leader button, I want anyone in that faction who was previously the leader to be removed as leader.
I can set the value for a faction's leader in the DB and remove the previous leader. However, how can I uncheck the button of the previous leader on the CT?
function onLeaderChanged()
local nodeRecord = getDatabaseNode();
local bLeader = leader.getValue();
-- can only be one leader
if bLeader then
DB.setValue(nodeRecord, "leader", "boolean", true);
local sFaction = DB.getValue(nodeRecord, "friendfoe", "");
for _,v in pairs(CombatManager.getCombatantNodes()) do
if DB.getValue(v, "friendfoe", "") == sFaction then
if nodeRecord ~= v then
DB.setValue(v, "leader", "boolean", false);
-- NEED CODE HERE - I want to toggle the "leader" button for v
end
end
end
end
Debug.chat(nodeRecord,bLeader,sClass,sFaction);
end
-
April 2nd, 2020, 21:25 #2
I think the method I would use to approach this would be to do a for loop to go through each window and set leader false.
Something like:
for _,w in pairs(getWindows()) do
w.leader.setValue(0 or whatever value turns it off)
end
It's a rough idea, but hopefully it helpsDominic 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
-
April 2nd, 2020, 23:23 #3
Thank you, that worked, basically. I didn't realize that setting the value also toggles the button itself.
-
April 2nd, 2020, 23:27 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 21,008
@AmadanNaBriona,
It depends on the implementation of the button. If the button defines more than one state, then you can change the state by using setValue. (The underlying value type is number.) If no states defined (or only a single state), then the value is always zero.
Regards,
JPG
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks