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
how do timers work?
Soverain Offline
Junior Member

Posts: 18
Threads: 5
Joined: Jul 2012
Reputation: 1
#1
how do timers work?

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?
(This post was last modified: 07-31-2012, 09:51 PM by Soverain.)
07-31-2012, 04:49 AM
Find
Mackiiboy Offline
Member

Posts: 101
Threads: 7
Joined: Jan 2012
Reputation: 11
#2
RE: how do timers work?

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?
07-31-2012, 09:56 AM
Website Find
ApeCake Offline
Member

Posts: 116
Threads: 20
Joined: Jun 2012
Reputation: 4
#3
RE: how do timers work?

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.
07-31-2012, 10:45 AM
Find
Soverain Offline
Junior Member

Posts: 18
Threads: 5
Joined: Jul 2012
Reputation: 1
#4
RE: how do timers work?

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
07-31-2012, 08:49 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#5
RE: how do timers work?

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

Trying is the first step to success.
07-31-2012, 08:58 PM
Find
Mackiiboy Offline
Member

Posts: 101
Threads: 7
Joined: Jan 2012
Reputation: 11
#6
RE: how do timers work?

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 :]

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
(This post was last modified: 07-31-2012, 09:07 PM by Mackiiboy.)
07-31-2012, 09:02 PM
Website Find
Soverain Offline
Junior Member

Posts: 18
Threads: 5
Joined: Jul 2012
Reputation: 1
#7
RE: how do timers work?

Wow, thank you all :3
07-31-2012, 09:51 PM
Find




Users browsing this thread: 3 Guest(s)