Frictional Games Forum (read-only)

Full Version: I'm back, with a new custom story and another question! [SOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys! I'm back after some time of not being here! ^^
I'm working on another custom story at the moment, but I'm facing some problems. You see:
Code:
void OnStart()
{
    SetEntityPlayerInteractCallback("OutsideDoor", "Checking", true);
    AddEntityCollideCallback("Player", "ScriptArea_1", "Checking2", true, 1);
}

void Checking(string &in asEntity)
{
    if (HasItem("Lantern")!=true)
    {
        SetMessage("Message", "OutsideDoorText", 0);
    }
}

void Checking2(string &in asParent , string &in asChild , int alState)
{
    if (HasItem("Lantern")==true)
    {
            SetLevelDoorLocked("OutsideDoor", false);
    }
}
This is the code of the Hallway. You can't go through a certain door as long as you don't have your lantern, which is in the bedroom. The lantern's called "Lantern". I've tested it, also with it just trying to play music instead of opening the door, but for some reason, it keeps saying that the second if statement is false, even if you have the lantern... can you help me out? I'm at a loss
Huh
HasItem("Lantern") == true

== true is unneeded here, as HasItem function is a boolean function.

This happened to someone else too. So, how about unlocking the level door on lantern pickup instead of checking if player has it?
(07-25-2011, 06:38 PM)Tanshaydar Wrote: [ -> ]HasItem("Lantern") == true

== true is unneeded here, as HasItem function is a boolean function.

This happened to someone else too. So, how about unlocking the level door on lantern pickup instead of checking if player has it?

Well you see, lantern is picked up in another map, So that's why I can't unlock that door yet. But if there is a way, I'm all ears ofcourse.
I found a workaround when i ran into this problem

if(HasItem("Lantern")){}
else{
// Unlock door
}

Smile
(07-25-2011, 11:11 PM)DRedshot Wrote: [ -> ]I found a workaround when i ran into this problem

if(HasItem("Lantern")){}
else{
// Unlock door
}

Smile

Well the thing is, the door has to unlock when you do have the lantern. Also, I've tried something simular before, but it doesn't work either.
ok, I dont fully understand what you're trying to do. If you want the door to unlock when you do have the lantern, this should work:

if(HasItem("Lantern")){
// Unlock Door
}

if that doesn't work, you may not have called it Lantern.
When you pick up the lantern in map 1, set a global variable to 1 and check if that variable is 1 when you click on the door.
(07-25-2011, 11:51 PM)Roenlond Wrote: [ -> ]When you pick up the lantern in map 1, set a global variable to 1 and check if that variable is 1 when you click on the door.

Okay, I did that, but it still won't open the door... Here are the scripts:

Hallway: (The map where the game starts (atm) and where the door is that needs to be unlocked)
Code:
void OnGameStart()
{
    SetGlobalVarInt("LanternVar", 1);
}

void OnStart()
{
    SetEntityPlayerInteractCallback("OutsideDoor", "Checking", true);
    AddEntityCollideCallback("Player", "ScriptArea_1", "Checking2", true, 1);
}

void Checking(string &in asEntity)
{
    if (GetGlobalVarInt("LanternVar") != 2)
    {
        SetMessage("Message", "OutsideDoorText", 0);
    }
}

void Checking2(string &in asParent , string &in asChild , int alState)
{
    if (GetGlobalVarInt("LanternVar") == 2)
    {
            SetLevelDoorLocked("OutsideDoor", false);
    }
}

Bedroom: (The map where you get the lantern)
Code:
void OnStart()
{
    SetEntityPlayerInteractCallback("Lantern", "Setvar", true);
}

void Setvar(string &in asEntity)
{
    AddGlobalVarInt("LanternVar", 1);
}
and for the record, yes, I am sure I called the lantern "Lantern"... I tried, but the door still won't open. Huh
Ok, here's what you do:

Since you already have your GlobalVarInt set up, use an if statement in your hallway map to unlock the door. So, for example:

void OnEnter()
{
if(GetGlobalVarInt("LanternVar")==1)
{ SetLevelDoorLocked(blahblahblah);
}
}

Here's where I suspect the problem is: You have your LanternVar set to 1 at the start of the game. Set it to 0. Then, when you get the lantern, adding 1 to it will make it 1, thus making the function I have outlined for you above work properly. Hope that helped Smile
(07-27-2011, 01:06 AM)Anxt Wrote: [ -> ]Ok, here's what you do:

Since you already have your GlobalVarInt set up, use an if statement in your hallway map to unlock the door. So, for example:

void OnEnter()
{
if(GetGlobalVarInt("LanternVar")==1)
{ SetLevelDoorLocked(blahblahblah);
}
}

Here's where I suspect the problem is: You have your LanternVar set to 1 at the start of the game. Set it to 0. Then, when you get the lantern, adding 1 to it will make it 1, thus making the function I have outlined for you above work properly. Hope that helped Smile

Thanks anxt! It's working completely fine now Smile