Frictional Games Forum (read-only)
if & else URGENT! PLZ! - 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 (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: if & else URGENT! PLZ! (/thread-8161.html)



if & else URGENT! PLZ! - X4anco - 05-21-2011

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
    
}



RE: if & else URGENT! PLZ! - Karai16 - 05-21-2011

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);
          }
     }
}



RE: if & else URGENT! PLZ! - Russ Money - 05-21-2011

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.


RE: if & else URGENT! PLZ! - X4anco - 05-21-2011

Never mind it was my script