Frictional Games Forum (read-only)
how do timers work? - 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: how do timers work? (/thread-17375.html)



how do timers work? - Soverain - 07-31-2012

I want it so that torches begin to light up by themselves when the player enters and i assume timers are involved but i have no idea how to use them. Tips?


RE: how do timers work? - Mackiiboy - 07-31-2012

If you want the torches to be lit at the beginning while entering, you could just press on the [] lit box on every entity in the Level Editor.

If you want the torches to be lit by scripting it, you will not need any timers. You will just have to use SetLampLit("NameOfATorch", true, true); in the void OnEnter(). If you want them to be unlit when you leave, ya'll just have to put SetLampLit("NameOfATorch", false, true); in the void OnLeave().

Of course it's possible to do this with timers if you want. Put AddTimer("", 1.0f, "TorchFunc"); in the void OnEnter(). 1.0f can be changed to any other float, it determines how many seconds it will take before the timer function will be called. In this case, TorchFunc will be called in 1 second.

TorchFunc(string &in asTimer)
{
SetLampLit("NameOfATorch", false, true);
}

----------------------------
I'm not sure if I understand what you mean with "the player enters", if it means that the player enters the map, do as above, if it means that the player enters a room, just use a script area that collides with the player and calls a function that have SetLampLit("NameOfATorch", false, true); or timers that calls SetLampLit in it.
.
(07-31-2012, 04:49 AM)Soverain Wrote: I want it so that torches begin to light up by themselves when the player enters and i assume timers are involved but i have no idea how to use them. Tips?



RE: how do timers work? - ApeCake - 07-31-2012

Yeah as far as I understand your question I think AddEntityCollideCallback is better. That way the player will probably notice the torches going on unlike timers (the player could be looking at a wall and the function would activate after a time and (s)he maybe wouldn't notice the torches going lit).
This should be the script:

void OnStart()
{
AddEntityCollideCallback("Player", "ScriptArea_1", "NameofFunction", false, 1);

// you can set false to true if you want it to delete after the first time.
}


void NameofFunction(string &in asParent, string &in asChild, int alState)
{
SetLampLit("NameofTorch", true, true);
}

I'm pretty sure that should work.


RE: how do timers work? - Soverain - 07-31-2012

Sorry if I am not clear. What I mean by the torches lighting up is that I saw another persons CS where he had a bunch of torches down a hall and they all lit up one by one which i thought was pretty cool


RE: how do timers work? - FlawlessHappiness - 07-31-2012

What you do is add 1 timer:

AddTimer("", 1, "Torch_1");
This timer takes 1 second before it calls the function "Torch_1"


Then you make the function:

void Torch_1(string &in asTimer)
{
SetLampLit("Torch_1", true, true);
AddTimer("", 1, "Torch_2");
}

See? I added another timer inside the timer function. So when the first function is called, the second is triggered 1 second later. This makes the torches light up with 1 second in between.

Repeat this for all your torches:


void Torch_2(string &in asTimer)
{
SetLampLit("Torch_2", true, true);
AddTimer("", 1, "Torch_3");
}




void Torch_3(string &in asTimer)
{
SetLampLit("Torch_3", true, true);
AddTimer("", 1, "Torch_4");
}


RE: how do timers work? - Mackiiboy - 07-31-2012

Something like this would do. Feel free to change all the function/torch names, and modify the timers!
For this, you will need a script area named TorchCollideArea, and a hallway with some torches. When you collide the TorchCollideArea, two torches will be lit every 0,5 second. You can add more / remove some torches, and edit if you want the timers to be called faster/slower :]

Code:
void OnStart()
{
    AddEntityCollideCallback("Player", "TorchCollideArea", "TorchFunc", true, 1);
}

void TorchFunc(string &in asParent, string &in asChild, int alState)
{
    AddTimer("T1", 0.0f, "TorchTimer");
    AddTimer("T2", 0.5f, "TorchTimer");
    AddTimer("T3", 1.0f, "TorchTimer");
    AddTimer("T4", 1.5f, "TorchTimer");
}

void TorchTimer(string &in asTimer)
{
    string x = asTimer;
    if (x == "T1")
    {
        SetLampLit("Torch_1", true, true);
        SetLampLit("Torch_2", true, true);
    }
    else if (x == "T2")
    {
        SetLampLit("Torch_2", true, true);
        SetLampLit("Torch_3", true, true);
    }
    else if (x == "T3")
    {
        SetLampLit("Torch_4", true, true);
        SetLampLit("Torch_5", true, true);
    }
    else if (x == "T4")
    {
        SetLampLit("Torch_5", true, true);
        SetLampLit("Torch_6", true, true);
    }
}
.
(07-31-2012, 08:49 PM)Soverain Wrote: Sorry if I am not clear. What I mean by the torches lighting up is that I saw another persons CS where he had a bunch of torches down a hall and they all lit up one by one which i thought was pretty cool



RE: how do timers work? - Soverain - 07-31-2012

Wow, thank you all :3