Frictional Games Forum (read-only)

Full Version: SOLVED Creating a Light Switch
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey guys,

I am working on a modern custom story, there's a room that is dark, in the middle of the room a light hangs from the ceiling. I've seen in other custom stories light switches that can turn on lights in the room. Could someone give me a tutorial on how to do this? I want the switch to turn on just the one light in the room.

I prefer with pictures, since I'm new at scripting and quite slow, but a tutorial without any pictures is fine.

Thanks
How would you like the lights to be turned on, button, lever or wheel?
Lever.
Try something like this.

Code:
void OnStart()
{
SetEntityConnectionStateChangeCallback("whatever","whateverthefunc");
}

void whateverthefunc(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLampLit("lampname", true, true);
}

if(alState == -1)
{
SetLampLit("lampname",false,true);
}
}
I tried and I'm getting a error when I try to launch the story.

FATAL ERROR: Could not load script file 'customs stories/csa/maps/csa/csa.hps'! main (5,1) : ERR : A function with the same name and parameters already exist.

This what I did after interpreting your suggestion.

In "whatever" I put in the name of the lever.

"In whateverthefunc" I put "jacobroomfunc"

Then in the editor, I put "jacobroomfunc" in the levers Callback Func

In "lampname" I put the name of the lamp.
You have two functions with the same name; please post your full script so we can help Smile
void OnStart()
{


}
void OnStart()
{
SetEntityConnectionStateChangeCallback("jacobwrbedswitch","jacobroomfunc");
}


void jacobroomfunc(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLampLit("Jacob_WR_Lamp", true, true);
}


if(alState == -1)
{
SetLampLit("Jacob_WR_Lamp",false,true);
}
}
Change the name to jacobroomfunc2 or something.
You had two OnStart's, here's a revision:


void OnStart()
{
SetEntityConnectionStateChangeCallback("jacobwrbedswitch","jacobroomfunc");
}


void jacobroomfunc(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLampLit("Jacob_WR_Lamp", true, true);
}


if(alState == -1)
{
SetLampLit("Jacob_WR_Lamp",false,true);
}
}

Hope that helped.
Or that. xD
Pages: 1 2