PDA

View Full Version : Need help with coding Interface.openwindow



LucasDM
November 11th, 2019, 14:05
Hi. I've been coding small ext coz my team always forget check off their used spell slots and in FGC no auto checking. So i make a BIG annoing button "CHOOSE SLOT" and some simple code. But i have problem. This button opens little window which gives you options to check slot that you gonna use and check it off from your slots. Also it's warning you if you dont have free slot. The problem is when i as GM open player charlist and open Actions tab im kinda become another owner and when the player click on that button it opens 2 window. 1 for me and 1 for initiator. But if i didnt open Action tab all is ok.
So i need this open 1 window to initiator only. Sorry for my eng and my code :D here it is btw
extension.xml


<?xml version="1.0" encoding="iso-8859-1"?>
<root release="3.0" version="3">
<properties>
<name>DND 5e Spell Slots Check</name>
<version>0.0.1</version>
<author>Nicolas Lucas</author>
<description>
Here will be link for tutorial
</description>
</properties>
<base>
<includefile source="xml/Window.xml" />
<script name="SSC" file="xml/scripts.lua" />
<string name="local_tab_ssc">CHOOSE SLOT</string>
<string name="local1_tab_ssc">CHOOSE1 SLOT</string>
<windowclass name="charsheet_actions" merge="join">
<sheetdata>
<button_stringcycler name="local_tab_ssc">
<anchored position="insidebottomright" offset="70,200" width="80" height="80"/>
<parameters>
<labelsres>local_tab_ssc</labelsres>
<values>1|2</values>
<defaultlabelres>local_tab_ssc</defaultlabelres>
</parameters>
<script>
function onValueChanged()
--[[Interface.openWindow("SSCWindow", window.getDatabaseNode());]]
Interface.openWindow("SSCWindow",window.getDatabaseNode());
end
</script>

</button_stringcycler>

</sheetdata>
</windowclass>
</base>
</root>

xml/window.xml

<?xml version="1.0" encoding="iso-8859-1"?>
<root release="3.0" version="3">

<string name="cont_ssc">CONTINUE</string>
<string name="no_ssc">NO SLOTS!</string>
<windowclass name="SSCWindow">
<frame>utilitybox2</frame>
<script>
function onInit()
--[[ Self points to a windowinstance, in this case.
Debug.console("self", self)
Debug.console("getclass", self.getClass())
Debug.console("getDatabaseNode", self.getDatabaseNode())
Debug.console("getFrame", self.getFrame()) ]]
end
</script>
<placement>
<size width="160" height="180" />
</placement>
<sheetdata>
<close_campaignlist />
<label>
<anchored position="insidetopleft" offset="23,7" width="100" height="30">

</anchored>
<static textres="power_label_spellslots" />
</label>
<simplenumber name="slot_n" source="powermeta.curslot">
<anchored position="insidetopleft" offset="23,60" width="110" height="30">
</anchored>
<frame name="fieldlight" offset="7,5,7,5" />
<script>
function onValueChanged()
SSC.checkSlots(window.getDatabaseNode(), window.cont_ssc, window.no_ssc)
end
</script>
</simplenumber>
<button_stringcycler name="cont_ssc">
<anchored position="insidetopleft" offset="23,110" width="110" height="30"/>
<parameters>
<labelsres>cont_ssc</labelsres>
<values>1|2</values>
<defaultlabelres>cont_ssc</defaultlabelres>
</parameters>
<script>
function onValueChanged()
SSC.useSpell(window.getDatabaseNode(),window)
end
</script>
</button_stringcycler>
<label name="no_ssc">
<anchored position="insidetopleft" offset="50,110" width="110" height="30"/>
<static textres="no_ssc" />
<invisible />
</label>
</sheetdata>


<playercontrol />

</windowclass>
</root>
xml/scripts.lua



function checkSlots(nodeWin,cond,lond)
local rActor = ActorManager.getActor("pc", nodeWin );
local nodePC = DB.findNode(rActor['sCreatureNode']);
local curvals = DB.getValue( nodePC.getPath() .. '.powermeta.curslot' );
local slotmax = DB.getValue( nodePC.getPath() .. '.powermeta.spellslots' .. curvals.. '.max' );
Debug.console(slotmax);
Debug.console(curvals);
if slotmax then
if slotmax>0 then
local slothas = DB.getValue( nodePC.getPath() .. '.powermeta.spellslots' .. curvals .. '.used' );
if slothas then
if slothas < slotmax then
cond.setVisible(true);
lond.setVisible(false);
else
cond.setVisible(false);
lond.setVisible(true);
--cond.setVisible(false);
end
end
else
cond.setVisible(false);
lond.setVisible(true);
end
else
cond.setVisible(false);
lond.setVisible(true);
end;
end;

function useSpell(nodeWin,w)
checkSlots(nodeWin,w.cont_ssc,w.no_ssc)
local rActor = ActorManager.getActor("pc", nodeWin );
local nodePC = DB.findNode(rActor['sCreatureNode']);
Debug.console(nodePC.getOwner());
local curvals = DB.getValue( nodePC.getPath() .. '.powermeta.curslot' );
if w.cont_ssc.isVisible() then

local slothas = DB.getValue( nodePC.getPath() .. '.powermeta.spellslots' .. curvals .. '.used' );
local slotmax = DB.getValue( nodePC.getPath() .. '.powermeta.spellslots' .. curvals.. '.max' );
if slothas then
slothas = slothas + 1;
else
slothas = 1;
end
if slothas<slotmax then ChatManager.Message("I'm gonna spend lvl "..curvals.." spell.", true, nodePC.getOwner()) else ChatManager.Message("I'm gonna spend LAST lvl "..curvals.." spell.", true, nodePC.getOwner()) end;
DB.setValue( nodePC.getPath() .. '.powermeta.spellslots' .. curvals .. '.used','number', slothas );
w.close()
else
ChatManager.Message("I have no free spellslots lvl "..curvals, true, nodePC.getOwner());
end
end;

Trenloe
November 11th, 2019, 14:19
You’re using the event onValueChanged to open the window. This event will run on any instance that has registered that event handler.

Use this instead: https://www.fantasygrounds.com/refdoc/buttoncontrol.xcp#onButtonPress

LucasDM
November 11th, 2019, 15:07
Thanx!

I replaced cyclebtn to

<buttoncontrol name="cont_ssc">
<anchored position="insidetopleft" offset="23,110" width="110" height="30"/>
<state frame="fielddark" text="CONTINUE" font="" />
<static textres="cont_ssc" />
<tooltip textres="cont_ssc" />
<script>
function onButtonPress()
SSC.useSpell(window.getDatabaseNode(),window)
end
</script>
</buttoncontrol>

And now it works. :)