Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 23rd, 2024, 8:46 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Drag and Drop - Original Position
PostPosted: October 10th, 2007, 9:33 pm 
Offline

Joined: December 25th, 2004, 3:31 pm
Posts: 178
Making a drag and drop puzzle, want drag pieces to be located randomly and then drop to quiz. The random part is working using this code with r being placed in an array:

Code:
var r = Math.ceil(Math.random() * TotNumber);
while (choosenNumbers[r])
   {
   r = Math.ceil(Math.random() * TotNumber);
   }
   choosenNumbers[r] = true;

return r;


Any suggestions for a better random number generator welcomed.

The problem I am having is the return location, I use SetPosition(GetXLocation, GetYLocation) to set to a random location. But if the object is dragged unsuccessfully and I have Return to original position if not dropper it will return, not to the random location but to it's original location.

I have tried the dropped triggers but there is not trigger for object dropped anywhere. The only triggers that I thought might work do not, the Object Dropped trigger is for correct drop only. This Object Dropped is again only for correct drop as above and Drop Refused is only if the object is dropped in the wrong location.

There is no action for Object Dragged, this would basically do an action once the user has finished dragging and just dropped the object anywhere on the page.


Top
 Profile  
 
 Post subject:
PostPosted: October 10th, 2007, 10:12 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi Joseph,

You need to use the IsIntersecting command to check whether the dropped object is in the correct place. You can then use SetPosition to return incorrectly dropped objects bypassing the D&D functions altogther.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: October 11th, 2007, 12:06 am 
Offline

Joined: December 25th, 2004, 3:31 pm
Posts: 178
Hi Mack,

I never noticed that function before, excellent will have to try it out. Is there any tutorials on using the IsObjectIntersecting() function?

It appears to only return true or false, it would be great if there was also a tolerance return, if the percentage of objects intersecting was shown. Would enable a threshold, so if greater than 60% drop, else error.

Thanks for the suggestion, I will look into it. The D&D can be limiting, especially if there are a lot of objects involved!


Top
 Profile  
 
 Post subject:
PostPosted: October 11th, 2007, 12:43 am 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
attached is a slightly modified drag and drop publication I did for BillyBob.
viewtopic.php?t=2914

basically it was to show how drag and drop can be done in scripting (using IsObjectIntersecting). If you drag the cat/cow to the pub/field, it only allows one correct answer --cow in pub and cat in field. You drag the animals then hit the test button. If the answer is not correct, it returns the incorrect placed animal to the original position.

In the new version, I have added a hotspot which covers the whole page and an action/script attached... if a draggable object is dropped on to the hotspot, but not in the drop zone, it simply gets the position of the cat and cow, this effectively stores the new position of the animal and it is this position it is returned to when incorrectly dropped.


I think it works as you want....if I understand you correctly.


You do not have the required permissions to view the files attached to this post.

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: October 11th, 2007, 1:09 am 
Offline

Joined: December 25th, 2004, 3:31 pm
Posts: 178
Thanks will have a look.

I did further Google search on a javascript random non repeating number generator and I found a much better solution. Create an array of numbers and then just shuffle.

Code:
function fisherYates(myArray)
{
   var i = myArray.length;

   if ( i == 0 ) return false;

   while ( --i )
   {
        var j = Math.floor( Math.random() * ( i + 1 ) );
        var tempi = myArray[i];
        var tempj = myArray[j];
        myArray[i] = tempj;
        myArray[j] = tempi;
   }
}


This is the Fisher-Yates randomizing shuffle algorithm taken from http://sedition.com/perl/javascript-fy.html

Works great and much quicker then the way I was doing the playlist.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 37 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group