Page 1 of 1

Need a small fix on this script

PostPosted: Tue Nov 09, 2004 3:38 am
Author: 4x4_Ender
For some reason, the nested loop on this script isnt working. Instead of creating only the objects under the conditions of the appropriate if statement, it creates ALL of the objects under all if statements (all 4 of them).

Code: Select all
void main()
{
    int nXP = GetXP(GetPCSpeaker());
    int nObjectType = OBJECT_TYPE_CREATURE;
    string strguardm = "amm_guardmale";
    string strguardf = "amm_guardfemale";
    string strhigrdm = "amm_higrdmale";
    string strhigrdf = "amm_higrdfemale";
    location locLocation = GetLocation(GetNearestObjectByTag("amm_guardspawn"));
    int bUseAppearAnimation = TRUE;

    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3),locLocation);

    if(0 <= nXP < 10000)
        {
        CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
        }
            if(10000 <= nXP < 45000)
                {
                CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
                CreateObject(nObjectType, strguardf, locLocation, bUseAppearAnimation);
                }
                    if(45000 <= nXP < 105000)
                        {
                        CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
                        }
    else
        {
        CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
        CreateObject(nObjectType, strhigrdf, locLocation, bUseAppearAnimation);
        }
}

PostPosted: Tue Nov 09, 2004 4:06 am
Author: Eliyas
I think the 2nd and 3rd ifs should be else if statements. Also, I don't know if the 0 <= x < 10000 syntax works, and it would be more clear if you made it (x >= 0) AND (x < 10000), and might fix the problem.

PostPosted: Tue Nov 09, 2004 4:13 am
Author: Jonezie
The 'else' statement you've used at the end only works off of the preceeding (3rd) 'if' statement. All of the other 'if's are independant of each other.

Have you tried it with characters of differant experience?
The way I read it, if youre 0-10000, it should spawn 3 creature - strguardm from the first 'if', and 2 higuards from the 'else'

10000 - 45000: All 4. 2 from the 2nd 'if' and 2 from the 'else'

45000 - 105000: just 1, from the third 'if'

Greater than 105000 - the two from the 'else'

I think if you change the 'else' to:

If (nXP>105000) {...

It should work the way you're wanting.

PostPosted: Tue Nov 09, 2004 5:36 am
Author: 4x4_Ender
what is the symbol used for the "AND" function? I tried | and || but they dont seem to combine the two conditions.

PostPosted: Tue Nov 09, 2004 5:59 am
Author: Tissa
4x4_Ender wrote:what is the symbol used for the "AND" function? I tried | and || but they dont seem to combine the two conditions.


AND is &&

as a note:
"&&" is Short circuit logical AND
"&" is bitwise AND
"||" is Short circuit logical OR
and "|" is bitwise OR

PostPosted: Tue Nov 09, 2004 6:00 am
Author: Jonezie
Try this, it should work, although there's probably a more elegant way of doing it. I think it was the (x < nXP < y) notation that was causing problems.

Code: Select all
void main()
{
    int nXP = GetXP(GetPCSpeaker());
    int nObjectType = OBJECT_TYPE_CREATURE;
    string strguardm = "amm_guardmale";
    string strguardf = "amm_guardfemale";
    string strhigrdm = "amm_higrdmale";
    string strhigrdf = "amm_higrdfemale";
    location locLocation = GetLocation(GetNearestObjectByTag("amm_guardspawn"));
    int bUseAppearAnimation = TRUE;

    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3),locLocation);

    if(nXP < 10000)
        {
        CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
        }
    else {  if(nXP < 45000)
            {
            CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
            CreateObject(nObjectType, strguardf, locLocation, bUseAppearAnimation);
            }
            else{   if(nXP < 105000)
                    {
                    CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
                    }
                    }
                    }
     if(nXP >= 105000)
        {
        CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
        CreateObject(nObjectType, strhigrdf, locLocation, bUseAppearAnimation);
        }
}

PostPosted: Tue Nov 09, 2004 6:50 am
Author: Tissa
I think this is what you want: (just fixing the if statements)

Code: Select all
void main()
{
    int nXP = GetXP(GetPCSpeaker());
    int nObjectType = OBJECT_TYPE_CREATURE;
    string strguardm = "amm_guardmale";
    string strguardf = "amm_guardfemale";
    string strhigrdm = "amm_higrdmale";
    string strhigrdf = "amm_higrdfemale";
    location locLocation = GetLocation(GetNearestObjectByTag("amm_guardspawn"));
    int bUseAppearAnimation = TRUE;

    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3), locLocation);

    if (nXP < 10000)
    {
        CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
    }
    else if (nXP < 45000)
    {
        CreateObject(nObjectType, strguardm, locLocation, bUseAppearAnimation);
        CreateObject(nObjectType, strguardf, locLocation, bUseAppearAnimation);
    }
    else if (nXP < 105000)
    {
        CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
    }
    else
    {
        CreateObject(nObjectType, strhigrdm, locLocation, bUseAppearAnimation);
        CreateObject(nObjectType, strhigrdf, locLocation, bUseAppearAnimation);
    }
}


another way to write it:

Code: Select all
void main()
{
    int iXP = GetXP(GetPCSpeaker());
    int iType = OBJECT_TYPE_CREATURE;
    location locSpawn = GetLocation(GetNearestObjectByTag("amm_guardspawn"));
    int bUseAnimation = TRUE;

    effect eMonster = EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_3);
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eMonster, locSpawn);

    if (iXP < 10000)
    {
        CreateObject(iType, "amm_guardmale", locSpawn, bUseAnimation);
    }
    else if (iXP < 45000)
    {
        CreateObject(iType, "amm_guardmale", locSpawn, bUseAnimation);
        CreateObject(iType, "amm_guardfemale", locSpawn, bUseAnimation);
    }
    else if (iXP < 105000)
    {
        CreateObject(iType, "amm_higrdmale", locSpawn, bUseAnimation);
    }
    else
    {
        CreateObject(iType, "amm_higrdmale", locSpawn, bUseAnimation);
        CreateObject(iType, "amm_higrdfemale", locSpawn, bUseAnimation);
    }
}


somewhat following the Avlis coding standard post http://www.avlis.org/viewtopic.php?t=7739 using a prefix of "i" for integer variables.

PostPosted: Tue Nov 09, 2004 7:17 am
Author: Jonezie
Heh....much nicer to look at then mine, too.

PostPosted: Tue Nov 09, 2004 2:54 pm
Author: 4x4_Ender
Thanks guys. 8)