-
February 27th, 2019, 15:06 #1
Creating, Cloning, or Writing a Class for dragdata
Has anyone had any success with creating a dragdata object from scratch?
I need one inside a double-click event handler. Some controls in the character sheet have both drag and click functionality, that pretty much end with the same result. It appears as though much of my work would be done if I could populate a dragdata object inside the click handler and send it on its way.
But I have not found any way to create a blank or empty dragdata object. LilCthulhu asked this same question back in 2010, and Moon Wizard sent him to throwDice(). I started going down that rabbit hole and it's scary down there.
I also tried draginfo.createBaseData("dragdata"). This seems to be a "cloner". You need an original to clone from, and there is no persistence. When the original dies, the clone dies (becomes empty or non functional).
So, two questions:
(1) After eight years (LilCthulhu's question) can we still not instantiate a fresh dragdata object?
(2) If I write my own class (lua table) with embedded functions and variables that mocks the dragdata object, your opinions on how successful it might be when I send it into the maze of onDragStart/onDrag but originating in onDoubleClick?
Thanks, in advance for your help, opinions, chides and gaffaws .Current Projects:
Always...
Community Contributions:
Extensions: Bardic Inspiration, Druid Wild Shapes, Local Dice Tower, Library Field Filters
Tutorial Blog Series: "A Neophyte Tackles (coding) the FG Extension".
-
February 27th, 2019, 15:20 #2
This is from my DOR Deadlands Classic Ruleset and deals with a "Fate Chip" construct that gets Dragged and Dropped to and from a number of locations.
Code:oDragData.createBaseData("fatechip"); oDragData.setType("fatechip"); oDragData.setIcon("iPokerChip" .. sChip); oDragData.setDescription(sChip); oDragData.setNumberData(1);
Dulux-Oz
√(-1) 2^3 Σ Π
...And it was Delicious!
Alpha-Geek
ICT Professional
GMing Since 1982
NSW, Australia, UTC +10
LinkedIn Profile: www.linkedin.com/in/mjblack
Watch our games on Twitch: www.twitch.tv/dulux_oz
Support Me on Patreon: www.patreon.com/duluxoz
Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz
-
February 27th, 2019, 17:12 #3
Thank you dulux-oz.
Interesting. I suspect this rectifies the persistence problem I had. But isn’t oDragData in the code above a dragdata object itself? Meaning I have to have one to create one? Otherwise, if I understand correctly, it would not have the embedded createBaseData() function.
-
February 27th, 2019, 17:29 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,559
You can not create a dragdata object from scratch. The createBaseData API creates a child dragdata object, but requires a dragdata object to create.
Regards,
JPG
-
February 27th, 2019, 22:19 #5
-
March 7th, 2019, 13:28 #6
-
March 7th, 2019, 15:14 #7
It is much more complicated than that.
The dragdata “table” is very much like a class in other languages. It has get and set functions embedded. So code down the line does a
draginfo.setDescription(blah);
rather than a simple
draginfo.desc = blah;
I wil have to add all those property getters and setters to my pseudo-dragdata “object”.
I tried what you suggest, create a dragdata table put in my data, and sent it on its way. It didn’t make it very far before an error was thrown complaining of such-and-such “get” function was nil.Last edited by Minty23185Fresh; March 7th, 2019 at 15:20.
-
March 7th, 2019, 19:52 #8
Riiiight... the “duck” principle.
Since the “typing” in Lua is quite coarse, and tables are their “classes”, you could in theory actually recreate a DragInfo class/instance if you implemented it completely, maybe? I’m too ignorant. However as an opaque object it is u likely you’d get enough of it done and done right, in effect Lua would just give you enough rope to shoot yourself in the foot with
If I needed it, Id quickly copy and
-
March 7th, 2019, 20:28 #9
Agreed. I alluded to this in my (unanswered) second question, in the original post.
I think I know where you were headed with this. If I’ve guessed correctly, I also mentioned copying (or cloning) an original and lack of persistence.
Thanks for the input.
I like a good challenge and plan on giving this a go here in the near future. Working on DWSI at the moment though.
-
March 9th, 2019, 17:54 #10
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks