Page 1 of 3 123 Last

Thread: LUA Help

  1. #1

    LUA Help


    I am working on trying to add code to have my weapons window autofill some things for me. The code I have so far is:

    function onDrop(x,y,draginfo)
    	if draginfo.isType("shortcut") then
    	local nodeWin = window.getDatabaseNode();"nodeWin: ");;
    	local nodeItem = nodeWin.getChild("....");"nodeItem: ");;
    	local nDamage = DB.getValue(nodeItem, "damagerating", 0);"nDamage");;
    	local nDisc = DB.getValue(nodeWin, "", 0);"nDisc");;
    		nDamage = nDamage + nDisc;"nDamage");;
    	local class, datasource = draginfo.getShortcutData();"class");;
    	if class == "referencetext" or class == "item" then
    		local newentry = createWindow()"newentry");;"name").getValue());
    	return true;
    Everything seems to work, except nodeItem generates nil. What I want to do is have it point to the items field in the database instead of the character field. Because this isn't working, my nDamage is coming back as 0. I took what I have from 5e and a little kit bashing, but I can not figure out how to fix this. I don't know enough about LUA, and I feel this may be an easy fix.

    Last edited by statik37; August 26th, 2019 at 19:02.

  2. #2
    What's the output from your debug statements? If nodeItem is nil, that probably means that the relative path "...." isn't valid.


  3. #3
    The output is nil. Basically, as it is, when I access the database, I am accessing the charsheet info. I want to use that statement to transfer and grab from the Items section of the database. How do i do that?

  4. #4
    I meant the output from all of your debug statements. For example, nodeItem depends on nodeWin, so there’s no way to tell if “....” is valid relative path without knowing what nodeWin is.

    If you use Debug.console instead of; you can just hit the Copy To Clipboard menu to quickly copy all the output.


  5. #5

  6. #6
    It looks like nodeWin is essentially the root character node that is only two levels deep; so “....” is not a valid relative path (which means to go up the data tree three levels). That explains why it’s returning nil.

    Try looking at getShortcutData, instead of getDatabaseNode. Dragging an item stores quite a bit of data in different places in the drag object; but each drag slot can contain a link.

    If that doesn’t work, you might want to go back and look at some of the CoreRPG code that handles onDrop with links to see examples. Make sure to use a good text editor with multiple file search capability. (I use Notepad++)


  7. #7
    Thank you, that was a great help.

    Instead of having:

    local nodeItem = nodeWin.getChild("....");

    I did:

    local nodeItem = draginfo.getDatabaseNode();

    And that seems to have fixed my issue. Thank you for your insight.

  8. #8
    OK, I have another question.

    I have a row of Attributes and a row of Disciplines. I have it set now, that when I click one attribute, it updates a DB field:

    function attribSelect(winFrame, nAttrib)
    local nodeWin = winFrame.getDatabaseNode();"nodeWin:");;
    local nAttribute = nodeWin.createChild("attrib");"nAttribute:");;
    local attrib = DB.getValue(nodeWin, nAttrib, 0);"attrib:");;
    return true;
    And the same thing for the disciplines.

    function discipSelect(winFrame, nDiscip)
    local nodeWin = winFrame.getDatabaseNode();"nodeWin:");;
    local nDiscipline = nodeWin.createChild("discip");"nDiscipline:");;
    local discip = DB.getValue(nodeWin, nDiscip, 0);"discip:");;
    return true;
    What I would like to do now is whenever either function value changes, I want to add the two of them together together and pass them into a third field. For that I wrote this:

    function targetNumber(winFrame, attrib, discip)
    local nodeWin = winFrame.getDatabaseNode();"nodeWin:");;
    local att = nodeWin.getValue(nodeWin, attrib, 0);
    local dis = nodeWin.getValue(nodeWin, discip, 0);
    local TN = att + dis;"TN:");;
    DB.setValue(nodeWin, "rollable.targetroll", "number", TN);
    Now, I don't know if I am even close to doing that right. Or how to then get the values from the two other functions into this function. I don't know if I need the second winNode command, or if it's just redundant.

  9. #9
    I just realized now looking at that, it is actually not doing what I was hoping. The createChild makes a new DB category, but doesn't pass the number. And I was just passing the value, without loading it into the database.

    Is there any insight on how to create a DB entry since createChild didn't work?

    basically I want to create a field that says something like

    <attrib type="number">12</attrib>

  10. #10
    Look at DB.setValue as a better way to do that.

    You can also pass additional parameters into createChild to set a data type for the node.


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