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 How to make a function run from other functions.
JSimoes Offline
Junior Member

Posts: 2
Threads: 1
Joined: Nov 2013
Reputation: 0
#1
How to make a function run from other functions.

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.

//////////
//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.
}
02-02-2014, 01:39 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#2
RE: How to make a function run from other functions.

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.

Trying is the first step to success.
02-02-2014, 04:08 PM
Find
JSimoes Offline
Junior Member

Posts: 2
Threads: 1
Joined: Nov 2013
Reputation: 0
#3
RE: How to make a function run from other functions.

Oh thanks! the () after the function name was all i was missing!
It is working now. Big Grin
02-02-2014, 04:44 PM
Find




Users browsing this thread: 4 Guest(s)