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 Lights ON and OFF
asghdrew Offline
Member

Posts: 138
Threads: 10
Joined: Mar 2012
Reputation: 7
#1
Information  Lights ON and OFF

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

lol noobs
03-21-2012, 03:57 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#2
RE: Lights ON and OFF

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

(This post was last modified: 03-21-2012, 04:09 PM by palistov.)
03-21-2012, 04:08 PM
Find
asghdrew Offline
Member

Posts: 138
Threads: 10
Joined: Mar 2012
Reputation: 7
#3
RE: Lights ON and OFF

(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



lol noobs
03-21-2012, 04:27 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#4
RE: Lights ON and OFF

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.

Tutorials: From Noob to Pro
03-21-2012, 09:44 PM
Website Find
asghdrew Offline
Member

Posts: 138
Threads: 10
Joined: Mar 2012
Reputation: 7
#5
RE: Lights ON and OFF

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


lol noobs
(This post was last modified: 03-22-2012, 02:04 PM by asghdrew.)
03-22-2012, 11:34 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#6
RE: Lights ON and OFF

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

Tutorials: From Noob to Pro
03-22-2012, 08:09 PM
Website Find
asghdrew Offline
Member

Posts: 138
Threads: 10
Joined: Mar 2012
Reputation: 7
#7
RE: Lights ON and OFF

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



lol noobs
03-22-2012, 08:40 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#8
RE: Lights ON and OFF

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

Read fully the description of SetEntityConnectionStateChangeCallback.

Tutorials: From Noob to Pro
03-22-2012, 08:57 PM
Website Find
asghdrew Offline
Member

Posts: 138
Threads: 10
Joined: Mar 2012
Reputation: 7
#9
RE: Lights ON and OFF

(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 :/

lol noobs
03-22-2012, 09:02 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#10
RE: Lights ON and OFF

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

Tutorials: From Noob to Pro
03-22-2012, 09:41 PM
Website Find




Users browsing this thread: 1 Guest(s)