Frictional Games Forum (read-only)

Full Version: For-loop - not declared [SOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys.

Take a look at this:

PHP Code:
void CheckBattle()
{
    
//ENEMY//
    
    
for(int EnemyHealthCounter=EnemyMonsterHealth;EnemyHealthCounter<11;EnemyHealthCounter++)SetLampLit("EnemyHealth_"+EnemyHealthCounterfalse);
    
    
    
    
//FRIENDLY//
    
for(int FriendlyHealthCounter=FriendlyMonsterHealth;FriendlyHealthCounter<11;FriendlyHealthCounter++)SetLampLit("FriendlyHealth_"+FriendlyHealthCounterfalse);
    for(
int i=1;i<5;i++)SetEntityActive("Move_"+ifalse);
    
    
    
//MOVES//
    
for(int MoveCounter=1;MoveCounter<MoveAmount+1;MoveCounter++)SetEntityActive("Move_"+MoveCountertrue);
    
CreateParticleSystemAtEntity("MoveParticle_"+MoveCounter"ps_orb_absorb.ps""Move_"+MoveCounterfalse);
    
    
    if(
EnemyMonsterHealth <= 0)
    {
        
BattleEnd();
    }
    


I hope this lines up correctly.


It says EnemyMonsterHealth is not declared.

When I am clearly declaring it here:

PHP Code:
void BattlePreparation()
{
    
SetLocalVarInt("InBattle"1);
    
    
//ENEMY MONSTER//
    
int EnemyMonsterHealth 10;
    
    
int MonsterNumber RandInt(1,2);
    
SetEntityActive("MonsterBox_"+MonsterNumbertrue);
    
    
    
CheckBattle();


What I'm trying to do is make a for loop check how much health the monster has by grabbing the actual health as the lowest and the max health (+1) as the highest.

Am I doing something wrong?
I don't think the script can find the int variable there, considering it's not a global int either. I would put the int variable in the CheckBattle script as well.

Code:
void CheckBattle()
{
    //ENEMY//
    
     int EnemyMonsterHealth = 10;
for(int EnemyHealthCounter=EnemyMonsterHealth;EnemyHealthCounter<11;EnemyHealthCounter++)SetLampLit("EnemyHealth_"+EnemyHealthCounter, false);
    
    
    
    //FRIENDLY//
    for(int FriendlyHealthCounter=FriendlyMonsterHealth;FriendlyHealthCounter<11;FriendlyHealthCounter++)SetLampLit("FriendlyHealth_"+FriendlyHealthCounter, false);
    for(int i=1;i<5;i++)SetEntityActive("Move_"+i, false);
    
    
    //MOVES//
    for(int MoveCounter=1;MoveCounter<MoveAmount+1;MoveCounter++)SetEntityActive("Move_"+MoveCounter, true);
    CreateParticleSystemAtEntity("MoveParticle_"+MoveCounter, "ps_orb_absorb.ps", "Move_"+MoveCounter, false);
    
    
    if(EnemyMonsterHealth <= 0)
    {
        BattleEnd();
    }
    
}
An int dies after it's functions is done. You need to use SetLocalVarInt("EnemyMonsterHealth);
Putting it there isn't gonna help much, since CheckBattle is actually checking the value of that int and if CheckBattle sets it to 10 all the time, there's no reason to check it..


I'm gonna try to fix this with a timer. Got other solutions? They'll be accepted with smiles ^^

(08-22-2014, 06:45 PM)Wapez Wrote: [ -> ]An int dies after it's functions is done. You need to use SetLocalVarInt("EnemyMonsterHealth);

Woop woop thanks! I'll see how it works!



EDIT: Oh god... It was too simple...

Thanks Wapez you solved one part.

The other part was... I need to remember to use GetLocalVarInt and not just use the name of the variable.