Facebook Twitter YouTube Frictional Games | Forum | Newsletter | Dev Blog | Dev Wiki | Support | Gametee


Post Reply 
 
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"if" remove message [Solved :D]
Author Message
DannieWest Offline
Member

Posts: 156
Joined: Apr 2011
Reputation: 0
Post: #1
"if" remove message [Solved :D]

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");
}
(This post was last modified: 06-28-2011 12:36 AM by DannieWest.)
05-30-2011 02:34 PM
Find all posts by this user Quote this message in a reply
Apjjm Offline
Is easy to say

Posts: 494
Joined: Apr 2011
Reputation: 51
Post: #2
RE: "if" remove message

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

05-30-2011 02:56 PM
Find all posts by this user Quote this message in a reply
Kyle Offline
Posting Freak

Posts: 911
Joined: Sep 2010
Reputation: 7
Post: #3
RE: "if" remove message

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

This is what mine looked like:

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

(This post was last modified: 05-30-2011 03:00 PM by Kyle.)
05-30-2011 02:57 PM
Find all posts by this user Quote this message in a reply
DannieWest Offline
Member

Posts: 156
Joined: Apr 2011
Reputation: 0
Post: #4
RE: "if" remove message

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
(This post was last modified: 05-30-2011 04:13 PM by DannieWest.)
05-30-2011 04:13 PM
Find all posts by this user Quote this message in a reply
Kyle Offline
Posting Freak

Posts: 911
Joined: Sep 2010
Reputation: 7
Post: #5
RE: "if" remove message

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:

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

05-30-2011 04:53 PM
Find all posts by this user Quote this message in a reply
Apjjm Offline
Is easy to say

Posts: 494
Joined: Apr 2011
Reputation: 51
Post: #6
RE: "if" remove message

(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).

(This post was last modified: 05-30-2011 05:24 PM by Apjjm.)
05-30-2011 05:19 PM
Find all posts by this user Quote this message in a reply
DannieWest Offline
Member

Posts: 156
Joined: Apr 2011
Reputation: 0
Post: #7
RE: "if" remove message

Ahaa, I c Tongue Haha, it's great to have a forum with people like you in it ^^
05-30-2011 10:00 PM
Find all posts by this user Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)