Frictional Games Forum (read-only)

Full Version: if & else URGENT! PLZ!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello peoples,

I wanted to know is there such features in angle script (the one to code Amnesia and custom stories) like 'if' and 'else' because I was going to do a bit in my level where you pull a lever and if a variable = 0 then a message will appear otherwise a door will unlock.

How would I set my script to detect if my var is 0 and show a message or 1 and unlock a door?

I hope that you can help Big Grin

EDIT:
Code:
void used1(string &in asParent, string &in asChild, int alState)
{
    if
    AddLocalVarInt("door1", 0);
    SetMessage("Message", "used1", 3);
    
    else
    //Something
    
}
Code:
void OnStart(){
    SetLocalVarInt("Lev", 1);
    SetEntityConnectionStateChangeCallback("Lever1", "L1");
    SetEntityConnectionStateChangeCallback("Lever2", "L2");
}

void L1(string &in asEntity, int alState)
{
     if (GetLeverState("Lever1") == 1)
     {
    SetEntityActive("ScriptArea_6", true);
    SetEntityActive("ScriptArea_4", true);
    SetLeverStuckState("Lever1", 1, true);
     }
}

void L2(string &in asEntity, int alState)
{
     if (GetLeverState("Lever2") == 1)
     {
          SetSwingDoorLocked("KeyStudyDoor", false, true);
      SetEntityActive("PrisonDoor", false);
          SetLeverStuckState("Lever2", 1, true);
     }
}
This is the code I used in my custom story to get my levers to work. I hope you'll be able to use it. If you want it to show the other message, I think you'll have to add something like this.

Code:
void L2(string &in asEntity, int alState)
{
     if (GetLeverState("Lever2") == 1)
     {
          SetSwingDoorLocked("KeyStudyDoor", false, true);
      SetEntityActive("PrisonDoor", false);
          SetLeverStuckState("Lever2", 1, true);
     }
     else {
         if (GetLeverState("Lever2")==0)
         {
             SetMessage("Message", "used1", 3);
          }
     }
}
If the lever is pulled, have the interaction call back set a global variable to 1.

SetGlobalVarInt(string& asName, int alVal);

Then have the callback area, timer, etc to check the global variable.

GetLocalVarInt(string& asName);

Example for checking the global variable from an area


Code:
void Checking(string &in asParent, string &in asChild, int alState)
{
     if(GetGlobalVarInt("Variable")==1
     {
     //Insert commands here if variable = 1
     }

     else
     {
     //Insert commands here if variable does not = 1
     }
}

Someone correct me if I'm wrong.
Never mind it was my script