1. #1

    Calling windowclass

    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:

    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>
    In file1.xml, I have this:
    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>
    And here is the lua file code.
    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
    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.

    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.

  2. #2
    I’m not sure what you are asking exactly. Off the top of my head, my suggestion is to just add an else statement to end of onInit so that clientStart gets called if not on host.

    JPG

  3. #3
    This is called when the host first connects.

    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
    I can't call that when the player first logs on, because they don't have access to that node and they have not selected their character yet to save it to their node. So, instead of looking for this info when they first log in, I want to wait till they open their character sheet and then call this section. The issue is

    if sourcefields then
    is gonna return false, because the character sheet does not have the sourcefields variable. That is stored in file1.xml.

    So I want to know if, when I open the character sheet, which triggers the onInit() in say record_char.xml. Can I tell it to open file1.xml, go to "diegroup" and if there is a sourcefield to then process this code with that value from sourcefields?
    Add me on Twitch: twitch.tv/statik367

    If you like what I am doing, you can support me via PayPal: paypal.me/wesleytoma
    Or Venmo: venmo.com/Wesley-Toma-Lee

  4. #4
    There's nothing in there that is going to trigger that from the PC sheet.

    I would maybe register a callback on User.onIdentityActivation which gets called whenever a player makes a PC active. You'll need your window to correctly change when PCs are changed; because a user can have more than one PC logged in at a time, but only one active at a time.

    Regards,
    JPG

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in