Frictional Games Forum (read-only)
[CHAOS] Setting up the elevator machine - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [CHAOS] Setting up the elevator machine (/thread-21426.html)

Pages: 1 2 3


RE: Setting up the elevator machine - Tomato Cat - 05-09-2013

How about a combination of both?

Like you were saying, you can check the state (the alState parameter) that the lever without having to lock it in place by doing something similar to this:

PHP Code:
void LeverFunction(parameters etcetc//This is the function that is called when you pull the lever
{

   if(
alState == 1//Experiment with "1" & "-1". I think 1 is up, and -1 is down.
   
{
      
//Code to do here if the lever is pulled to the aforementioned state
   
}



However, you don't want the machine to start if the repairs aren't complete! To solve this, we'll need some code in the lever function will check if everything is complete.

Do you remember how we set those local integers? "Coal" and "Cogs?" We can use them to see if the machine's repairs are finished:

PHP Code:
void leverfunction blahblah //Lever callback, sorry for my shorthand =p
{
   if(
alState == 1//This checks if the lever is pulled
   
{
     
      
//If it is pulled, checks if repairs are complete
      
if(GetLocalVarInt("Coal") == &&  GetLocalVarInt("Cogs") == 3)
      {
         
//This block is executed if everything is complete
         //Run your machine startup routine here
      
}

      else
      {
        
//This block executes if something isn't finished
       
}
   }


I hope it gives you a general idea. Adjust it to your liking!


RE: Setting up the elevator machine - serbusfish - 05-09-2013

I'm just about ready to cry at this!

The main problem im facing is if I move frictional's part of the script to the onstart section it throws up errors and wont load, but leaving it where it is means your solutions cant be implemented (unless im doing it wrong?).

Code:
void PullStartLever(string &in asEntity, int alState)
{
if(alState == -1) AddDebugMessage("Lever Min", false);
else if (alState == 1) StartMachine(asEntity);
}
/*If all settings correct start the machine, if not do a hickup start
*/
void StartMachine(string sEntity)
{
PlaySoundAtEntity("s1"+sEntity, "13_ignite", sEntity, 0.2f, false);
PlaySoundAtEntity("s2"+sEntity, "13_machine_fail", sEntity, 0.2f, false);

if(GetLocalVarInt("WheelOK") == 3 && GetLocalVarInt("Coal") == 3)

PullStartLever in this case is linked to the main machine lever, when it is pulled it does the Var checks, somewhere in here I need another check for the other lever. Perhaps im missing something obvious but I just cant get it working. I tried adding this before the PullStartLever command:

Code:
void PullCoalLever(string &in asEntity, int alState)

{
if(alState == 1) AddLocalVarInt("LeverOn", 1);
}

but this just stops the machine from starting even if the burner is running. I guess in this case im using the AddLocalVarInt command wrong?


RE: Setting up the elevator machine - PutraenusAlivius - 05-09-2013

(05-09-2013, 04:37 PM)serbusfish Wrote: I'm just about ready to cry at this!

The main problem im facing is if I move frictional's part of the script to the onstart section it throws up errors and wont load, but leaving it where it is means your solutions cant be implemented (unless im doing it wrong?).

Code:
void PullStartLever(string &in asEntity, int alState)
{
if(alState == -1) AddDebugMessage("Lever Min", false);
else if (alState == 1) StartMachine(asEntity);
}
/*If all settings correct start the machine, if not do a hickup start
*/
void StartMachine(string sEntity)
{
PlaySoundAtEntity("s1"+sEntity, "13_ignite", sEntity, 0.2f, false);
PlaySoundAtEntity("s2"+sEntity, "13_machine_fail", sEntity, 0.2f, false);

if(GetLocalVarInt("WheelOK") == 3 && GetLocalVarInt("Coal") == 3)

PullStartLever in this case is linked to the main machine lever, when it is pulled it does the Var checks, somewhere in here I need another check for the other lever. Perhaps im missing something obvious but I just cant get it working. I tried adding this before the PullStartLever command:

Code:
void PullCoalLever(string &in asEntity, int alState)

{
if(alState == 1) AddLocalVarInt("LeverOn", 1);
}

but this just stops the machine from starting even if the burner is running. I guess in this case im using the AddLocalVarInt command wrong?
Code:
void PullCoalLever(string &in asEntity, int alState)
{
if(alState == 1)
{
AddLocalVarInt("LeverOn", 1);
}
}



RE: Setting up the elevator machine - Tomato Cat - 05-09-2013

Just forget about FG's script and focus on building your own. Believe me, it's easier because you'll know precisely what's going.

I actually forgot about the coal lever. Instead of the elevator lever, the coal lever should check if the "Coal" variable is equal to 3.

Modify it like so:

PHP Code:
void PullCoalLever(string &in asEntityint alState)

{
   if(
alState == 1//Executed if the lever is pulled
   
{
       if(
GetLocalVarInt("Coal") == 3)) //Checks to see if all coal is inside
       

         
AddLocalVarInt("LeverOn"1); //This is what we'll check when we pull the elevator starting lever
        
}
    }


Ok, now the elevator lever will check if LeverOn is equal to 1.

PHP Code:
void ElevatorStartFunction(parameters)
{
   if(
alState == 1//Executed if the lever is pulled
   
{
     
      
//If it is pulled, checks if repairs are complete
      
if(GetLocalVarInt("LeverOn") == &&  GetLocalVarInt("Cogs") == 3)
      {
         
//This block is executed if everything is complete
         //Run your machine startup routine here
      
}

      else
      {
        
//This block executes if something isn't finished
       
}
   }


That should fix it, given you've declared your callbacks/variables. Unless this isn't the issue you're having. ~.o


RE: Setting up the elevator machine - serbusfish - 05-09-2013

(05-09-2013, 05:24 PM)Tomato Cat Wrote: Just forget about FG's script and focus on building your own. Believe me, it's easier because you'll know precisely what's going.

I actually forgot about the coal lever. Instead of the elevator lever, the coal lever should check if the "Coal" variable is equal to 3.

Modify it like so:

PHP Code:
void PullCoalLever(string &in asEntityint alState)

{
   if(
alState == 1//Executed if the lever is pulled
   
{
       if(
GetLocalVarInt("Coal") == 3)) //Checks to see if all coal is inside
       

         
AddLocalVarInt("LeverOn"1); //This is what we'll check when we pull the elevator starting lever
        
}
    }


Ok, now the elevator lever will check if LeverOn is equal to 1.

PHP Code:
void ElevatorStartFunction(parameters)
{
   if(
alState == 1//Executed if the lever is pulled
   
{
     
      
//If it is pulled, checks if repairs are complete
      
if(GetLocalVarInt("LeverOn") == &&  GetLocalVarInt("Cogs") == 3)
      {
         
//This block is executed if everything is complete
         //Run your machine startup routine here
      
}

      else
      {
        
//This block executes if something isn't finished
       
}
   }


That should fix it, given you've declared your callbacks/variables. Unless this isn't the issue you're having. ~.o

Yes you're right, I wanted to stick with it because apart from that one little detail it works as intended.

I will strip it out and build my own, hopefully I will get it working ok Tongue


RE: Setting up the elevator machine - serbusfish - 05-10-2013

Btw as im thinking about it, when in game on Frictional's level the coal pieces are black, but in mine they are red, how do they manage this as in the editor for both they are red?


RE: Setting up the elevator machine - PutraenusAlivius - 05-10-2013

(05-10-2013, 12:53 AM)serbusfish Wrote: Btw as im thinking about it, when in game on Frictional's level the coal pieces are black, but in mine they are red, how do they manage this as in the editor for both they are red?

The coal are both red.