Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 6:31 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Randomise levels
PostPosted: December 20th, 2004, 12:52 am 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
I've tried for what seems like hours to randomise the appearance of 9 objects named obj_1 through obj_9 so they appear on top of one another, but at randomised levels so each time the user visits the page, as the objects are dragged off one another they are in a different order.

I guess I'm possibly not thinking any straighter about the problem than I was some hours ago!

Any help would be appreciated.

John


For this message JMahoney has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: December 20th, 2004, 12:35 pm 
Offline

Joined: November 4th, 2004, 10:55 am
Posts: 5
Location: Digital Workshop
You need something like the following script:


Code:
var iNumObjects = 10;

var RandomArray = CreateRandomArray(iNumObjects );

for(var iIndex=1; iIndex<iNumObjects; iIndex++)
{
   var object = eval("obj_" + iIndex);
   object.SetLayer(RandomArray[iIndex]);
}

function CreateRandomArray(iSize)
{
   var SelectionArray = new Array;
   var RandomArray = new Array;
   
   for(var i=0; i<iSize; i++)
   {
      SelectionArray[i] = 1;
   }
   
   for(var i=0; i<iSize; i++)
   {
      while(true)
      {
         var iTest = Math.round(Math.random()*iSize);
         if(SelectionArray[iTest])
         {
            RandomArray[i]=iTest;
            SelectionArray[iTest]=0;
            break;
         }
      }
   }
   
   return RandomArray;
}


Hope this helps,

Damion Kelly

DW


For this message Damion Kelly has been thanked by : mackavi


Last edited by Damion Kelly on December 20th, 2004, 3:59 pm, edited 3 times in total.

Top
 Profile Visit website  
 
 Post subject:
PostPosted: December 20th, 2004, 3:40 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Hi Damion,

Many thanks.

I put the code in as a script object for the page, but it comes up with the error message - Unidentified identifier 'i' - putting the script 'On show' as a page action brings up error messages as well. Also, how do I progress further and set the stacked objects at 'shuffled' layers/levels?

Sorry to be so dim - but this isn't my forte - understatement of the year!

John


For this message JMahoney has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: December 20th, 2004, 3:57 pm 
Offline

Joined: November 4th, 2004, 10:55 am
Posts: 5
Location: Digital Workshop
Sorry, there was a typo in the original script, I have now edited it and it should work ok. This code will set the objects at random layers, the function call SetLayer achieves this.


For this message Damion Kelly has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: December 20th, 2004, 6:10 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Thanks Damion,

That works, but exhibits what seems, in use, to be strange behaviour.

Every time the page is reset the objects randomise in levels. But when I drag the top object from the pile of objects, it's not the top displayed object but one of those underneath it that is dragged! ?

It drags out the objects in the 'correct' order as though theeir layer order hadn't been shuffled - hope that makes sense!

John


For this message JMahoney has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: December 20th, 2004, 6:54 pm 
Offline

Joined: November 4th, 2004, 10:55 am
Posts: 5
Location: Digital Workshop
Ah, yes. I've unfortunately overlooked the fact that SetLayer only affects the 'graphical' side of things, whereas the drag drop relies on the 'real' order of things in the tree view, which hasn't changed.

There are two other alternatives that I can think of, one would be to duplicate the page a number of times, reorder the objects on each duplicate and then pick from one of these pages randomly. The other would be to write the drag drop manually, which would be more complicated.

The code for the first solution would be:

Code:
var iNumPages = 10;

function GotoRandomPage()
{
   var strPage = "Page " + (Math.round(Math.random()*iNumPages)+1);
   GotoPage(strPage);
}


You would need call the function GotoRandomPage() from the appropriate place and substitute the "Page " string.


For this message Damion Kelly has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: December 21st, 2004, 9:52 pm 
Offline

Joined: November 3rd, 2004, 4:52 pm
Posts: 99
Location: Worcester. UK
Many thanks for your help Damion.

Looks like I'll have go for the random pages.

It's a pity Opus cannot re-arange the levels as I wanted. I think the lack of a facility to 'shuffle' a pack of cards (objects) - even a just a dozen or so and allow them to be dragged to a new location, cuts out card games that could be a good basis for educational activities.

Anyway - thanks for pointing me in the direction I need to go.

John


For this message JMahoney has been thanked by : mackavi


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 56 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group