DICE PACKS BUNDLE
Page 1 of 2 12 Last
  1. #1

    attempt to call global getDatabaseNode (a nil value)

    I have an extension that modifies campaign/scripts/spell.lua from 3.5E.

    I have this windowclass merge:
    Code:
    	<windowclass name="spell_item" merge="join">
    		<script file="campaign/scripts/spell.lua" />
    	</windowclass>
    and in my spell.lua file I have only:
    Code:
    function onMenuSelection(selection, subselection)
    	if selection == 6 and subselection == 7 then
    		getDatabaseNode().delete();
    	elseif selection == 4 then
    		SpellManager.parseSpell(getDatabaseNode());
    		-- bmos removing this line to keep script error away
    		-- activatedetail.setValue(1);
    	elseif selection == 3 then
    		if subselection == 2 then
    			createAction("cast");
    			activatedetail.setValue(1);
    		elseif subselection == 3 then
    			createAction("damage");
    			activatedetail.setValue(1);
    		elseif subselection == 4 then
    			createAction("heal");
    			activatedetail.setValue(1);
    		elseif subselection == 5 then
    			createAction("effect");
    			activatedetail.setValue(1);
    		end
    	end
    end
    but on some NPCs I get a bunch of script errors when I open their spell lists:
    Code:
    Script execution error: [string "campaign/scripts/spell.lua"]:54: attempt to call global 'getDatabaseNode' (a nil value)
    As you can see, there is not getDatabaseNode function being called at a 54th line, so this is coming from the original file for some reason.

    Why would this global function be missing?

    Thanks for your time looking at this.

  2. #2
    Did you try window.getDatabaseNode?
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

  3. #3
    Quote Originally Posted by SilentRuin View Post
    Did you try window.getDatabaseNode?
    I don't have anywhere to change that to window.getDatabaseNode().
    It's an error coming from a function that I haven't changed (onDisplayChanged in 3.5E's spell.lua)
    I have tried adding that function to my spell.lua and commenting out everything in it (leaving the function empty) and it still has the same error!

    Specifically this is my Upgrade NPC Actions extension and I'm testing this error by opening Demon, Nalfeshnee from an official Bestiary.
    I have changed parseSpell to replace the spell entry (which means that the id-XXXXXX node changes) with one from a module when re-parsing the spell.
    I get why getDatabaseNode() might return bad info, but I don't understand is why the global function would be missing completely.
    I was hoping I could just empty the onDisplayChanged function since I don't care about its functionality, but for some reason that doesn't even fix the issue as my merged function isn't overriding the one in the ruleset.
    Last edited by bmos; May 16th, 2021 at 15:01.

  4. #4
    Quote Originally Posted by bmos View Post
    I don't have anywhere to change that to window.getDatabaseNode().
    It's an error coming from a function that I haven't changed (onDisplayChanged in 3.5E's spell.lua)

    I have tried adding that function to my spell.lua and commenting out everything in it (leaving the function empty) and it still has the same error!
    Not sure what you mean in this answer. Sometimes things do not set that function and you have to call it off window. You saying you don’t have any place to try that confused me. If your menu function is calling it now adding window in front of it is where you would “call it”. It may not work - but it’s worth a try was all I was saying. But if it worked before as you have it in same circumstances (nothing has changed) not sure what would cause that.
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

  5. #5
    Quote Originally Posted by SilentRuin View Post
    Not sure what you mean in this answer. Sometimes things do not set that function and you have to call it off window. You saying you don’t have any place to try that confused me. If your menu function is calling it now adding window in front of it is where you would “call it”. It may not work - but it’s worth a try was all I was saying. But if it worked before as you have it in same circumstances (nothing has changed) not sure what would cause that.
    The script error is coming from spell.lua's line 54 which is in the function onDisplayChanged().
    I have not touched onDisplayChanged() so I have nowhere to change getDatabaseNode() to window.getDatabaseNode().

    When I did try to replace onDisplayChanged() in my merged copy of spell.lua, it ignored my changes.

  6. #6
    Quote Originally Posted by bmos View Post
    The script error is coming from spell.lua's line 54 which is in the function onDisplayChanged().
    I have not touched onDisplayChanged() so I have nowhere to change getDatabaseNode() to window.getDatabaseNode().

    When I did try to replace onDisplayChanged() in my merged copy of spell.lua, it ignored my changes.
    Is it possible its being triggered by a place other than normal somehow? For sure in 5E onDisplayChanged() only present in power_item.lua and power_page.lua (which work fine). But if yours in spell.lua? is somehow triggered during the OnInit cycle it may not be defined yet or something (seen that in other functions). In which case, you just check for nil and skip the call till it works. In other words, its a false error from startup maybe? As I only deal in 5E maybe something I've never seen is going on for you also. Sorry, that's the best I know on advice for this sort of thing which I've had to workaround for other functions in the past (usually involving delete node timing issues).
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

  7. #7
    To my knowledge you cannot merge windowclasses like that; you need to overwrite the full script and not just the part you edit (however, one could try super maybe for more compatibility.) (and I now did not read the full conversation here; sorry, if already discussed and mentioned )

  8. #8
    Quote Originally Posted by Kelrugem View Post
    To my knowledge you cannot merge windowclasses like that; you need to overwrite the full script and not just the part you edit (however, one could try super maybe for more compatibility.) (and I now did not read the full conversation here; sorry, if already discussed and mentioned )
    I assumed that was just a snippet. But if not - then Kelrugem is stating you need to do all the functions even if you don't use them (not sure that is a requirement but I always do it)...

    For example...
    Code:
    function onInit()
    	if super and super.onInit then
    		super.onInit();
    	end
    end
    
    function onSummaryChanged()
    	if super and super.onSummaryChanged then
    		super.onSummaryChanged();
    	end
    end
    
    function updateControl(sControl, bReadOnly, bForceHide)
    	if super and super.updateControl then
    		super.updateControl(sControl, bReadOnly, bForceHide);
    	end
    end
    
    function update()
    	if super and super.update then
    		super.update();
    	end
    end
    
    function addTrait(sName, sDesc)
    	if super and super.addTrait then
    		super.addTrait(sName, sDesc);
    	end
    end
    ...
    But it gets even trickier. If something is actually triggered from one of these super calls and it calls something that you have actually replaced in the same file - then you will need to replace the super call to directly call your replacement else it will end up calling the super version (not yours). I've run into that also when dealing with a function when it is being called in the same .lua overridden file.
    Free(Forums/Forge) Extension(FGU 5E):
    Paid (Forge) Extension(FGU 5E):

  9. #9
    Quote Originally Posted by Kelrugem View Post
    To my knowledge you cannot merge windowclasses like that; you need to overwrite the full script and not just the part you edit (however, one could try super maybe for more compatibility.) (and I now did not read the full conversation here; sorry, if already discussed and mentioned )
    I've done so in the past without any obvious issues, but maybe I was breaking things without knowing it.

    Quote Originally Posted by SilentRuin View Post
    I assumed that was just a snippet. But if not - then Kelrugem is stating you need to do all the functions even if you don't use them (not sure that is a requirement but I always do it)...

    For example...
    Code:
    function onInit()
    	if super and super.onInit then
    		super.onInit();
    	end
    end
    
    function onSummaryChanged()
    	if super and super.onSummaryChanged then
    		super.onSummaryChanged();
    	end
    end
    
    function updateControl(sControl, bReadOnly, bForceHide)
    	if super and super.updateControl then
    		super.updateControl(sControl, bReadOnly, bForceHide);
    	end
    end
    
    function update()
    	if super and super.update then
    		super.update();
    	end
    end
    
    function addTrait(sName, sDesc)
    	if super and super.addTrait then
    		super.addTrait(sName, sDesc);
    	end
    end
    ...
    But it gets even trickier. If something is actually triggered from one of these super calls and it calls something that you have actually replaced in the same file - then you will need to replace the super call to directly call your replacement else it will end up calling the super version (not yours). I've run into that also when dealing with a function when it is being called in the same .lua overridden file.
    Hopefully this will solve the issue.
    Last edited by bmos; May 17th, 2021 at 18:01.

  10. #10
    Nope, same error.
    I made my spell.lua file like this:
    Code:
    -- 
    -- Please see the LICENSE.md file included with this distribution for 
    -- attribution and copyright information.
    --
    
    local bShow = super.bShow or true;
    
    function setFilter(bFilter)
    	bShow = bFilter;
    end
    
    function getFilter()
    	return bShow;
    end
    
    function onInit()
    	-- trigger original function
    	if super and super.onInit then
    		super.onInit()
    	end
    end
    
    function update(bEditMode)
    	if minisheet or super.minisheet then
    		return;
    	end
    	
    	-- trigger original function
    	if super and super.update then
    		super.update(bEditMode)
    	end
    end
    
    function onDisplayChanged()
    	if minisheet or super.minisheet then
    		return;
    	end
    
    	-- trigger original function
    	if super and super.onDisplayChanged then
    		super.onDisplayChanged()
    	end
    end
    
    function onHover(bOver)
    	-- trigger original function
    	if super and super.onHover then
    		super.onHover(bOver)
    	end
    end
    
    function createAction(sType)
    	-- trigger original function
    	if super and super.createAction then
    		super.createAction(sType)
    	end
    end
    
    function onMenuSelection(selection, subselection)
    	if selection == 6 and subselection == 7 then
    		getDatabaseNode().delete();
    	elseif selection == 4 then
    		SpellManager.parseSpell(getDatabaseNode());
    		-- bmos removing this line to keep script error away
    		-- activatedetail.setValue(1);
    	elseif selection == 3 then
    		if subselection == 2 then
    			createAction("cast");
    			activatedetail.setValue(1);
    		elseif subselection == 3 then
    			createAction("damage");
    			activatedetail.setValue(1);
    		elseif subselection == 4 then
    			createAction("heal");
    			activatedetail.setValue(1);
    		elseif subselection == 5 then
    			createAction("effect");
    			activatedetail.setValue(1);
    		end
    	end
    end
    
    function toggleDetail()
    	-- trigger original function
    	if super and super.toggleDetail then
    		super.toggleDetail()
    	end
    end
    
    function getDescription()
    	-- return output of original function
    	if super and super.getDescription then
    		return super.getDescription()
    	end
    end
    
    function activatePower()
    	-- trigger original function
    	if super and super.activatePower then
    		super.activatePower()
    	end
    end
    
    function usePower()
    	-- trigger original function
    	if super and super.usePower then
    		super.usePower()
    	end
    end
    so then I got rid of the merge="join" part in the xml file so it would overwrite the original script and just got a ton of errors about super not existing (which is really weird because I have it in an if statement so it not existing shouldn't even be an issue).
    Last edited by bmos; May 17th, 2021 at 18:02.

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
  •  
5E Character Create Playlist

Log in

Log in