Frictional Games Forum (read-only)
[SCRIPT] Script Help - 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: [SCRIPT] Script Help (/thread-20888.html)

Pages: 1 2 3 4


Script Help - Knusper. - 03-23-2013

hey forum

I need help with my scripts.
First:
if ("statue_" + areanumber1 == active)
{
IsInArea = true;
LastArea = areanumber1;
AddTimer("Dead", 3, "Dead");
}

There is the problem, that there is no way that the computer can check like this, if an entity is active.
Is there a way to check if an entity is active???

Second:
void FadeOut1(string &in asParent, string &in asChild, int alState)
{
string areanumber2 = StringSub(asChild, 11, 2);
if(LastArea == areanumber2 - 10)
{
IsInArea = false;
LastArea = areanumber2;
}

}

Here there is no possibility to do maths like "-" with a string and an int.
How can I change a string like "16" into an int?

Thx for reading


RE: check if active/ string to int - Adrianis - 03-24-2013

(03-23-2013, 10:02 PM)Knusper. Wrote: Is there a way to check if an entity is active???

There is no function to check if an entity is active, but there is one to check if it exists, not sure if it will be useful for you though...
GetEntityExists(string& asName);

Alternatively, if it is an entity that you are setting active/inactive in the script, you can a bool or int to set to true/false when you active/deactive the entity, then check that instead to see if it is active/inactive

(03-23-2013, 10:02 PM)Knusper. Wrote: Here there is no possibility to do maths like "-" with a string and an int.

You can use + and += to concatenate integers onto the string (which converts the int into a number character), but you can't do math operations like '-' with a string.

However since the string is essentially an array of integers that hold the ASCII value for the character in the string, you can treat the characters as int's by accessing the index values of the characters in the string (using [ and ], e.g. string[0] = 1)


RE: check if active/ string to int - Rapture - 03-24-2013

You could have the "entity" initially set "Inactive" in the level editor. Have a script make it active, and in the script have a variable you create set to "1" (Initially at the start of the map, it's set to 0). From their you can keep track of the "said entity" Active and Inactive states.


RE: check if active/ string to int - Knusper. - 03-24-2013

thx all.
I now found a way for ma problems.
But it doesnt work...
Maybe you can find a mistake.
I hope you understand the skripts.
I dont know if you have to understand what im looking for and how i built the map...

Here they are:

Code:
void OnStart()
{
    
    for (int i = 0; i < 10; i++)
        {
            AddEntityCollideCallback("Player" , "ScriptArea_" + 0 + i , "InArea" , true , 1);
        }
        
        
    for (int i = 11; i < 20; i++)
        {
            AddEntityCollideCallback("Player" , "ScriptArea_" + i , "FadeOut1" , true , 1);
        }
        
    SetSanityDrainDisabled(true);
    AddEntityCollideCallback("Player" , "activeslendy_1" , "Slender1" , true , 1);    
}

bool IsInArea = false;
bool Slender_1active = false;
string LastArea = "00";



void Slender1 (string &in asParent, string &in asChild, int alState)
{
    SetEntityActive("Slender_1", true);
    Slender_1active = (alState == 1);
}



void InArea(string &in asParent, string &in asChild, int alState)
{
    string areanumber1 = StringSub(asChild, 11, 2);
    if (Slender_1active)
    {
        IsInArea = true;
        LastArea = areanumber1;
        AddTimer("Dead", 3, "Dead");
    }
    
}


void Dead(string &in asParent, string &in asChild, int alState)
{
    if(IsInArea == true)
    {
        FadeOut(0.5);
        SetPlayerHealth(0);
    }
}


void FadeOut1(string &in asParent, string &in asChild, int alState)
{
    string areanumber2 = StringSub(asChild, 11, 2);
    int i1, i2;
    
    i2 = areanumber2[0] *10 + areanumber2[1];       //LastArea 2 als int
    i1 = LastArea[0] *10 + LastArea[1];                //LastArea 1 als int
    
    if(i1 == i2 - 10)
    {
        //FadeOut
        IsInArea = false;
        LastArea = areanumber2;
    }
    
}



RE: check if active/ string to int - Adrianis - 03-24-2013

What in the script doesn't work? Is there a particular function that is not working, or do you get an error?


RE: check if active/ string to int - Knusper. - 03-24-2013

At
void InArea(string &in asParent, string &in asChild, int alState)
{
string areanumber1 = StringSub(asChild, 11, 2);
if (Slender_1active)
{
Here
IsInArea = true;
LastArea = areanumber1;
AddTimer("Dead", 3, "Dead");
}

}


I made a debug message at the point i marked.
But it was never shown.
There is "if (Slender_1active)", and the area to set the entitiy active is right at the start, that the model is surely active.

edit:

void Slender1 (string &in asParent, string &in asChild, int alState)
{
SetEntityActive("Slender_1", true);
Slender_1active = (alState == 1);
}

There i have a question:
Slender_1active = (alState == 1);
Does that mean that Slender_1active = true or false?
Or is that completely wrong?


RE: check if active/ string to int - Adrianis - 03-24-2013

(03-24-2013, 08:51 PM)Knusper. Wrote: There i have a question:
Slender_1active = (alState == 1);
Does that mean that Slender_1active = true or false?
Or is that completely wrong?

It might be completely wrong Smile

Code:
void Slender1 (string &in asParent, string &in asChild, int alState)
{
    SetEntityActive("Slender_1", true);
    Slender_1active = true;
}

You are setting Slender_1 to active, so you should set Slender_1active to true, it doesn't matter whether the player is entering or leaving the area, since SetEntityActive("Slender_1", true); is being used regardless of whether the player is entering or leaving. The collide callback is set to only execute when the player is entering the area anyway

I'm not sure you can assign a boolean value using (alState==1), so try it as in my code above. If that doesn't work then maybe there's another problem, if mine does work, then its likely that you can't assign the value the way you were trying


RE: check if active/ string to int - Knusper. - 03-24-2013

yes, i thought so.
strangely another person told me to do what i did...
but now i changed it, but it still doesnt work Huh


RE: check if active/ string to int - Adrianis - 03-24-2013

(03-24-2013, 10:57 PM)Knusper. Wrote: yes, i thought so.
strangely another person told me to do what i did...
but now i changed it, but it still doesnt work Huh

They might be right, I've never tried doing it like that. But in this case it's unnecessary, so you might as well just use the method that definately works Smile

You might need to check all of the names of the script areas and such, I can't see any other problems in the script that should prevent it from working.

Code:
void InArea(string &in asParent, string &in asChild, int alState)
{
    string areanumber1 = StringSub(asChild, 11, 2);
    if (Slender_1active)
    {
        AddDebugMessage("InArea > if statement executing", false);
        IsInArea = true;
        LastArea = areanumber1;
        AddTimer("Dead", 3, "Dead");
    }
}
Use that, just want to make sure your debug message call itself isn't the problem


RE: check if active/ string to int - Knusper. - 03-25-2013

that works, i will add some more messages.

ok, i found the problem, i didnt wrote void MyFunc(string &in asTimer)
Tongue

Now only At
Code:
void FadeOut1(string &in asParent, string &in asChild, int alState)
{
    IsInArea = false;
    string areanumber2 = StringSub(asChild, 11, 2);
    int i1, i2;
    
    i2 = areanumber2[0] *10 + areanumber2[1];       
    i1 = LastArea[0] *10 + LastArea[1];                
    
    if(i1 == i2 - 10)
    {
        AddDebugMessage("fade", false);
        LastArea = areanumber2;
    }
    
}

He sometimes shows the message and sometimes he does not.