Page 1 of 1

problems with arrays

PostPosted: Fri Nov 26, 2010 4:29 am
by sportmaster
I Have 4 enemies with different HP values. I need a code to destroy every actor with HP below 0. I want to use arrays. I really need to know how to use it. Should I create a variable with array option, or write
Code: Select all
int HP[4];
? Where I should put this ? In to global code ? In to enemy's create actor or draw actor ? where ? I also don't know where to put HP values :
Code: Select all
HP[0]=80;
HP[1]=120;
HP[2]=60;
HP[3]=40;
and how to use this function :
Code: Select all
int i
for(i=0;i<4;i++)
{
      if(HP[i]<0)
      {
            DestroyActor("enemy.i");
      }
}
I have no idea how to decrease HP after a collision event to hurt only the attacked foe clone or maybe a shouldn't make clones and add 4 enemy actors with the same variable... help ! please !

Re: problems with arrays

PostPosted: Fri Nov 26, 2010 5:05 am
by jimmynewguy
Global Code
Code: Select all
int hp[4]; // 4 because you only have 4 enemies, make larger for more

create actor -> enemy -> script editor
Code: Select all
hp[cloneindex]=20; // makes it have 20 health (each enemy)
// if you want you could do 20*cloneindex so each enemy would have 20 more than the next

collsion on whatever hurts them -> scripteditor
Code: Select all
hp[cloneindex]-=1; // for subtracting 1 hit point

enemy -> draw actor -> script editor
Code: Select all
if(hp[cloneindex]<=0)// if "my" health is less than or equal to zero (ie dead)
DestroyActor("Event Actor");


is the array way to do it. but its much simpler to make an actor variable called hp then on create actor
Code: Select all
hp = 20;

Code: Select all
hp-=1;
for hurt
Code: Select all
if(hp<=0)DestroyActor("Event...");
for dieing
you get the idea same thing basically

and if you want to make different hp's based not on 20's like you had it just
Code: Select all
switch(cloneindex)
{
case 0:hp = 20; // if the cloneindex is 0 ie the first made one
break;
case 1:hp = 60;
break;
// continue for others (2, 3)

}

Re: problems with arrays

PostPosted: Fri Nov 26, 2010 9:46 pm
by sportmaster
About your first way to solve my problem : as you can see, if you downloaded my ged the enemy with cloneindex 0 is dieing at the begining, but when he and his hp display are removed it's all right(additionally I have placed a text clones to display enemy's hp). You can drag warrior with a mouse to hit the foe.

Re: problems with arrays

PostPosted: Sat Nov 27, 2010 10:40 am
by sportmaster
Second option works well too it's even better I'll use it, thanks :D ,but you forgot to say that I should set variable as an actor variable :( so I thought that it shall be in draw actor, and to exit loop I must add disable draw actor at the end but as I have guessed later It has to be in create actor but the variable should be actor not global. I'm still learning basics :p

Re: problems with arrays

PostPosted: Sun Nov 28, 2010 2:59 pm
by jimmynewguy
Glad to hear you got it working, sorry to hear i confused you a little. But just to say i did say actor variable and create actor and to save myself... :P
jimmynewguy wrote:is the array way to do it. but its much simpler to make an actor variable called hp then on create actor
Code: Select all
hp = 20;


Re: problems with arrays

PostPosted: Mon Nov 29, 2010 3:00 am
by sportmaster
Indeed :o