Page 3 of 3 First 123

Thread: LUA Help

  1. #21
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    18,878
    Blog Entries
    1
    Mooooaaaarrrr MoreCore!

    MoreCore - Generic Ruleset
    --- Projects ---
    Extensions | Tutorials | MoreCore | MoreCore Themes | Call of Cthulhu | Maelstrom | FG Con

  2. #22
    I have another question. I am trying to set up certain windows on my items screen to lock when I hit the lock icon. This is the code I have so far:

    Code:
    function onInit()
    	update();
    end
    
    function VisDataCleared()
    	update();
    end
    
    function InvisDataAdded()
    	update();
    end
    
    function updateControl(sControl, bReadOnly)
    	if not self[sControl] then
    		return false;
    	end
    		
    	return self[sControl].update(bReadOnly);
    end
    
    function update()
    	local nodeRecord = getDatabaseNode();
    	local bReadOnly = WindowManager.getReadOnlyState(nodeRecord);
    	
    	local bWeapon = ItemManager2.isWeapon(nodeRecord);
    	local bArmor = ItemManager2.isArmor(nodeRecord);
    		
    	local bSection1 = false;
    	if updateControl("type", bReadOnly) then bSection1 = true; end
    	if updateControl("range", bReadOnly) then bSection1 = true; end
    
    	local bSection2 = false;
    --	if updateControl("damagerating", bReadOnly) then bSection2 = true; end
    --	if updateControl("resistance", bReadOnly) then bSection2 = true; end
    	if updateControl("effect", bReadOnly) then bSection2 = true; end
    
    	local bSection3 = false;
    	if updateControl("size", bReadOnly) then bSection3 = true; end
    	if updateControl("qualities", bReadOnly) then bSection3 = true; end
    	if updateControl("cost", bReadOnly) then bSection3 = true; end
    
    	local bSection4 = true
    	notes.setReadOnly(bReadOnly);
    		
    	divider.setVisible(bSection1 and bSection2);
    	divider2.setVisible((bSection1 or bSection2) and bSection3);
    	divider3.setVisible((bSection1 or bSection2 or bSection3) and bSection4);
    end
    I took it from 5E and made some adjustments. As it sits now, it works with no problem, but the two commented out fields do not lock. If I uncomments then, I get the error:

    attempt to call field 'update' (a nil value)
    The difference between those fields and the others are those two are number fields and everything else is a string field. However, when I look at the code in 5E, they have this on numbers and strings, and it works fine. The only big difference was I got rid of the bID bit, because I don't want to have non-ID settings.

  3. #23
    What template are you using to implement those fields?

    The scripts associated with those templates must have an update function, which is the error reporting when you uncomment.

    There are some templates in CoreRPG that implement those functions for strings and numbers already that you can reuse. If you’re making a custom field, you’ll need to implement your own script for those fields.

    Make sure to use a multi-file text search with a good text editor to track back the templates to see what is being inherited.

    Regards,
    JPG

  4. #24
    I was able to fix it. Upon looking back at the code I borrowed from, I realized I was using the wrong template for the number fields. I was off by one letter. Once I fixed that, it was all set.

  5. #25
    You all have been so helpful.

    Code:
    function rankchange(draginfo, winFrame)
    
    	local nodeWin = winFrame.getDatabaseNode();
    	local curRank = DB.getValue(nodeWin, "rank");
    	DB.setValue(nodeWin, "reputation.rank", "string", curRank);
    	DB.setValue(nodeWin, "reputation.reputation", "number", 10);
    	
    	if DB.getValue(nodeWin, "reputation.rank") == "Ensign" then
    		nodeWin.getChild("reputation.privilege").setValue(1);
    		nodeWin.getChild("reputation.responsibility").setValue(20);
    	elseif DB.getValue(nodeWin, "reputation.rank") == "Lieutenant JG" then
    		nodeWin.getChild("reputation.privilege").setValue(1);
    		nodeWin.getChild("reputation.responsibility").setValue(20);
    	elseif DB.getValue(nodeWin, "reputation.rank") == "Lieutenant" then
    		nodeWin.getChild("reputation.privilege").setValue(2);
    		nodeWin.getChild("reputation.responsibility").setValue(19);
    	elseif DB.getValue(nodeWin, "reputation.rank") == "Lieutenant Commander" then
    		nodeWin.getChild("reputation.privilege").setValue(2);
    		nodeWin.getChild("reputation.responsibility").setValue(19);
    	elseif DB.getValue(nodeWin, "reputation.rank") == "Commander" then
    		nodeWin.getChild("reputation.privilege").setValue(3);
    		nodeWin.getChild("reputation.responsibility").setValue(18);
    	elseif DB.getValue(nodeWin, "reputation.rank") == "Captain" then
    		nodeWin.getChild("reputation.privilege").setValue(4);
    		nodeWin.getChild("reputation.responsibility").setValue(17);
    	else
    		nodeWin.getChild("reputation.privilege").setValue(1);
    		nodeWin.getChild("reputation.responsibility").setValue(20);
    
    	end
    
    		
    end
    This is in the LUA file. As it stands, when I open the character sheet and I go to Attributes I have a number default for these fields. After visiting the Attributes, when I run through the cycler to activate this code, it works perfectly fine. However, if I create a new character, and do not go to the Attributes page, once I start cycling, I get an error saying setChild is a nul value. I assume it's because the field has yet to be created in the DB. How can I change the code to have it create the DB fields if it's not been created yet?

  6. #26
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,623
    Quote Originally Posted by statik37 View Post
    How can I change the code to have it create the DB fields if it's not been created yet?
    Use <dbnode>.createChild - https://www.fantasygrounds.com/refdo...cp#createChild

    FG Con 15 Fantasy Grounds Online RPG Convention - Nov. 8-10, 2019
    Register at www.fg-con.com for all the latest info.

    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!

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