Have drop zone accept only one element out of several correct ones

papi Jo's picture

Hi,

I've recently been confronted with the following situation, which has currently no solution in the Drag & Drop activity.

In a certain drop zone DZ0 I need to accept as correct one out of two draggable elements, E1 and E2.

If I set that drop zone to "This drop zone can only contain one element", I can drag either E1 or E2 into that zone, not more than one, of course. But then, the total score for the activity expects 2 elements to be dragged into drop zone DZ0. When only one element has been dragged, it's impossible to achieve a full correct score.

I would like the score for that kind of drop zone to count for 1 point only, not 2.

I hope this makes sense.

Content types: 
0
0
Supporter votes Members of the Supporter Network can vote for feature requests. When the supporter network has generated sufficient funding for the top voted feature request it will normally be implemented and released. More about the H5P Supporter Network
otacke's picture

Hi Papi Jo!

I agree. I don't think there's any case where you'd want to create such an impossible task - if a dropzone just accepts one item, then the maximum score for that dropzone should be 1 regardless of the number of draggables that might be correct.

Likewise, if a draggable would be correct in multiple drop zones, but the draggable is not set to have an infinite number of element instances, the content type should not expect it to be placed multiple times. This case is actually covered, currently, but a fix should not break this scenario.

I created a branch with a patch at https://github.com/otacke/h5p-drag-question/tree/fix-max-score. I think it should cover all cases and compute the maximum score correctly all the time - thus guaranteeing that full score can always be achived. Feel free to give it a test run with different combinations of dropzone settings and draggable settings.

Cheers,
Oliver

papi Jo's picture

Hi Oliver,

Thanks for your prompt reply to my feature request. I will test your PR and report.

papi Jo's picture

Hi Oliver!

Just tested your fix. It works OK for Case #1: "if a dropzone just accepts one item, then the maximum score for that dropzone should be 1 regardless of the number of draggables that might be correct."

But I'm afraid your fix breaks Case #2 " if a draggable would be correct in multiple drop zones, but the draggable is not set to have an infinite number of element instances, the content type should not expect it to be placed multiple times."

otacke's picture

Hi Papi Jo!

It shouldn't break #2 and doesn't break here, but maybe I didn't think of some edge case. What's your exact config?

Cheers,
Oliver

papi Jo's picture

@Oliver,

Upon further testing, it seems your fix does work for either case #1 or case #2, as long as we don't have those 2 cases in one D & D content at the same time. Hope that makes sense, and it's quite acceptable to me.

otacke's picture

Hi Papi Jo!

That may have been okay, but your comment made me find some other problem: I mistook the meaning of one of the properties - it was not the dropzones that an element was correct in, but the dropzones the element could be dragged to. That could lead to trouble if you had an element that was not correct anywhere.

Fixed that now. Would be cool if you gave that new version another look. If you encounter any scenario that leaves you with a maximum score that cannot be achieved, please let me know that scenario so I can take another look.

Best,
Oliver

papi Jo's picture

Hi Oliver,

Still conflict if both cases occur in one content. See attached screenshot and content file.

H5P file: 
otacke's picture

Hi Papi Jo!

Aaah, get it. I'll fix that as well. Thanks!

Cheers,
Oliver

otacke's picture

Hey, Papi Jo!

Thanks again for helping out. The problem was that you could have a certain number of dropzones that only accept one element, but you could have more than that elements that are only correct on those "single dropzones". In your example that were "dz01", "el1" and "el2". Either "el1" or "el2" cannot be placed anywhere, but I had not figured that in before.

Can I challenge you to find a setting that doesn't work once more? :-D

Cheers,
Oliver

papi Jo's picture

Hi Oliver,

I think you've finally managed to fix this. Well-done! If I find a borderline case which does not work I'll let you know.

Bravo!

otacke's picture

Perfect!

Let"s do this again some other time to fix more things :-)

Will create a pull request tomorrow.

Best,

Oliver 

otacke's picture

For documentation: The pull request can be found at https://github.com/h5p/h5p-drag-question/pull/116. It also fixes https://h5ptechnology.atlassian.net/browse/HFP-2444, so hopefully it will be dealt with at some point.

papi Jo's picture

The saga continues...

Oliver, your recent fix throws an error in the case that there is (at least) one draggable which is not accepted as correct in any dropzone. In the attached screenshot Russia is not accepted as correct in any of the 2 dropzones. When clicking Check button, the Canada draggable is marked as correct, the Russia draggable is marked as incorrect, but there is no display of the Score at the bottom, and the console throws the following error message Uncaught TypeError: that.correctDZs[index] is undefined (etc.).

I am attaching the sample H5P file.

H5P file: 
otacke's picture

At Papi Jo!

Are you running the code from the pull request?

Best,
Oliver

papi Jo's picture

No, I was still using the fix on your own github. Will now try the PR on the H5P site at https://github.com/h5p/h5p-drag-question/pull/116 and will report here.

papi Jo's picture

Ah, that was it. Using the code form the PR on the H5P github fixes my problem posted on Wed, 06/30/2021 - 16:50.

Good work, Oliver!