Thread: Buttongroup_counter
-
November 11th, 2019, 06:19 #21
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
I feel like such a pain now, but let me try to explain this a little better.
In order to create the pips on the desktop I am using the buttongroup_counter template and lua file from CoreRPG. The only difference is I stripped out all reference to the database. Once I did that, I was able to get the buttons to click on and off as expected. When I add debug commands into the lua file I can generate the correct value. The thing I'm struggling with is now how to I pull that info from the file? I tried registering controls. I tried the getmodifierkey like in 5e. Nothing I have tried will pull a value of 1 to 5 as I would like.
As of right now, the only change I have made that makes things work is stripping out the database stuff so the buttons will react. At this point I don't know what else to do to get the info out.
I am attaching the lua file here for reference. As I said, all I did was strip the db info. Any insight on how to now pull the value out of this file and store it in a variable in another lua file? I looked at the 5E code, and from what I can see, it's just looking for a single button to be on or off I tried to manipulate it to work for a variable button, but I couldn't figure it out.
for reference, here is the template:
Code:<template name="dice_counter"> <genericcontrol> <stateicons> <on>button_checkon</on> <off>button_checkoff</off> </stateicons> <script file="desktop/scripts/dice_counter.lua" /> </genericcontrol> </template>
Code:<windowclass name="rollpanel"> <sizelimits> <minimum width="64" height="52" /> </sizelimits> <noclose /> <sheetdata> <dice_counter name="diegroup"> <anchored position="insidetopleft" offset="4,50" width="60"/> <allowsinglespacing /> <stateicons> <on>button_checkon2</on> <off>button_checkoff2</off> </stateicons> <values> <maximum>5</maximum> <current>2</current> </values> <sourcefields> <current>curr</current> </sourcefields> <maxslotperrow>5</maxslotperrow> </dice_counter> </sheetdata> </windowclass>
right now, that's everything I have and did. I don't know what to do next so when I run this function in a different file:
Code:function taskcheck(draginfo, winFrame, foc, tar) local nodeWin = winFrame.getDatabaseNode(); local node = DB.findNode("."); local rActor = ActorManager.getActor("pc", nodeWin); local rolling20 = 0; rolling20 =????????; local sides = 20; local TN = DB.getValue(nodeWin, tar); local FC = DB.getValue(nodeWin, foc); local nDiff = ActionsManager2.encodeDesktopDiff(nDiff); local nComp = 1 -- nodeWin.getChild("rollable.comprange").getValue(); local comp = 21 - nComp local sParams = rolling20.."d"..sides.."t"..TN.."f"..FC.."c"..comp.."d"..nDiff; local msg = {font = "sheetlabel"}; msg.text = rActor.sName .. " rolls a task" Comm.deliverChatMessage(msg); local msg = {font = "sheetlabel"}; msg.text= "Target Number.." .. TN.."\nFocus Range.."..FC.."\nComplication Range.."..nComp.."\nDifficulty.."..nDiff.."\nRolling "..rolling20.. "d20\n"; Comm.deliverChatMessage(msg); resetdice(winFrame); DiceRoller.performAction(draginfo, rActor, sParams) return true; end
I hope that all makes sense. I have been staring at this code for 2 weeks now, and I have to somehow get it to work.
-
November 11th, 2019, 19:49 #22
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
OK, after searching the forums further, I found this:
https://www.fantasygrounds.com/forum...on-the-Desktop
The number 2 version looks pretty much exactly what I want, but instead of entering a number, I want it to add up the value of the pips.
I put the functions in the dice_counter.lua file and added the script to the windowclass.
I then had rolling20 = DiceCounter.getDCValue. I changed the control names as appropriately. However, when I reload and try a roll, I get
attempt to call field 'getValue' (a nil value)
-
November 11th, 2019, 19:53 #23
What code is running when you get that error? "nil value" means that getValue is being called against an invalid FG object. What object do you have before the getValue() code? Something like myControlName.getValue()
As I mention in this post: https://www.fantasygrounds.com/forum...l=1#post387852 "... uses control.examplenumber.getValue() to get the value stored in the examplenumber number control ..."Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
November 11th, 2019, 19:57 #24
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
function getDCValue()
local numberValue = 0;
if control then
Debug.chat(control.diegroup);
numberValue = control.diegroup.getValue();
end
return numberValue;
end
And the debug gives me: "windowcontrol = {x,y,w,h = 4,50,50,10}
-
November 11th, 2019, 20:01 #25
What does debug for control give you?
What does debug for control.diegroup give you?
You're calling this: numberValue = control.diegroup.getValue(); so FG is looking for a GUI control called control.diegroup - does that exist? Is it accessible from where the code is running? Is getValue() a valid API call for that type of control?Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
November 11th, 2019, 20:04 #26
Also please read, in detail, the information I provide in the forum posts you've linked. For example:
"note that control is actually a local variable declared at the stop of the script file - it is here that the reference to the desktop panel control will be stored when it is registered. This allows future function calls into this package to get access to the desktop panel control."
Do you have this local variable in your script? Do you register it to the actual desktop control?Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
November 11th, 2019, 20:05 #27
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
Debug of control gives me:
windowinstance = { class = rollpanel, node = nil, x,y,w,h = 6,944,74,62 }
Debug for control.diegroup gives me:
windowcontrol = {x,y,w,h = 4,50,50,10}
For reference, rollpanel is the name of the windowclass and diegroup is the name of the genericcontrol
-
November 11th, 2019, 20:06 #28
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
And for your second question, yes I added:
Code:local control = nil; function registerControl(ctrl) control = ctrl; end
And the windowclass has
Code:<script> function onInit() DiceCounter.registerControl(self); end function onClose() DiceCounter.registerControl(nil); end </script>
-
November 11th, 2019, 20:08 #29
getValue() is not a valid API call for genericcontrol : https://www.fantasygrounds.com/refdo...riccontrol.xcp
Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
November 11th, 2019, 20:15 #30
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
Well shoot.
Now I feel dumb.
Is there something I can do for it to look the same and be able to do what I want it to?
I want it to look like the file attached and click on and off sequentially.
Here is the code I am using now, for reference.
Code:<template name="dice_counter"> <genericcontrol> <stateicons> <on>button_checkon</on> <off>button_checkoff</off> </stateicons> <script file="desktop/scripts/dice_counter.lua" /> </genericcontrol> </template>
Code:<dice_counter name="diegroup"> <anchored position="insidetopleft" offset="4,50" width="60"/> <allowsinglespacing /> <stateicons> <on>button_checkon2</on> <off>button_checkoff2</off> </stateicons> <values> <maximum>5</maximum> <current>2</current> </values> <sourcefields> <current>curr</current> </sourcefields> <maxslotperrow>5</maxslotperrow> </dice_counter>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks