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
On and off light.
gabiaef Offline
Junior Member

Posts: 4
Threads: 1
Joined: Jul 2012
Reputation: 0
#1
On and off light.

Hello! I come here for a code.
sorry if this is not well understood English ... that I speak Spanish and am using the translator
I hope you understand me

I want prener a light with a button or area (same for me) and off (like a switch). This time it was with a book by touching an area comprising a light.

But I have a problem. Achievement on and off the light but after aver done this. no light turns back on, it's like only use the script only once I leave here.


void OnStart()
{
SetLocalVarInt("Var0", 0);
SetLocalVarInt("Var1", 0);
AddEntityCollideCallback("B0", "A0A", "Prender0", true, 1);
AddEntityCollideCallback("B1", "A1A", "Prender1", true, 1);
AddEntityCollideCallback("B0", "D0", "Desactivo0", true, 1);
AddEntityCollideCallback("B1", "D1", "Desactivo1", true, 1);

}

void Desactivo0(string &in asParent, string &in asChild, int alState)
{
SetLocalVarInt("Var0", 0);


}
void Desactivo1(string &in asParent, string &in asChild, int alState)
{
SetLocalVarInt("Var1", 0);



}

void Prender1(string &in asParent, string &in asChild, int alState)
{
AddLocalVarInt("Var1", 1);
if(GetLocalVarInt("Var1") == 1)
{

SetLampLit("l1", false, false);
SetLampLit("l2", false, false);
SetLampLit("l3", false, false);
SetLampLit("l4", false, false);
SetLampLit("l5", false, false);
SetLampLit("l6", false, false);
SetLampLit("l7", false, false);
SetLampLit("l8", false, false);
SetLampLit("l9", false, false);
SetLampLit("l10", false, false);
SetLampLit("l11", false, false);
SetLampLit("l12", false, false);
SetLampLit("l13", false, false);
SetLampLit("l14", false, false);
SetLampLit("l15", false, false);
SetLampLit("l16", false, false);
SetLampLit("l17", false, false);
SetLampLit("l18", false, false);
SetLampLit("l19", false, false);
SetLampLit("l20", false, false);

SetLampLit("l16", true, true);
SetLampLit("l12", true, true);
SetLampLit("l8", true, true);
SetLampLit("l4", true, true);
SetLampLit("l20", true, true);
}

}
void Prender0(string &in asParent, string &in asChild, int alState)
{
AddLocalVarInt("Var0", 1);
if(GetLocalVarInt("Var0") == 1)
{
SetLampLit("l1", false, false);
SetLampLit("l2", false, false);
SetLampLit("l3", false, false);
SetLampLit("l4", false, false);
SetLampLit("l5", false, false);
SetLampLit("l6", false, false);
SetLampLit("l7", false, false);
SetLampLit("l8", false, false);
SetLampLit("l9", false, false);
SetLampLit("l10", false, false);
SetLampLit("l11", false, false);
SetLampLit("l12", false, false);
SetLampLit("l13", false, false);
SetLampLit("l14", false, false);
SetLampLit("l15", false, false);
SetLampLit("l16", false, false);
SetLampLit("l17", false, false);
SetLampLit("l18", false, false);
SetLampLit("l19", false, false);
SetLampLit("l20", false, false);

SetLampLit("l1", true, true);
SetLampLit("l2", true, true);
SetLampLit("l3", true, true);
SetLampLit("l4", true, true);
SetLampLit("l5", true, true);
SetLampLit("l9", true, true);
SetLampLit("l13", true, true);
SetLampLit("l17", true, true);
SetLampLit("l20", true, true);
SetLampLit("l16", true, true);
SetLampLit("l12", true, true);
SetLampLit("l8", true, true);
SetLampLit("l18", true, true);
SetLampLit("l19", true, true);

}

}
hopefully can give me the solution Thanks.
(This post was last modified: 07-16-2012, 11:33 PM by gabiaef.)
07-15-2012, 11:04 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: On and off light.

If you want it to happen multiple times, you need to pass in false to AddEntityCollideCallback. Though, you're probably using script areas for a switch or lever, which would be the wrong way of checking which direction the switch was pulled.

Tutorials: From Noob to Pro
07-15-2012, 11:22 PM
Website Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#3
RE: On and off light.

So basically what you want is to make a lightswitch?
If so, I'll post a solution in a few minutes.

[Image: 18694.png]
07-15-2012, 11:23 PM
Find
gabiaef Offline
Junior Member

Posts: 4
Threads: 1
Joined: Jul 2012
Reputation: 0
#4
RE: On and off light.

(07-15-2012, 11:23 PM)Ongka Wrote: So basically what you want is to make a lightswitch?
If so, I'll post a solution in a few minutes.
I would help a lot if you could do that also I will try the first way I said

Thanks!
07-15-2012, 11:30 PM
Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#5
RE: On and off light.

You want to turn all lights on and off with one switch right?

[Image: 18694.png]
07-15-2012, 11:46 PM
Find
gabiaef Offline
Junior Member

Posts: 4
Threads: 1
Joined: Jul 2012
Reputation: 0
#6
RE: On and off light.

(07-15-2012, 11:46 PM)Ongka Wrote: You want to turn all lights on and off with one switch right?

Yes.
Only it would be enough to know how to operate a switch that can turn on and off a light infinitely.
07-15-2012, 11:59 PM
Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#7
RE: On and off light.

Create a lever, doesn't matter which one.
Set the configuration of the lever like shown in the image.
[Image: Qw2NX.jpg]


Put this into your script:
void LightSwitch(string &in asEntity, int alState)
{
    if(alState == 1){
    
        for(int i=1;i<=20;i++)  //Change the 20 to any number you want, e.g. 10, this will cause only the first 10 to be lit/unlit
        {
        SetLampLit("l"+i, false, true);
        }

    }
    else if(alState == -1){
        for(int i=1;i<=20;i++)  //Change the 20 to any number you want, e.g. 10, this will cause only the first 10 to be lit/unlit
        {
        SetLampLit("l"+i, true, true);
        }
    }
}

By moving the lever up the lamps get lit and by moving down they get unlit.
Works infinite times.

Have fun! Wink

[Image: 18694.png]
(This post was last modified: 07-16-2012, 01:22 AM by Ongka.)
07-16-2012, 01:15 AM
Find
gabiaef Offline
Junior Member

Posts: 4
Threads: 1
Joined: Jul 2012
Reputation: 0
#8
RE: On and off light.

(07-16-2012, 01:15 AM)Ongka Wrote: Create a lever, doesn't matter which one.
Set the configuration of the lever like shown in the image.
[Image: Qw2NX.jpg]


Put this into your script:
void LightSwitch(string &in asEntity, int alState)
{
    if(alState == 1){
    
        for(int i=1;i<=20;i++)  //Change the 20 to any number you want, e.g. 10, this will cause only the first 10 to be lit/unlit
        {
        SetLampLit("l"+i, false, true);
        }

    }
    else if(alState == -1){
        for(int i=1;i<=20;i++)  //Change the 20 to any number you want, e.g. 10, this will cause only the first 10 to be lit/unlit
        {
        SetLampLit("l"+i, true, true);
        }
    }
}

By moving the lever up the lamps get lit and by moving down they get unlit.
Works infinite times.

Have fun! Wink
Thank you very much! Did not know recently started with this.
07-16-2012, 01:45 AM
Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#9
RE: On and off light.

So did it work?
It may be hard in the beginning, but you'll learn to do this stuff by yourself step by step.

[Image: 18694.png]
07-16-2012, 01:51 AM
Find




Users browsing this thread: 2 Guest(s)