Frictional Games Forum (read-only)

Full Version: How to make a function run from other functions.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, i will try to explain myself in few words:
I am trying to make a function A run from several other functions, so if i edit function A, i will be editing what happens when function B, C, and D are triggered.

This is how my code looks ATM and it doesnt give me any error, so while i have an idea what is wrong in it, i dont know exactly what.

Code:
//////////
//Declare Variables
bool red = false; //light1
bool green = false; //light2
bool blue = false; //light3

void OnEnter()
{
}

//////////
//Script that runs first time that player enters the map.
void OnStart()
{
    SetLightVisible("light", false);
    SetLightVisible("light2", false);
    SetLightVisible("light3", false);
    SetEntityConnectionStateChangeCallback("leverobj", "leverfunc");
    SetEntityConnectionStateChangeCallback("leverobj2", "leverfunc2");
    SetEntityConnectionStateChangeCallback("leverobj3", "leverfunc3");
    SetEntityPlayerInteractCallback("concluir", "conclusao", false);
}

//////////////////////////////////////////////////////////////////////////
// Function that i am trying to run from other functions, this is where the error probably is!!!
////////////////////////////////////////////////////////////////////////////
void updatelocks()
{
    PlaySoundAtEntity("", "enabled.snt", "Player", 0, true); // Just a random sound so i can test if it is working
}

//////////
//Script for red light lever.
void leverfunc(string &in asEntity, int alState)
{
     if (alState == -1)
     {
     PlaySoundAtEntity("", "19_attach_needle.ogg", "player", 0, false);
     SetLightVisible("light", true);
     red = true; //light1
     }
     else if (alState == 1)
    {
    SetLightVisible("light", false);
    red = false; //light1
    }
/////////////////////////////////////////////////////////////////////
    updatelocks; //My attempt to make a function run from another, this could be also where the error is!!!!!
////////////////////////////////////////////////////////////////////
}

//////////
//Script that runs for the green lever
void leverfunc2(string &in asEntity, int alState)
{
     if (alState == -1)
     {
     PlaySoundAtEntity("", "19_attach_needle.ogg", "player", 0, false);
     SetLightVisible("light2", true);
     green = true; //light2
          return;
     }
     else if (alState == 1)
    {
    SetLightVisible("light2", false);
    green = false; //light3
    }
    updatelocks; //Explained above
}

//////////
//Script that runs on the blue lever
void leverfunc3(string &in asEntity, int alState)
{
     if (alState == -1)
     {
     PlaySoundAtEntity("", "19_attach_needle.ogg", "player", 0, false);
     SetLightVisible("light3", true);
     bool blue = true; //light3
          return;
     }
     else if (alState == 1)
    {
    SetLightVisible("light3", false);
    bool blue = false; //light3
    }
    updatelocks; //Explained above.
}
How about just:

void A()
{

}

void B()
{

}

void C()
{

}

void D()
{

}

Now just edit them.

To call them use:


void CallFunctions()
{
A();
B();
C();
D();
}

I think that's how it works.
Oh thanks! the () after the function name was all i was missing!
It is working now. Big Grin