Arrays - question about programming

You must understand the Game Editor concepts, before post here.

Arrays - question about programming

Postby Leif » Tue Feb 08, 2011 8:08 am

Hi :D

The question is about arrays. For example we have 2 arrays of int and depending on A and B values we work either with array1[10] or with array2[10].
I have procedure like this:
Code: Select all
void PROC(int A, int B)
{
if (A>B)
{   array1[0]=...;
.....
..... // other actions with array1[];
}

if (A<B)
{ array2[0]=...;
.....
..... // other actions with array2[];
}
}


This is what i want to do:

Code: Select all
void PROC(int A, int B)
{
if (A>B) AAA=array1[10]; // can I do something like this?
if (A<B) AAA=array2[10];

{   AAA[0]=...;
.....
..... // other actions with AAA[];
}



How ?
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Arrays - question about programming

Postby Bee-Ant » Tue Feb 08, 2011 8:32 am

OK, so in this case you have 3 arrays, array1[10], array2[10], and AAA[10].
You seem to already know how to do it though.
Well, this would be my method :
Code: Select all
void InsertValue(int A, int B, int SourceIndex, int TargetIndex, int CheckIndex, int CheckValue)
{
    if(A>B)
    {
        AAA[TargetIndex]=array1[SourceIndex];
    }
    if(A<B)
    {
        AAA[TargetIndex]=array2[SourceIndex];
    }
    if(AAA[CheckIndex]==CheckValue)
    {
        //Do something here
    }
}
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Arrays - question about programming

Postby Leif » Tue Feb 08, 2011 9:03 am

Need some explanations.
Code: Select all
if(A>B)
    {
        AAA[TargetIndex]=array1[SourceIndex];
    }

Does it mean that we assign values from array1 to AAA one by one?

Can we do things like "operate with AAA, but changes are made in array1" just using pointer or other method ?
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Arrays - question about programming

Postby Bee-Ant » Tue Feb 08, 2011 10:27 am

In that case, one by one.

Oh, do you want to include the whole array1 or array2 into AAA?
Then it should be:
Code: Select all
int i;
if(A>B)
{
    for(i=0;i<10;i++)
    {
        AAA[i]=array1[i];
    }
}
if(A<B)
{
    for(i=0;i<10;i++)
    {
        AAA[i]=array2[i];
    }
}
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Arrays - question about programming

Postby Leif » Thu Feb 10, 2011 8:45 am

Thanks, solved )
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron