PDA

View Full Version : onDrop Issue



bradmcadam
August 4th, 2012, 22:23
So I'm trying to get my code to shortcut via a windowreferencecontrol back to the original data. I tried scripting some things but I got stuck at:


function onDrop(x, y, draginfo)
print("Drop started");

if draginfo.isType("shortcut") then

print("Drop entering");
local class datasource= draginfo.getShortcutData();
local source = draginfo.getDatabaseNode();

if source then

print("source");
window.setShortcutData(class, datasource);
return true;
end
end
end

Any ideas?

kairos
August 5th, 2012, 01:11
What behavior are you expecting and what is actually happening?

The draginfo parm for onDrop doesn't pass data into the function (other than type), but you can use the draginfo obj to pass data out of the function to be then used in the onDragEnd event on the drag source object. In other words, pass the reference to the window object as customdata then set the shortcut in onDragEnd.

bradmcadam
August 5th, 2012, 01:12
I guess I could try that, I was using onDrop since that's what all of the scripts use for 3.5E and 4E to get the same effect. Honestly, my problem has little to do with what the onDrop function is passing in and much more to do with I'm not quite sure how to assign it to the current window. The charsheet abilities script uses this:


function onDrop(x, y, draginfo)
if draginfo.isType("shortcut") then
if draginfo.getShortcutData() == "referencefeat" then
local nodeSource = draginfo.getDatabaseNode();

local win = addEntry(true);
if win then
win.value.setValue(DB.getValue(nodeSource, "name", ""));
win.shortcut.setValue(draginfo.getShortcutData());
end

end

return true;
end
end

but addEntry is a global variable I can't touch, so...

Moon Wizard
August 7th, 2012, 19:44
addEntry() is just a function that calls createWindow() and sets the focus to a specific field.

If you need a new record window for your data, just use the window object returned by addEntry(). If you don't need a new record window, just strip out all of that code and replace with what you want to do.

Regards,
JPG

bradmcadam
August 23rd, 2012, 16:47
So I think I tried to do what you suggested moon_wizard and used createWindow() instead of addEntry(). The only problem is, whenever I close my list of npcs and reopen it they have all disappeared. Any idea why it wouldn't be saving my new database nodes?


function onDrop(x, y, draginfo)
print("Drop started");
if draginfo.isType("shortcut") then
print("Drop entering");
if draginfo.getShortcutData() == "npc" then
local nodeSource = draginfo.getDatabaseNode();

local win = createWindow(nodeSource);

end
return true;
end
end