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

Non-platform specific questions.

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

Postby foleyjo » Sat Jul 23, 2011 3:01 pm

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");
Last edited by foleyjo on Sat Jul 23, 2011 5:09 pm, edited 1 time in total.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Coding Issue - Why Doesn't This Work

Postby schnellboot » Sat Jul 23, 2011 3:09 pm

tell us what exactly doesn't work
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: Coding Issue - Why Doesn't This Work

Postby foleyjo » Sat Jul 23, 2011 3:16 pm

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
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Coding Issue - Why Doesn't This Work

Postby schnellboot » Sat Jul 23, 2011 3:26 pm

what do you want to express with this
Code: Select all
getclone2("ball",TheseBalls[i].cloneindex);
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: Coding Issue - Why Doesn't This Work

Postby foleyjo » Sat Jul 23, 2011 3:35 pm

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
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Coding Issue - Why Doesn't This Work

Postby foleyjo » Sat Jul 23, 2011 4:45 pm

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;
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

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

Postby foleyjo » Sat Jul 23, 2011 5:10 pm

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");

KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest