Digital Workshop

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Merge and alternate 2 arrays into single array
PostPosted: July 25th, 2012, 5:29 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi,

I've been searching online, without success, to find a way to merge and alternate elements from 2 arrays into a third merged array.

The current script (adapted from an IMP on this forum: viewtopic.php?f=4&t=2744&hilit=simon+says) which has been changed to create one array for 1-6, needs to be modified to create 2 arrays (1-3 and 4-6):

current script
Code:
function separate()
   {
      

      for(i=1;i<=listamount;i++)
         {
         //create 6 random numbers from 1-6
         temp = Math.round(Math.random()*(6))
         if (temp == 0){temp = 1}
         if (temp == 7){temp = 6}
         
            randomset[i] = temp
         }         
      
   }


Trying a different design as an exercise for an eLearning project, so the current script needs to be revised.

New design: 3 lights on the left side and 3 lights on the right side. Flashing lights need, each time, to alternate right/left, so the random list needs to be comprised of a random pick from left (lights 1, 2, 3) alternating each time with a random pick from right (4, 5, 6). For example, 2,5,1,4,3,6.

So, maybe 2 (A and B) separate 3 member random lists, then merged alternating one random pick from A with one from B, on and on til 6 total?

So far, been stuck. Can't figure out how to script this.

Any help appreciated.

Regards,

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Merge and alternate 2 arrays into single array
PostPosted: July 26th, 2012, 11:29 pm 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Hi Stephen,

As I thought about it, I started to approach it from the "lights" which I assume are buttons. And I wanted to create 2 sets of 3 Buttons each (set L and set R, for example). Then I'd go into a function that "toggled" a variable... e.g., var Leftbank = true ;
Everytime you go through the function, simply have this statement included within the function at the end:
Code:
Leftbank = !Leftbank ;   //toggle from true to false to true, etc etc


But since I do not know what manipulations or actions turn your lights on/off, I can suggest you simply modify your current script:

1) change from generating randoms btw 1 and 6 to random btw 0 and 2 (or btw 1 and 3, depending on your indexing, addressing)
2) issue a comman to TURN OFF all of the lights
3) use the convenient switch/case command
Code:
switch( Leftbank )
{
case true:
// list of actions next...  if the variable equals true for modify LEFT set
randomset[i] = temp ;  // let's say temp is a value of:  1, or 2, or 3
break;

case false:
// list of actions next...  if the variable equals false for modify RIGHT set
randomset[i] = 3+ temp ;  // let's say temp is a value of:  1, or 2, or 3 ==> so the result here is 4, 5, or 6
break;


4) You will have to layout your "lights" OBJECTS so values 1, 2, or 3 will properly light up LEFT set
and OBJECTS on the RIGHT will be keyed by 4, 5, or 6

- - - - - - -
The above should work consistently, with one possible issue. You have to make sure you are always calling the function twice (first time will take care of LEFT and then 2nd time will do the RIGHT )

_________________
_good things come to those who wait(0)_


For this message Lar_123 has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Merge and alternate 2 arrays into single array
PostPosted: July 27th, 2012, 12:55 am 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi Larry,

Thank you for your helpful reply. With some changing/adapting, this is showing promise. Making progress.

Again, thank you for these suggestions.

Kind Regards,

_________________
Stephen


For this message Stephen has been thanked by : mackavi


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 33 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