Page 1 of 1

Coding Issue - Why Doesn't This Work **SORTED**

PostPosted: Sat Jul 23, 2011 3:01 pm
by foleyjo
Is there a reason this won't work?
I assume it's got something to do with my Actors and how I'm using them.
The last 2 lines work so they can be ignored.



Code: Select all
//Actor Vars = Colour and Colour Match
//Actors = Border and ball
//1 - Get All Balls Colliding With Border
//2 -For Each Of The Balls Colliding
//3- Get all balls colliding with the checkball
//4 -For all balls colliding with the checkball check the colour and see if it matches

int i,n;
Actor * TheseBalls =getAllActorsInCollision("Border",&n);//1
for(i=0;i<n;i++) //2
{
  int j,m;
  int ThisColour;
  Actor*CheckBall = getclone2("ball",TheseBalls[i].cloneindex);
  Actor*CollidingActor = NULL;
 
  CollidingActor = getAllActorsInCollision("CheckBall",&m);//3
  for(j=0;j<m;j++)
  {
    if(CollidingActor[j].Colour==CheckBall->Colour) //4
      CheckBall->ColourMatch++;
  }
}
 CreateActor("Trigger", "icon", "(none)", "(none)", 10, 205, true);
DestroyActor("Event Actor");

Re: Coding Issue - Why Doesn't This Work

PostPosted: Sat Jul 23, 2011 3:09 pm
by schnellboot
tell us what exactly doesn't work

Re: Coding Issue - Why Doesn't This Work

PostPosted: Sat Jul 23, 2011 3:16 pm
by foleyjo
It doesn't do the first for loop (and maybe not the 2nd once the first is working)

I know this because I added an integer starting at 0 and added 1 to it at various stages.

The end value of the integer was 2 (checked in a text box)
so that was +1 before the for loop and +1 after the for loop

bit more info that I should have included - Border is a Filled Region and inside it there are currently 8 ball actors

This code is in a seperate actor called setup. It is in the Draw function and is only to be executed once at the start of the game. Which is why it is destroyed at the end

Re: Coding Issue - Why Doesn't This Work

PostPosted: Sat Jul 23, 2011 3:26 pm
by schnellboot
what do you want to express with this
Code: Select all
getclone2("ball",TheseBalls[i].cloneindex);

Re: Coding Issue - Why Doesn't This Work

PostPosted: Sat Jul 23, 2011 3:35 pm
by foleyjo
I was going to use
Code: Select all
 CollidingActor = getAllActorsInCollision(TheseBalls[i].cloneindex,&m)


but kept getting errors so I thought it might be better to use

Code: Select all
  Actor*CheckBall = getclone2("ball",TheseBalls[i].cloneindex);
  CollidingActor = getAllActorsInCollision(TheseBalls[i].cloneindex,&m);


I also tried
Code: Select all
  Actor*CheckBall = getclone2("ball",i);


but this only seems to work if the balls cloneindex's are in sequence 0 to amount of balls colliding

As a further note I don't think it actually gets to the line


Code: Select all
 Actor*CheckBall = getclone2("ball",TheseBalls[i].cloneindex);

because I put the debug line below it and it did not add 1 to the value

Re: Coding Issue - Why Doesn't This Work

PostPosted: Sat Jul 23, 2011 4:45 pm
by foleyjo
I have located where I think the problem is

When using the following the output is 0 when it should be 8. (8 actors in between the filled region border)

Code: Select all
int n;
Actor * TheseBalls = NULL;
TheseBalls = getAllActorsInCollision("Border",&n);//1
texty.textNumber =n;

Re: Coding Issue - Why Doesn't This Work **SORTED**

PostPosted: Sat Jul 23, 2011 5:10 pm
by foleyjo
It's OK this seems to do it (not sure if it's the best way to do it though so feel free to correct me :D )

Code: Select all
//1 -Get All Balls Colliding With Border
//2 -For Each Of The Balls Colliding
//3 -Get all balls colliding with the checkball
//4 -For all balls colliding with the checkball check the colour and see if it matches

int i;
int n;

Actor * TheseBalls = NULL;
TheseBalls = getAllActorsInCollision(Border.clonename,&n);//1
if(TheseBalls)
{
 for(i=0;i<n;i++) //2
 {
  int j,m;
  int ThisColour;
  Actor*CheckBall = getclone2("ball",TheseBalls[i].cloneindex);
  Actor*CollidingActor = NULL;
  CollidingActor = getAllActorsInCollision(CheckBall->clonename,&m);//3
  for(j=0;j<m;j++)
  {
    if(CollidingActor[j].Colour==CheckBall->Colour) //4
      CheckBall->ColourMatch++;
  }
}
}
CreateActor("Trigger", "icon", "(none)", "(none)", 10, 205, true);
DestroyActor("Event Actor");