I am having a problem dealing with arrays.

I have a var array with 5 elements set up with numbers 1-5, and I have a second var array, same size, with all zeroes.

I want to randomly select one element from the first array, put it into the next open element in the second array, replace the element in the first array with a zero, then move the zero to the last element, then start again to fill up the second array with the first array elements but in random order.

if the explanation is hard to understand here is a visual
Code:
element      0  1  2  3  4
first array [1][2][3][4][5]
secondarray [0][0][0][0][0]

pick random element by integer(random(max)) //max is maximum number of elements in array to choose from, so no zeroes.
secondarray [4][0][0][0][0]
first array [1][2][3][0][0]

after loop algorithm

first array [1][2][3][5][0]

max--;



Here is my actual code
Code:
var* firstSet[5] = {1,2,3,4,5};

ENTITY* ball;
ENTITY* box;
ENTITY* floorMdl;
ENTITY* cubeMdl;
ENTITY* temp;
var max = 5;
var* placed[5] = {0,0,0,0,0};
void retrieveItem();

void main()
{
...
retrieveItem();
...
}

action place()
{
	var x = my.x;
	var y = my.y;
	var z = my.z;
	var a = my.skill1 - 1;
	wait_for(retrieveItem);
	var b = placed[a];
	switch(b)
	{
		case 1: ball = ent_create("bball.mdl", vector(x,y,z), NULL); break;
		case 2: box = ent_create("bbox.mdl", vector(x,y,z), NULL); break;
		case 3: floorMdl = ent_create("floor.mdl", vector(x,y,z), NULL); break;
		case 4: cubeMdl = ent_create("cube.mdl", vector(x,y,z), NULL); break;
		case 5: temp = ent_create("way.mdl", vector(x,y,z), NULL); break;
	}
}

void retrieveItem()
{
	random_seed(0);

	var i = 0;
	for(;i<5; i++)
	{
	var randomItem = integer(random(max));

	placed[i] = firstSet[randomItem];
	
	firstSet[randomItem] = 0;
	//cycle the the zero to the end
	var k=0;
	for(;k<5;k++)
	{
		if(firstSet[k] == 0)
		{
			firstSet[k] = firstSet[k+1];
			firstSet[k+1] = 0;
		}
	}
	max-= 1;
	}
}

What is supposed to happen is, there are five invisible entities in the level each with a unique id 1-5, at startup, they are assigned a random item to spawn by simply checking their spot in the second array.

What actually happens......Nothing! grin I'm so lost as to why nothing is happening.

I have tried using printf to see what the variables are equal to a different parts of the code, and they all say 0.

any help would be appreciated.

I think I just need more...coffee. grin

EDIT: I placed a default case at the switch and just told it to beep(), and they all just beeped there fore the second array is staying at all 0's


EDIT: I figured out the problem...after more coffee. grin
For some reason I made the arrays pointers which was causing the problem. I took out the "*" on both array definitions and everything works perfectly. Thanks anyways. laugh

Last edited by xbox; 01/12/14 01:30.