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
Need help with a script (again)
Akasu Offline
Member

Posts: 62
Threads: 6
Joined: Aug 2010
Reputation: 2
#1
Need help with a script (again)

I've been trying to get this script to work for 2 hours now with no luck.
It should make a light visible when a box is in the right place and make it invisible when it's not in place.

void OnStart ()
{
AddEntityCollideCallback("box1","area_red","BOX1RED", false, 1);
}

// Is this right? : "box1" is the object that should collide with the "area_red", "BOX1RED" is the script it runs when collided, "false" makes the script re-runnable, and "1" means that the "BOX1RED" runs on collide (-1 runs when they're not colliding)


void BOX1RED(string &in asParent, string &in asChild, int alState)
{if(asChild == "area_red") {
SetLightVisible("redy", true);
// "redy" is a pointlight
}
else SetLightVisible("redy", false);
}

I copied it from one of the main maps' scripts but it won't work. It simply does nothing (doesn't crash though)
09-22-2010, 08:03 PM
Find
gosseyn Offline
Member

Posts: 63
Threads: 7
Joined: Sep 2010
Reputation: 1
#2
RE: Need help with a script (again)

you can just do

void BOX1RED(string &in asParent, string &in asChild, int alState)
{
SetLightVisible("redy", true);
}

unless you have other boxes that needs colliding with the same area
09-22-2010, 08:11 PM
Find
Akasu Offline
Member

Posts: 62
Threads: 6
Joined: Aug 2010
Reputation: 2
#3
RE: Need help with a script (again)

Yeah, I've got other boxes and areas. Just wanted to test with one first.
09-22-2010, 08:17 PM
Find
gosseyn Offline
Member

Posts: 63
Threads: 7
Joined: Sep 2010
Reputation: 1
#4
RE: Need help with a script (again)

i mean, you can do as i told you, unless you want to handle all collisions inside one big function. But you can also make one function for each collision

example, blue box and blue light :

void OnStart ()
{
AddEntityCollideCallback("box2","area_blue","BOX1BLUE", false, 1);
}
and
void BOX1BLUE(string &in asParent, string &in asChild, int alState)
{
SetLightVisible("BluePointLight", true);
}
09-22-2010, 08:23 PM
Find
Akasu Offline
Member

Posts: 62
Threads: 6
Joined: Aug 2010
Reputation: 2
#5
RE: Need help with a script (again)

Yeah, sure but that doesn't solve the problem why the script doesn't work. Anyways, the bigger function would be more convenient.
09-22-2010, 08:32 PM
Find
gosseyn Offline
Member

Posts: 63
Threads: 7
Joined: Sep 2010
Reputation: 1
#6
RE: Need help with a script (again)

maybe check the names
09-22-2010, 08:35 PM
Find
Akasu Offline
Member

Posts: 62
Threads: 6
Joined: Aug 2010
Reputation: 2
#7
RE: Need help with a script (again)

Been there, done that.
Could you test if it works
09-22-2010, 08:38 PM
Find
gosseyn Offline
Member

Posts: 63
Threads: 7
Joined: Sep 2010
Reputation: 1
#8
RE: Need help with a script (again)

yes it works, i don't have to test it, i have many collision callbacks in my script
09-22-2010, 08:47 PM
Find
Akasu Offline
Member

Posts: 62
Threads: 6
Joined: Aug 2010
Reputation: 2
#9
RE: Need help with a script (again)

Now it lights up but doesn't switch off when the box is removed.. Help?

void OnStart ()
{
SetLightVisible("redy", false);

AddEntityCollideCallback("box1","area_red","BOX1RED", false, 1);
}

void BOX1RED(string &in asParent, string &in asChild, int alState)
{if(asChild == "area_red") {
SetLightVisible("redy", true);
}
else if (asChild != "area_red"){
SetLightVisible("redy", false);
}
}
09-22-2010, 09:05 PM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#10
RE: Need help with a script (again)

It won't work, let me clarify it for you:

void OnStart ()
{
AddEntityCollideCallback("box1","area_red","BOX1RED", false, 1);
}

void BOX1RED(string &in asParent, string &in asChild, int alState)
{if(asChild == "area_red") {
SetLightVisible("redy", true);
// "redy" is a pointlight
}
else SetLightVisible("redy", false);
}

1. the alState in AddEntityCollideCallback doesn't mean - "1" means that the "BOX1RED" runs on collide (-1 runs when they're not colliding) - it means alStates = 1=only call when entity enters, -1=only call when entity leaves 0=both
2. a solution to your problem I can think of is:

void OnStart ()
{
AddEntityCollideCallback("box1","area_red","BOX1RED", false, 0);
SetLocalVarInt("RedLightOn", 1);
}

void BOX1RED(string &in asParent, string &in asChild, int alState)
{
//Why this? Do you want to trigger this function from multiple areas? If not, remove it.
if(asChild == "area_red") {
if(GetLocalVarInt("RedLightOn") == 1) SetLocalVarInt("RedLightOn", 0);
else SetLocalVarInt("RedLightOn", 1);

if(GetLocalVarInt("RedLightOn") == 1) SetLightVisible("redy", true);
else SetLightVisible("redy", false);
}
}

Could have made the script much easier if the game had local booleans though.

09-22-2010, 09:12 PM
Find




Users browsing this thread: 1 Guest(s)