Thread: Back again with another question
-
September 22nd, 2021, 02:20 #1
- Join Date
- Jun 2017
- Posts
- 61
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 }
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.
-
September 22nd, 2021, 02:25 #2
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!
-
September 22nd, 2021, 02:31 #3
- Join Date
- Jun 2017
- Posts
- 61
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
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
-
September 22nd, 2021, 13:48 #4
- Join Date
- Jun 2017
- Posts
- 61
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.
-
September 22nd, 2021, 15:43 #5
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,561
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
-
September 22nd, 2021, 15:56 #6
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
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!
-
September 22nd, 2021, 17:12 #7
- Join Date
- Jun 2017
- Posts
- 61
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