Thread: LUA Help
-
August 26th, 2019, 18:00 #1
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
LUA Help
Hi,
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:
Code:function onDrop(x,y,draginfo) if draginfo.isType("shortcut") then local nodeWin = window.getDatabaseNode(); Debug.chat("nodeWin: "); Debug.chat(nodeWin); local nodeItem = nodeWin.getChild("...."); Debug.chat("nodeItem: "); Debug.chat(nodeItem); local nDamage = DB.getValue(nodeItem, "damagerating", 0); Debug.chat("nDamage"); Debug.chat(nDamage); local nDisc = DB.getValue(nodeWin, "discipline.security", 0); Debug.chat("nDisc"); Debug.chat(nDisc); nDamage = nDamage + nDisc; Debug.chat("nDamage"); Debug.chat(nDamage); local class, datasource = draginfo.getShortcutData(); Debug.chat("class"); Debug.chat(class); if class == "referencetext" or class == "item" then local newentry = createWindow() Debug.chat("newentry"); Debug.chat(newentry); newentry.name.setValue(draginfo.getDatabaseNode().getChild("name").getValue()); newentry.size.setValue(draginfo.getDatabaseNode().getChild("size").getValue()); newentry.damage.setValue(draginfo.getDatabaseNode().getChild("damagerating").getValue()); end return true; end end
Thanks.Last edited by statik37; August 26th, 2019 at 18:02.
-
August 26th, 2019, 22:28 #2
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,426
What's the output from your debug statements? If nodeItem is nil, that probably means that the relative path "...." isn't valid.
Regards,
JPG
-
August 26th, 2019, 23:37 #3
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
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?
-
August 26th, 2019, 23:48 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,426
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 Debug.chat; you can just hit the Copy To Clipboard menu to quickly copy all the output.
Regards,
JPG
-
August 26th, 2019, 23:52 #5
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
-
August 27th, 2019, 03:11 #6
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,426
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++)
Regards,
JPG
-
August 27th, 2019, 15:26 #7
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
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.
-
August 27th, 2019, 19:50 #8
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
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();
Debug.chat("nodeWin:");
Debug.chat(nodeWin);
local nAttribute = nodeWin.createChild("attrib");
Debug.chat("nAttribute:");
Debug.chat(nAttribute);
local attrib = DB.getValue(nodeWin, nAttrib, 0);
Debug.chat("attrib:");
Debug.chat(attrib);
return true;
end
function discipSelect(winFrame, nDiscip)
local nodeWin = winFrame.getDatabaseNode();
Debug.chat("nodeWin:");
Debug.chat(nodeWin);
local nDiscipline = nodeWin.createChild("discip");
Debug.chat("nDiscipline:");
Debug.chat(nDiscipline);
local discip = DB.getValue(nodeWin, nDiscip, 0);
Debug.chat("discip:");
Debug.chat(discip);
return true;
end
function targetNumber(winFrame, attrib, discip)
local nodeWin = winFrame.getDatabaseNode();
Debug.chat("nodeWin:");
Debug.chat(nodeWin);
local att = nodeWin.getValue(nodeWin, attrib, 0);
local dis = nodeWin.getValue(nodeWin, discip, 0);
local TN = att + dis;
Debug.chat("TN:");
Debug.chat(TN);
DB.setValue(nodeWin, "rollable.targetroll", "number", TN);
end
-
August 27th, 2019, 19:57 #9
- Join Date
- Dec 2015
- Location
- Boston, MA
- Posts
- 167
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>
-
August 27th, 2019, 20:19 #10
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,426
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.
Regards,
JPG
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks