Thread: Buttongroup_counter
-
November 6th, 2019, 15:57 #1
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
Buttongroup_counter
I am using the buttongroup_counter template on the main desktop.
It looks great, and loads correct. The problem is, in the onInit, there is this section:
Code:-- Synch to the data nodes local nodeWin = window.getDatabaseNode(); if nodeWin then local sLoadMaxNodeName = ""; local sLoadCurrNodeName = ""; if sourcefields then if sourcefields[1].maximum then sLoadMaxNodeName = sourcefields[1].maximum[1]; end if sourcefields[1].current then sLoadCurrNodeName = sourcefields[1].current[1]; end end if sLoadMaxNodeName ~= "" then if not DB.getValue(nodeWin, sLoadMaxNodeName) then DB.setValue(nodeWin, sLoadMaxNodeName, "number", 1); end setMaxNode(DB.getPath(nodeWin, sLoadMaxNodeName)); end if sLoadCurrNodeName ~= "" then setCurrNode(DB.getPath(nodeWin, sLoadCurrNodeName)); end end
I was thinking of throwing that section into a separate function, and when host call it at one point, and when player, call it when char sheet opens. If I do that, I feel like I may need to create a different nodeWin for player and host, but I'm not sure if this will work or not. I don't know if it will be as simple as that, since the file also has a few other functions that will do a DB.getValue and DB.setValue. Any insight would be appreciated.
-
November 6th, 2019, 16:41 #2
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
Also, a thought, because this will have an effect on the dice roll, should I modify the buttongroup_counter.lua file and add the registerControl and updateControl functions from modifierstack.lua and then manipulate those somehow? If that is the answer, I will also need a little guidance. Basically, I want a 5 button system that just keeps track of a number 1 to 5, and when I roll the dice, I can then throw it into rRoll as another key value pair.
-
November 6th, 2019, 19:24 #3
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
OK, update on what I've done. I initially used the buttongroup_counter template as is, but I had two groups on the desktop. Different windowsclasses though. but when I made them both the buttongroup template, they seemed to be linked and when clicking one, the other would also increase or decrease. So, I separated them into two different templates and I made two copies of the lua file unique to the template. Now, it kinda works. First off, it would error out after the first click because under the setCurrentValue function was this:
function setCurrentValue(nCount)
if sCurrNodeName ~= "" then
DB.setValue(sCurrNodeName, "number", nCount);
else
nLocalCurrent = nCurrent;
end
end
-
November 6th, 2019, 23:54 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,557
I didn't quite follow if you still had questions, or whether you were just documenting the steps you went through. If you have questions, just call them out in a bulleted list or in some way that it's obvious and myself or the community can try to answer.
Regards,
JPG
-
November 7th, 2019, 00:03 #5
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
Sorry, I was not thinking of clearity as I was typing it up. I do still have questions.
1) The line:
local nodeWin = window.getDatabaseNode();
2) the buttons are showing up and whatever I have the starting value at is what buttons are on and what are off (staring value of 2, first two are checked on last 3 are not). When I debug and click on them, the debug tells me the actual value that it should be, but the icons are not updating. How do I fix that?
3) Once I get this fixed, I want to be able to be able to add these as a key value pair to rRoll, once I initiate the roll. How do I do that? I assume it would be similar to the nMod pair, but I can't find where in the system that info is collected. Any help on that would be appreciated.
-
November 7th, 2019, 00:43 #6
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,557
1) The controls on the desktop should still be encapsulated in a window instance. So, window.getDatabaseNode() should still work, and just return nil. What's the exact error message you are seeing in the console?
2) The template was really built to support database-linked capability in a sheet to which the user has access. Since you are making your own, I would copy the template and script; and modify what you need.
Since it is not linked to the database, you'll need to call the update() function for the control manually after changing either the current or max values, in order for the template to update it's visual display. That's what the addHandler/removeHandler functions set up to do automatically when this template is database-linked.
If this control is meant to be mirrored in values on both host and player, then you can create a global database node to hold the values; and have the template linked that way. Of course, since only one user can own a database node at a time, the reality is that only the GM will be able to update the values. If you want something that either the GM or players can update independently of each other, that's more complex, and would require OOB messaging to set that up.
If this control is meant to be unique in values for each user, then you would want to rip out all the database stuff in your copied version of the template script; and just make the setMaxValue and setCurrentValue functions perform the update call directly.
3) There is no place to inject values into a roll arbitrarily. You have to override the individual roll handling for rolls that are affected. This is how it's handled in the 5E ruleset for example to handle the ADV/DIS, +/-2, and +/-5 buttons.
Regards,
JPG
-
November 7th, 2019, 12:07 #7
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
Hello,
Thank you for that help. I now have the physical buttons working. Here's a question to expand on #3. I know, if I type a number into the modifier box and then roll the dice, the system will add that number to the roll. From what I can tell, that box is not stored in the DB. I have been looking and having trouble finding the code that actually tells the system, if there is a number here, then use it as a modifier. I know it usually gets saved as rRoll.nMod, and then it is used however, once the roll is complete. But how does the system grab that number to then add it to the rRoll table? I looked in some action files, but I feel like I may be missing a step, as it doesn't seem complete. I also don't see any OOB messaging used for the modifier, unless that piece I'm missing uses it. I hope that makes sense, and I'm sorry if these are dumb questions.
-
November 7th, 2019, 17:27 #8
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,557
That code is embedded in the ModifierStack and ActionsManager global scripts within CoreRPG ruleset.
As I mentioned, you should look at 5E, which has an example of pulling desktop button modifiers into rolls. See ActionsManager2.encodeDesktopMods(rRoll); calls throughout 5E ruleset.
Regards,
JPG
-
November 7th, 2019, 19:14 #9
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
So, further questions. Upon research, I found this under desktop_template.xml
<script>
local bInit = false;
function onInit()
if ModifierStack.getModifierKey(getName()) then
setValue(1);
end
bInit = true;
end
function onValueChanged()
if bInit then
if getValue() ~= 0 then
ModifierStack.setModifierKey(getName(), true);
else
ModifierStack.setModifierKey(getName(), false);
end
end
end
Debug.chat(bInit);
</script>
-
November 7th, 2019, 19:19 #10
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,557
The ModifierStack built-in functionality only knows about whether a button is pressed or not; there's no concept of a multi-state like you're trying to do. You could implement as five different "keys" that are true/false, based on the value. However, you could just have your own custom global script to track this that you reference in the roll modification code.
Regardless of how you do this, you will still need to handle this in your own custom roll modification code as mentioned in post #8 above.
Regards,
JPG
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks