5E Product Walkthrough Playlist
  1. #1

    Back again with another question

    So I am trying to loop through a windowlist item. I have the code being called correctly (although more times than I would have thought). I am able to get the list object into a variable as well:

    Code:
    databasenode = { npc.id-00002.npcdrlist }
    However, when I try to print out the list items, I get a nil error:

    Code:
    function npcDRCalc(source)
    	Debug.chat("I'm in npcDRCalc");
    	Debug.chat(source);
    	if source then
    		local sPCNodeName = ActorManager.getCreatureNodeName(source);		
    		Debug.chat("Node Name");
    		Debug.chat(sPCNodeName);
    		local vDR = DB.getChild(sPCNodeName, "npcdrlist");    <---- Line 45
    		Debug.chat("After getting child");
    		Debug.chat(vDR);		
    		Debug.chat(vDR.getWindows());
    	end
    end
    Script Error: [string "campaign/scripts/NPCSheetManager.lua"]:45: attempt to call field 'getWindowCount' (a nil value)
    Script Error: [string "campaign/scripts/NPCSheetManager.lua"]:45: attempt to call field 'getWindowCount' (a nil value)
    Script Error: [string "campaign/scripts/NPCSheetManager.lua"]:45: attempt to call field 'getWindowCount' (a nil value)
    Script Error: [string "campaign/scripts/NPCSheetManager.lua"]:45: attempt to call field 'getWindowCount' (a nil value)

    I though the windowlist had a built in function to get all the items from the list. I'm sure its something I am doing wrong, but can't quite put my finger on it. Thanks in advance.

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    There's no "getWindowCount" in the code you list. Is that the actual code you're running - does that cover line 45 in campaign/scripts/NPCSheetManager.lua ?

    EDIT: Sorry, I just saw your "<---- Line 45" comment. Do you have a simple extension, with steps to reproduce the error?
    Last edited by Trenloe; September 22nd, 2021 at 02:30.
    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!

  3. #3
    Basically I have a an windowlist object with the following code attached:

    Code:
    function onInit()			
    	onListChanged();
    end
    
    function onListChanged()
    	local nodeWin = window.getDatabaseNode();
    	NPCSheetManager.npcDRCalc(nodeWin);
    end
    The NPCSheetManager is just a lua script with a function called npcDRCalc which is below:

    Code:
    function npcDRCalc(source)
    
    	Debug.chat("I'm in npcDRCalc");
    	Debug.chat(source);
    
    	if source then
    		
    		local sPCNodeName = ActorManager.getCreatureNodeName(source);		
    		Debug.chat("Node Name");
    		Debug.chat(sPCNodeName);
    		local vDR = DB.getChild(sPCNodeName, "npcdrlist");
    		Debug.chat("After getting child");
    		Debug.chat(vDR);		
    		Debug.chat(vDR.getWindows());		
    	end
    end
    I can probably create a quick extension if that would be easier, but wont be able to get to it until tomorrow.

  4. #4
    Here is a ruleset to test with that just has the issue in it. Just create a new NPC and then add an item to the list.
    Attached Files Attached Files

  5. #5
    You're calling getWindowCount on a databasenode object (or possibly nil depending on return result); which is not a valid API.

    I recommend against "chaining" function calls like you are doing in Line 48 of NPCSheetManager in general. By breaking apart, you can test variables by using Debug.chat(<variable>) to make sure that the objects are the type/value that you are expecting at that point in the code. Also, make sure to review the Developer API reference for valid API calls for each object type.

    https://fantasygroundsunity.atlassia...+API+Reference

    Regards,
    JPG

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,361
    Quote Originally Posted by mixologee View Post
    Here is a ruleset to test with that just has the issue in it. Just create a new NPC and then add an item to the list.
    Thanks for providing that. The code provided has different API calls to that listed in your posts above. Hence my comment in post #2: "There's no "getWindowCount" in the code you list. Is that the actual code you're running..." I was confused because the error was for the API command getWindowCount, but that wasn't in your code snippets provided.

    So, as Moon Wizard has indicated, the code in the ruleset is attempting to use getWindowCount against a database node - which is invalid.

    Code:
    function npcDRCalc(source)
    
    	Debug.chat("I'm in npcDRCalc");
    	Debug.chat(source);
    
    	if source then
    		
    		local sPCNodeName = ActorManager.getCreatureNodeName(source);		
    		Debug.chat("Node Name");
    		Debug.chat(sPCNodeName);
    		local vDR = DB.getChild(sPCNodeName, "npcdrlist");
    		Debug.chat("After getting child");
    		Debug.chat(vDR);		
    		local aInfo = DB.getChild(sPCNodeName, "npcdrlist").getWindowCount();
    		Debug.chat(aInfo);
    	end
    end
    getWindowCount can only be used against a GUI windowlist control: https://fantasygroundsunity.atlassia...getWindowCount

    As your code is working against the database, you can't use GUI based API calls, but you could use getChildCount to see how many children npcdrlist has: https://fantasygroundsunity.atlassia...#getChildCount But, as Moon Wizard mentions, you should have code that ensures the databasenode you're using getChildCount against exists, otherwise you'll get an error. You could do something like this:

    Code:
    local nodeNPCDRList = DB.getChild(sPCNodeName, "npcdrlist");
    if nodeNPCDRList then
    	local nListCount = nodeNPCDRList.getChildCount();
    end
    Last edited by Trenloe; September 22nd, 2021 at 16:00.
    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!

  7. #7
    Ah ok, makes sense now. I knew it was something I was doing wrong. Thanks both of you for the help. Will make this thing move along much easier I think.

Thread Information

Users Browsing this Thread

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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
STAR TREK 2d20

Log in

Log in