Frictional Games Forum (read-only)
LocalVar - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: LocalVar (/thread-18282.html)



LocalVar - i3670 - 09-11-2012

Hi got this small problem with my script.

Spoiler below!

void OnStart()
{
SetLocalVarInt("InsaneImages", 0);
AddEntityCollideCallback("Player", "AreaActivateInteract", "ActivateInsaneImages", true, 1);
}

void ActivateInsaneImages(string &in asParent, string &in asChild, int alState)
{
for(int i=1;i<=3;i++) {
SetEntityPlayerInteractCallback("Flask_"+i+"", "AddLocalNumber", false);
}
}

void AddLocalNumber(string &in asEntity)
{
if(GetLocalVarInt("InsaneImages") == 1)
{
SetEntityActive("armour_nice_complete_1", true);
SetEntityActive("", true);

}

if(GetLocalVarInt("InsaneImages") == 2)
{
SetEntityActive("armour_nice_complete_2", true);
SetEntityActive("", true);

}

AddLocalVarInt("InsaneImages", 1);
All_Active();
}

void All_Active()
{
if(GetLocalVarInt("InsaneImages") == 3)
{
SetEntityActive("armour_nice_complete_3", true);
SetEntityActive("", true);
}
}



After I've interacted with 1 flask, doesn't matter which one, 1 armour is supposed to get active This, however, doesn't really work exactly to plan.

If I for instance interact with flask_3 first all armours gets activated, regardless if I've interacted with the other 2. If I interact with flask_1 nothing happens, this also goes for flask_2. However if I interact with 1 and then 2 or the other way around only 1 armour gets activated.


RE: LocalVar - Adny - 09-11-2012

Try something like this:


void OnStart()
{
SetLocalVarInt("InsaneImages", 0);
AddEntityCollideCallback("Player", "AreaActivateInteract", "ActivateInsaneImages", true, 1);
}

void ActivateInsaneImages(string &in asParent, string &in asChild, int alState)
{
for(int i=1;i<=3;++i)
SetEntityPlayerInteractCallback("Flask_" + i, "AddLocalNumber", false);
}

void AddLocalNumber(string &in asEntity)
{
AddLocalVarInt("InsaneImages", 1);
CheckArmor();
}

void CheckArmor()
{
if(GetLocalVarInt("InsaneImages") == 1)
{
SetEntityActive("armour_nice_complete_1", true);
}
if(GetLocalVarInt("InsaneImages") == 2)
{
SetEntityActive("armour_nice_complete_2", true);
}
if(GetLocalVarInt("InsaneImages") == 3)
{
SetEntityActive("armour_nice_complete_3", true);
}
}


The only problem I see (with the original) is that since the callback doesn't remove automatically, the player can interact with 1 flask 3 times and achieve the same effect. You would have to make 3 separate callbacks (1 for each flask) to get rid of that problem.

Hope that helped :o


RE: LocalVar - Tomato Cat - 09-11-2012

*edit*
NINJA'D >.<

I think that this line:

Code:
SetEntityPlayerInteractCallback("Flask_"+i+"", "AddLocalNumber", false);

should be this instead:

Code:
SetEntityPlayerInteractCallback("Flask_"+i, "AddLocalNumber", false);
And I would put your if statements into the "All_Active" function.
Spoiler below!

Code:
void OnStart()
{
    SetLocalVarInt("InsaneImages", 0);
    AddEntityCollideCallback("Player", "AreaActivateInteract", "ActivateInsaneImages", true, 1);
}

void ActivateInsaneImages(string &in asParent, string &in asChild, int alState)
{
    for(int i=1;i<=3;i++) {
    SetEntityPlayerInteractCallback("Flask_"+i+"", "AddLocalNumber", false);
    }
}

void AddLocalNumber(string &in asEntity)
{
        AddLocalVarInt("InsaneImages", 1);
        All_Active();
}

void All_Active()
{

if(GetLocalVarInt("InsaneImages") == 1)
    {
        SetEntityActive("armour_nice_complete_1", true);
        SetEntityActive("", true);
    }
    
if(GetLocalVarInt("InsaneImages") == 2)
        {
            SetEntityActive("armour_nice_complete_2", true);
            SetEntityActive("", true);
        }
if(GetLocalVarInt("InsaneImages") == 3)
{
SetEntityActive("armour_nice_complete_3", true);
SetEntityActive("", true);
}
}



Try that and see if it fixes it.


RE: LocalVar - FlawlessHappiness - 09-12-2012

Yes. Before you ask "if(GetLocalVarInt("InsaneImages") == 1)" you will have to "AddLocalVarInt("InsaneImages", 1)" Because otherwise it would just be 0 since you haven't added anything to it