Frictional Games Forum (read-only)

Full Version: Need help with a script (again)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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)
you can just do

Code:
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
Yeah, I've got other boxes and areas. Just wanted to test with one first.
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 :

Code:
void OnStart ()
{
AddEntityCollideCallback("box2","area_blue","BOX1BLUE", false, 1);
}
and
Code:
void BOX1BLUE(string &in asParent, string &in asChild, int alState)
{
SetLightVisible("BluePointLight", true);
}
Yeah, sure but that doesn't solve the problem why the script doesn't work. Anyways, the bigger function would be more convenient.
maybe check the names
Been there, done that.
Could you test if it works
yes it works, i don't have to test it, i have many collision callbacks in my script
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);
}
}
It won't work, let me clarify it for you:

Code:
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:

Code:
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.
Pages: 1 2