Frictional Games Forum (read-only)
"if" remove message [Solved :D] - 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" remove message [Solved :D] (/thread-8342.html)



"if" remove message [Solved :D] - DannieWest - 05-30-2011

Searched the forum, and couldn't really find a thread to help me, neither could I fully understand the one on the wiki, so I hope maybe one of you guys can make me understand a bit more Undecided
So I've been trying to understand how "if" actually works, I know it's something with locked door got state 0 and unlocked like 1, and if it's 1 something happens, and 0 something else happens, but i have no clue how to script it, and where to put which line of code Confused

This is my script, and what I wanna do is remove the message after the door is unlocked :o
Spoiler below!
void OnStart()

{
if(ScriptDebugOn())
{
GiveItemFromFile("lantern", "lantern.ent");
SetPlayerLampOil(100.0f);

for(int i = 0;i < 10;i++)
{
GiveItemFromFile("tinderbox", "tinderbox.ent");
}
}
AddUseItemCallback("", "Honey", "mansion_1", "UsedHoneyOnDoor", true);
AddEntityCollideCallback("Player", "ScriptArea_1", "TriggerFunction", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_2", "Ragdoll", true, 1);
SetEntityPlayerInteractCallback("mansion_1", "LockedDoor", false);
}

void LockedDoor(string &in entity)
{
SetMessage("TestStory", "ItemDesc_mansion_1", 0);
}

void UsedHoneyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "mansion_1", 0.0f, true);
RemoveItem("Honey");
}



RE: "if" remove message - Apjjm - 05-30-2011

Code:
void OnStart()
{
    SetLocalVarInt("DoorUnlocked",0); //Say door is locked
    if(ScriptDebugOn())
    {
        GiveItemFromFile("lantern", "lantern.ent");
        SetPlayerLampOil(100.0f);

        for(int i = 0;i < 10;i++)
        {
              GiveItemFromFile("tinderbox", "tinderbox.ent");
        }
    }
}

void UsedHoneyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("mansion_1", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "mansion_1", 0.0f, true);
    RemoveItem("Honey");
    SetLocalVarInt("DoorUnlocked",1); //Say door is unlocked
}

void LockedDoor(string &in entity)
{
    if(GetLocalVarInt("DoorUnlocked")==0)
         { //If door is locked, display the message.
           SetMessage("TestStory", "ItemDesc_mansion_1", 0);
         }
}



RE: "if" remove message - Kyle - 05-30-2011

Oh, this is easy because I did the exact same kind of script. :p

This is what mine looked like:

Code:
void OnStart()
{
     SetEntityPlayerInteractCallback("prison_1", "LockedHint", false);
}
void LockedHint(string &in asEntity)
{
     if (GetSwingDoorLocked(asEntity) == true)
     {
          SetMessage("Message", "Hint02", 3);
          return;
     }
}

So when the player interacts with the door, display the "Locked Door" message only IF the door is locked, and if it isn't locked, it will do nothing when interacted. Smile


RE: "if" remove message - DannieWest - 05-30-2011

Thanks alot Big Grin (To both of you x))
I wonder though, Apjjm, do it have to be named DoorUnlocked, or is that just a name so you know what you're doing?

And for Kyle, what does the "return;" do? o.O


RE: "if" remove message - Kyle - 05-30-2011

The "return" is used to return out of it, going back to void LockedHint(string &in asEntity).

It is mostly used to make sure that "if" statements work when using multiple "if" statements.

For example:

Code:
void OnStart()
{
     SetEntityPlayerInteractCallback("prison_1", "LockedHint", false);
}
void LockedHint(string &in asEntity)
{
     if (GetSwingDoorLocked(asEntity) == true)
     {
          [whatever in here]
          return;
     }
     else if (GetSwingDoorLocked(asEntity) == false)
     {
          [whatever in here]
          return;
     }
}



RE: "if" remove message - Apjjm - 05-30-2011

(05-30-2011, 04:13 PM)DannieWest Wrote: Thanks alot Big Grin (To both of you x))
I wonder though, Apjjm, do it have to be named DoorUnlocked, or is that just a name so you know what you're doing?

You have to give the variable a name, in this case it was called "DoorUnlocked" as that both made sense and was unique. Kyles method is the better option for you to use in this case though.

The return statement will actually return out of that function at that point in the code, which can be used to stop the code executing further on a certain condition (though the same effect is provided by the "else" construct).


RE: "if" remove message - DannieWest - 05-30-2011

Ahaa, I c Tongue Haha, it's great to have a forum with people like you in it ^^