Here is an interesting question, at least I think. Can I reference a windowclass of one file in the lua code of another?
An example.
I have this template:
In file1.xml, I have this: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>
And here is the lua file code.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>
</values>
<sourcefields>
<current>curr</current>
</sourcefields>
<maxslotperrow>5</maxslotperrow>
</dice_counter>
This all runs as soon as FG starts. As the GM, this is fine, however, I want to then create a new function clientStart(). Where I will modify the host code to run within the client DB node. The problem is, hostStart has the if sourcefields and sourcefields[1] stuff. Which when this code is called for the client, it won't be there.Code:function onInit()
if values then
if values[1].maximum then
nLocalMax = tonumber(values[1].maximum[1]) or 0;
end
if values[1].current then
nLocalCurrent = tonumber(values[1].current[1]) or 0;
end
end
if maxslotperrow then
nMaxSlotRow = tonumber(maxslotperrow[1]) or 10;
end
if spacing then
nSpacing = tonumber(spacing[1]) or nDefaultSpacing;
end
if allowsinglespacing then
setAnchoredHeight(nSpacing);
else
setAnchoredHeight(nSpacing*2);
end
setAnchoredWidth(nSpacing);
bInit = true;
updateSlots();
registerMenuItem(Interface.getString("counter_menu_clear"), "erase", 4);
if User.isHost() then
hostStart();
end
end
function hostStart()
DB.setValue("curdie.curr", "number", 2);
local sLoadMaxNodeName = "";
local sLoadCurrNodeName = "";
-- Synch to the data nodes
local nodeWin = DB.findNode("curdie");
if nodeWin then
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
end
Can I add something to the client side that says if file1.xml windowclass sourcefields and sourcefields[1]?
I could probably create an invisible windowclass that calls the template and I put in a new sourcefield, but that seems like a crap way to do it. Unless it's the only way, then I guess I can try that.