Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Script Help
Knusper. Offline
Member

Posts: 58
Threads: 7
Joined: Feb 2013
Reputation: 2
#1
Script Help

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

No one knows, how "I" goes.
(This post was last modified: 03-27-2013, 10:44 AM by Knusper..)
03-23-2013, 10:02 PM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#2
RE: check if active/ string to int

(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)

(This post was last modified: 03-24-2013, 01:11 AM by Adrianis.)
03-24-2013, 01:08 AM
Find
Rapture Offline
Posting Freak

Posts: 1,078
Threads: 79
Joined: May 2011
Reputation: 30
#3
RE: check if active/ string to int

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.
(This post was last modified: 03-24-2013, 02:18 AM by Rapture.)
03-24-2013, 02:18 AM
Find
Knusper. Offline
Member

Posts: 58
Threads: 7
Joined: Feb 2013
Reputation: 2
#4
RE: check if active/ string to int

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:

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;
    }
    
}

No one knows, how "I" goes.
(This post was last modified: 03-24-2013, 01:19 PM by Knusper..)
03-24-2013, 01:15 PM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#5
RE: check if active/ string to int

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

03-24-2013, 03:14 PM
Find
Knusper. Offline
Member

Posts: 58
Threads: 7
Joined: Feb 2013
Reputation: 2
#6
RE: check if active/ string to int

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?

No one knows, how "I" goes.
(This post was last modified: 03-24-2013, 09:21 PM by Knusper..)
03-24-2013, 08:51 PM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#7
RE: check if active/ string to int

(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

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

(This post was last modified: 03-24-2013, 10:52 PM by Adrianis.)
03-24-2013, 10:48 PM
Find
Knusper. Offline
Member

Posts: 58
Threads: 7
Joined: Feb 2013
Reputation: 2
#8
RE: check if active/ string to int

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

No one knows, how "I" goes.
03-24-2013, 10:57 PM
Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#9
RE: check if active/ string to int

(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.

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

(This post was last modified: 03-24-2013, 11:03 PM by Adrianis.)
03-24-2013, 11:03 PM
Find
Knusper. Offline
Member

Posts: 58
Threads: 7
Joined: Feb 2013
Reputation: 2
#10
RE: check if active/ string to int

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
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.

No one knows, how "I" goes.
(This post was last modified: 03-25-2013, 11:23 AM by Knusper..)
03-25-2013, 10:00 AM
Find




Users browsing this thread: 1 Guest(s)