PDA

View Full Version : Version compatibility issues with onDrag / onDragStart ?



cscase
July 15th, 2013, 08:58
Hey all,
I'm trying to make some tweaks to the CoC ruleset and I am running into some problems that I wonder if some of you have already encountered and resolved.

In a nutshell, I want to change the version in the base.xml to 2.9, but doing so creates some problems. I notice that, for one thing, items that drag, like the eye icons on the bottom of the module selection screen, didn't drag.

Alright, so I found that as of 2.8, onDragStart is triggered by drag events instead of onDrag. I found 51 instances of onDrag in the ruleset, but no instances of onDragStart. What I did - and this may be a mistake - was replace them all with the onDragStart. After that, some things were fixed, like I could drag the eyes, but after I drag an icon away, it just disappears from below where it normally would be put back after a drag, and the modules and reference material I select doesn't actually load. I'm scratching my head here.

Does this sound familiar to anyone? Can anyone point me in the right direction?
Thanks!!

Trenloe
July 15th, 2013, 13:51
Alright, so I found that as of 2.8, onDragStart is triggered by drag events instead of onDrag. I found 51 instances of onDrag in the ruleset, but no instances of onDragStart. What I did - and this may be a mistake - was replace them all with the onDragStart. After that, some things were fixed, like I could drag the eyes, but after I drag an icon away, it just disappears from below where it normally would be put back after a drag, and the modules and reference material I select doesn't actually load. I'm scratching my head here.

Does this sound familiar to anyone? Can anyone point me in the right direction?
Thanks!!
There are 51 instances of onDrag including onDragEnd, there are actually only 42 instances of onDrag itself - if you did a find and replace for onDrag with OnDragStart you will have changed any onDragEnd to onDragStartEnd and so broken those items.

Do a search for onDragStartEnd and put that back to onDragEnd and hopefully that will fix your issues. :)

cscase
July 15th, 2013, 15:12
Hahaha! How embarrassing! Seems I was a bit hasty there.

Thanks for not only solving my problem but also starting my day with a laugh, Trenloe. :p

cscase
July 16th, 2013, 17:42
A little follow-up info:
Changing the onDragStartEnds back to onDragEnd, as Trenloe suggested, fixed some of the problems I was seeing. Thanks again for catching that!

I also found and fixed another issue, which I'll mention here just in case anyone in the future runs into the same thing and is reading this post: With version # 2.9 in my base.xml, none of the things being loaded from modules were showing up. I could go in the module selection screen and select modules to load, but none of them showed up anywhere, i.e. in the story panel, maps or graphics, NPCs, items, library resources, etc. This turned out to be another version compatibility thing, and adding <useallmodules /> to the ruleset's windowlists for those things straightened that out.

So as of now, the only thing I can see that isn't quite right is that on the module screen, I can't load a module by dragging the little books open. Previously, if I wanted to load a module, I would click and drag on the little closed book icon by the module, and that would make it show as open, and the module would load. As of now, that doesn't work. Click on the book icon shows the "open book" icon, but only as long as I hold the mouse down. If I want the book to actually stay open, I have to double-click the thumbnail for the module, which does work. I'm not sure what the cause of that is and I'd like to fix it, if I've broken something else in changing the version, but ultimately, I guess it's not a huge deal. If anyone has any idea about this one, that'd be awesome, but if not, I still figured it'd be good to post these details for future forum-searchers.

Thanks!

saithan
July 17th, 2013, 00:29
add this function it will fix (pretty much all it needed)


function onDragStart(button, x, y, dragdata)
return onDrag(button, x, y, dragdata);
end

cscase
July 17th, 2013, 03:46
Hrm, so we are redefining onDragStart to work as though it were onDrag? Which file(s) does this need to be defined in? Thanks for your help!

edit:
Thinking about this some more and looking at the difference between onDragStart and onDrag, I see that the difference between the two is that onDragStart is only called once, when dragging begins, whereas onDrag is called continually while dragging. Did Smiteworks change the default way to be onDragStart for performance reasons? Like, I guess there's no need for a continually spamming event when you can use logic to deduce that if the drag hasn't ended or been handled yet, it must still be in progress. Does this make any sense?

So, I can either patch this to work as it used to with the function you gave me, or maybe I could re-code to use just the onDragStart instead? Or maybe just make it toggle the state of the book icon on a click. Dragging it open is a little annoying anyway, so maybe that would make more sense?

Anyway just mulling it over. Am I making any sense, or am I making incorrect deductions here?

Thanks again!!

Saith_mobile
July 17th, 2013, 03:56
Sory for the name change, out on the town. But I'm not familliar with coc but in the nwod I had to add that to moduleselect_enrtry.lua
In the gurps ruleset when 2.8 was released, I had to add that to all the files that used ondrag. Been fine since.

cscase
July 17th, 2013, 06:51
Thanks once again, Saith. This was a big help.

I am looking at this now and I think I understand what is going on a little better. It looks like this is coded so that the little book icons have not just a binary state - open or closed - but also two intermediary states, where it's half-opened or half-closed, before you release the mouse button. And in order to update that, it actually needs data mid-drag, to know where the mouse pointer is before you have released it, and for that, onDragStart is not sufficient. So, having onDragStart kick off onDrag, as in your function, is the way to go in this case. And that seems to work like a charm. Thanks much, Saith and Trenloe!

Seems like understanding how existing code works can be totally overwhelming if you try to look at the whole huge ruleset, but in cases where you can take it one little piece at a time, it gets a little more manageable.

Dakadin
July 17th, 2013, 07:09
Seems like understanding how existing code works can be totally overwhelming if you try to look at the whole huge ruleset, but in cases where you can take it one little piece at a time, it gets a little more manageable.

That is definitely the case. It is definitely easier if you focus on smaller more manageable things at first. Also as you found out, be sure to ask questions when you get stuck. There is usually someone willing and able to help out and you are likely to get a response fairly quickly. Have fun learning it. :D