Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, bigsmack, 7th_zorro, dr_panther), 1,364 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
a little array help please #293673
10/13/09 04:52
10/13/09 04:52
Joined: Apr 2006
Posts: 624
DEEP 13
badapple Offline OP
User
badapple  Offline OP
User

Joined: Apr 2006
Posts: 624
DEEP 13
var array_choice1;
var array_choice2;
var array_choice3;
var array_choice4;
var array_choice5;

var my_array[10] = {0,10,20,30,40,50,60,70,80,90};


i need a small function that choses 5 variables from
my_array[10] and applies them to array_choice 1-5 but
doesnt chose the same array spot twice.
so if this function choses my_array[3] randomly first
then array_choice1 will be assinged that value and
my_array[3] cant be chosen again

and all must be chosen randomly

i really appreciate any help smile

Last edited by badapple; 10/13/09 04:54.
Re: a little array help please [Re: badapple] #293675
10/13/09 05:52
10/13/09 05:52
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Untested but I think its OK...
Code:
var array_choice1 = -1;
var array_choice2 = -1;
var array_choice3 = -1;
var array_choice4 = -1;
var array_choice5 = -1;

var my_array[10] = {0,10,20,30,40,50,60,70,80,90};

function populate-choices()
{  random_seed(0);   //really ranomize values
   //select first index
   array_choice1 = integer(random(10));
   //select second index
   while(array_choice2==-1)
   {  array_choice2 = integer(random(10));
      if(array_choice2==array_choice1)   array_choice2 = -1;
   }
   //select third index
   while(array_choice3==-1)
   {  array_choice3 = integer(random(10));
      if(array_choice3==array_choice1)   array_choice3 = -1;
      if(array_choice3==array_choice2)   array_choice3 = -1;
   }
   //select forth index
   while(array_choice4==-1)
   {  array_choice4 = integer(random(10));
      if(array_choice4==array_choice1)   array_choice4 = -1;
      if(array_choice4==array_choice2)   array_choice4 = -1;
      if(array_choice4==array_choice3)   array_choice4 = -1;
   }
   //select fifth index
   while(array_choice5==-1)
   {  array_choice5 = integer(random(10));
      if(array_choice5==array_choice1)   array_choice5 = -1;
      if(array_choice5==array_choice2)   array_choice5 = -1;
      if(array_choice5==array_choice3)   array_choice5 = -1;
      if(array_choice5==array_choice4)   array_choice5 = -1;
   }
   //now turn indexes into actual array values
   array_choice1 = my_array[array_choice1];
   array_choice2 = my_array[array_choice2];
   array_choice3 = my_array[array_choice3];
   array_choice4 = my_array[array_choice4];
   array_choice5 = my_array[array_choice5];
}

BEWARE of typo's....


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: a little array help please [Re: EvilSOB] #293688
10/13/09 08:27
10/13/09 08:27
Joined: Apr 2006
Posts: 624
DEEP 13
badapple Offline OP
User
badapple  Offline OP
User

Joined: Apr 2006
Posts: 624
DEEP 13
thank you evilsob i will try it.

Re: a little array help please [Re: badapple] #293699
10/13/09 09:40
10/13/09 09:40
Joined: Jul 2008
Posts: 553
Singapore
delinkx Offline
User
delinkx  Offline
User

Joined: Jul 2008
Posts: 553
Singapore
here is another way [tested]

Code:
//array choices
var array_choice1;
var array_choice2;
var array_choice3;
var array_choice4;
var array_choice5;

var my_array[10] = {0,10,20,30,40,50,60,70,80,90};
var chosen_index_array[5];

//random variable
var myRandom;

//variables
var i,j;
var myflag;


void main()
{
	for (j=0;j<5;j++)
	{
		//seeds the random function
		random_seed(0);
		//flag
		myflag = 0;
		
		while(myflag == 0)
		{
			//choose a random index
			myRandom = integer(random(10));
			
			//check if index already chosen
			for(i=0;i<5;i++)
			{
			 if(myRandom == chosen_index_array[i])
			  {	
				myflag = 0;
				break;
			  }
			 myflag = 1;
			 
			}
			 
		}
	
		//adding index to array chosen
		chosen_index_array[j] = myRandom;
				
		if(j==0)
			array_choice1 = my_array[myRandom];
		if(j==1)
			array_choice2 = my_array[myRandom];
		if(j==2)
			array_choice3 = my_array[myRandom];
		if(j==3)
			array_choice4 = my_array[myRandom];
		if(j==4)
			array_choice5 = my_array[myRandom];
						
	
}
	
	
}




A7 commercial Team / VC++ 2008 Pro
homepage | twitter | facebook
Re: a little array help please [Re: delinkx] #293706
10/13/09 11:38
10/13/09 11:38
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
here's some of my old code...

would use a little code to define and reset the array
Code:
//setup possible object number pairs
	int_objects = 10; //global int
	for(i = 0; i < int_objects; i+=2){
		arr_objects[i] = i*10; //*10 for (0, 10, 20 etc...)
	}



then use this to pick the number
Code:
function get_object_number(){
	
	random_seed(0);
	
	//find number
	int int_temp_chose, int_temp_pos;
	
	int_temp_pos = integer(random(int_objects));
	int_temp_chose = arr_objects[int_temp_pos];
	
	int i;
	for(i = int_temp_pos; i < int_objects; i++){
		arr_objects[i] = arr_objects[i+1];
	}
	
	int_objects--;
	return(int_temp_chose);
}



Re: a little array help please [Re: MrGuest] #293834
10/14/09 08:09
10/14/09 08:09
Joined: Apr 2006
Posts: 624
DEEP 13
badapple Offline OP
User
badapple  Offline OP
User

Joined: Apr 2006
Posts: 624
DEEP 13
thank you all for your help


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1