Frictional Games Forum (read-only)
[SCRIPT] Lights ON and OFF - 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] Lights ON and OFF (/thread-14150.html)



Lights ON and OFF - asghdrew - 03-21-2012

I have a problem that all light sources (not lamps) are always ON , on startup
even thought I unchecked Active in level editor.

///////////////////////////////////////////////////////////////////////
void OnStart()
{
SetEntityPlayerInteractCallback("lights", "lights_on", true);
}

///////////////////////////////////////////////////////////////////////

void lights_on(string &in asEntity)
{
SetLightVisible("light_1", true);
SetLightVisible("light_2", true);
SetLightVisible("light_3", true);
SetLightVisible("light_4", true);
SetLightVisible("light_5", true);
SetLightVisible("light_6", true);
}
////////////////////////////////////////////////////////////////////////

What I want is when in game I click the switch (lights)
Then the lights should turn on and off
but when I tried it the lights were already ON
and using the switch did complitely nothing.


Thanks Smile



RE: Lights ON and OFF - palistov - 03-21-2012

A few things:

First, players cannot interact with lights in-game. You can script interactions through buttons or levers (like I'm guessing you're trying to do), but scripting a direct player interaction with a light (e.g. the player walks up and literally clicks on the light source) won't work. Second, the only thing your current script would do, even if it worked, is turn the lights on. Third, lights don't turn on/off based on being 'active' or not. They aren't treated as entities, so you'll need to use the scripts to control them.

In your OnStart function, put this line. It is a for-loop which will turn off all of the lights.

for(int i=1;i<=6;i++) SetLightVisible("light_"+i, false);

Now you can work out the function to turn the lights on and off, and use that same line of script (changing the value of false as needed).


RE: Lights ON and OFF - asghdrew - 03-21-2012

(03-21-2012, 04:08 PM)palistov Wrote: A few things:

First, players cannot interact with lights in-game. You can script interactions through buttons or levers (like I'm guessing you're trying to do), but scripting a direct player interaction with a light (e.g. the player walks up and literally clicks on the light source) won't work. Second, the only thing your current script would do, even if it worked, is turn the lights on. Third, lights don't turn on/off based on being 'active' or not. They aren't treated as entities, so you'll need to use the scripts to control them.

In your OnStart function, put this line. It is a for-loop which will turn off all of the lights.

for(int i=1;i<=6;i++) SetLightVisible("light_"+i, false);

Now you can work out the function to turn the lights on and off, and use that same line of script (changing the value of false as needed).
Yes im using a button (switch)
which is attached in wall (its not a static object ,its an entity)
And what I need is that the lights at start of the game are Off not On.
Its like when I start the game (the switch which im suposed to press magicaly turns on by itself and the lights are on)
Il use the loop line and see if it works Smile





RE: Lights ON and OFF - Your Computer - 03-21-2012

Did you understand this? 'Cause it sounds like you didn't:

(03-21-2012, 04:08 PM)palistov Wrote: Third, lights don't turn on/off based on being 'active' or not. They aren't treated as entities, so you'll need to use the scripts to control them.

Also, use SetEntityConnectionStateChangeCallback not SetEntityPlayerInteractCallback.


RE: Lights ON and OFF - asghdrew - 03-22-2012

(03-21-2012, 09:44 PM)Your Computer Wrote: Did you understand this? 'Cause it sounds like you didn't:

(03-21-2012, 04:08 PM)palistov Wrote: Third, lights don't turn on/off based on being 'active' or not. They aren't treated as entities, so you'll need to use the scripts to control them.

Also, use SetEntityConnectionStateChangeCallback not SetEntityPlayerInteractCallback.
Okay I used SetEntityConnectionStateChangeCallback

This is what it looks like

//////////////////////////////////////////////////
void OnStart()

{
SetEntityConnectionStateChangeCallback( "lights", "lights_on");
for(int i=1;i<=6;i++) SetLightVisible("light_"+i, false);
}

//////////////////////////////////////////////////

void lights_on(string &in asEntity)
{
SetLightVisible("light_1", true);
SetLightVisible("light_2", true);
SetLightVisible("light_3", true);
SetLightVisible("light_4", true);
SetLightVisible("light_5", true);
SetLightVisible("light_6", true);
}

void lights_off(string &in asEntity)
{
SetLightVisible("light_1", false);
SetLightVisible("light_2", false);
SetLightVisible("light_3", false);
SetLightVisible("light_4", false);
SetLightVisible("light_5", false);
SetLightVisible("light_6", false);
}

/////////////////////////////////////////////////

I hope thats right...
Well anyways now when i start the game the lights are OFF (which im very happy with Big Grin)
BUT interacting with (lights) button , doesn't turn them on Sad
What am I doing wrong ?




RE: Lights ON and OFF - Your Computer - 03-22-2012

(03-22-2012, 11:34 AM)BlingBoyOto Wrote: What am I doing wrong ?

You lack understanding on how callbacks work and how to define them (though i'm inclined to say the same for functions in general). A callback is a function to be called when specific interactions or events occur. Each type of callback has their own syntax. You did not follow the required syntax for the callback, so the engine does not call the callback when the interaction occurs.


RE: Lights ON and OFF - asghdrew - 03-22-2012

(03-22-2012, 08:09 PM)Your Computer Wrote:
(03-22-2012, 11:34 AM)BlingBoyOto Wrote: What am I doing wrong ?

You lack understanding on how callbacks work and how to define them (though i'm inclined to say the same for functions in general). A callback is a function to be called when specific interactions or events occur. Each type of callback has their own syntax. You did not follow the required syntax for the callback, so the engine does not call the callback when the interaction occurs.
Right .
So im totally lost right now...
I don't know what commands do I need ?





RE: Lights ON and OFF - Your Computer - 03-22-2012

(03-22-2012, 08:40 PM)BlingBoyOto Wrote: I don't know what commands do I need ?

Read fully the description of SetEntityConnectionStateChangeCallback.



RE: Lights ON and OFF - asghdrew - 03-22-2012

(03-22-2012, 08:57 PM)Your Computer Wrote:
(03-22-2012, 08:40 PM)BlingBoyOto Wrote: I don't know what commands do I need ?

Read fully the description of SetEntityConnectionStateChangeCallback.
I still don't understand somehow

Do I need to change my void MyFunc
Or is SetEntityConnectionStateChangeCallback works different ?

I fell like a retard :/



RE: Lights ON and OFF - Your Computer - 03-22-2012

(03-22-2012, 09:02 PM)BlingBoyOto Wrote: I still don't understand somehow

Do I need to change my void MyFunc
Or is SetEntityConnectionStateChangeCallback works different ?

I fell like a retard :/

The second argument of SetEntityConnectionStateChangeCallback is the name of the function that is to be the callback set for the entity provided in the first argument. Did you pass in "MyFunc" to the second argument? No, you passed in "lights_on". However, the syntax for the callback function requires two parameters: one of type string and one of type int. Your current lights_on function only declares one parameter, which is of type string.