Frictional Games Forum (read-only)
Doors behave stangely - 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 - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Doors behave stangely (/thread-20832.html)



Doors behave stangely - ingedoom - 03-20-2013

Hi forum.

I have a problem that i hope you can help me solve. The problem is; that the OpenDoor() function doesn't seem to work when it's called from within a timer function (in this case IntroHalt()). The debug message "door opens" is sent but the door is not affected by the script. When i call the function from Onstart() or StartIntro() it works just fine and the door opens.
I've also tried to put the door opening script inside the timer function itself, but this does not work either..

Do i have to make a ScriptArea for this to work, or can i do something else to avoid it? So i won't have to worry about adding areas in the level editor?

Also, can you explain why i can't seem to call the door opening script from a timer?


Spoiler below!

PHP Code:
//======================
//Functions 
    
void AddDebugMessage(string text)// Just for debug purposes
        
{
            
AddDebugMessage(textfalse);
        }
    
void StartIntro()//Starts intro sequence
        
{
            
AddDebugMessage("Intro Started");
            
FadeOut(0.0f);
            
FadeIn(15.0f);
            
SetPlayerActive(false);
            
AddTimer("MoveForward"0.01f"IntroMove");
            
AddTimer("StopMoving"53.0f"IntroHalt");
        }
    
void IntroMove(string TimerName)
        {
            
MovePlayerForward(0.005f);
            
AddTimer("MoveForward"0.01f"IntroMove");
        }
    
void IntroHalt(string TimerName)
        {
            
AddDebugMessage("Player stops");
            
RemoveTimer("MoveForward");
            
OpenDoor("prison_11");
        }
    
void OpenDoor(string door)
        {
            
AddDebugMessage("Door opens");
            
SetSwingDoorDisableAutoClose(doortrue);
            
SetSwingDoorClosed(doorfalsefalse);
            
SetMoveObjectState(door0.1f);
            
AddPropForce(door, -50000"world");
        }
//======================
//Run when map first starts
    
void OnStart()
        {
            if(
ScriptDebugOn() and ! HasItem("lantern"))
                {
                    
GiveItemFromFile("lantern""lantern.ent");
                    
SetPlayerLampOil(100.0f);
                    
SetPlayerRunSpeedMul(5.0f);
            
                    for(
int i 0;10;i++)
                        {
                            
GiveItemFromFile("tinderbox""tinderbox.ent");
                        }
                }
            
StartIntro();
        }

//=====================
//Run when entering map//
    
void OnEnter()
        {
            
        }

//=====================
//Run when leaving map//
    
void OnLeave()
        {
        
        } 


Edit: I tried to call the OpenDoor function with an EntityCollideCallback, but that didn't help either. I still only get the debug message
Spoiler below!

PHP Code:
//======================
//Functions
    
void AddDebugMessage(string text)// Just for debug purposes
        
{
            
AddDebugMessage(textfalse);
        }
//Starts intro sequence
    
void StartIntro()
        {
            
AddDebugMessage("Intro Started");
            
/*FadeOut(0.0f);
            FadeIn(15.0f);
            SetPlayerActive(false);
            AddTimer("MoveForward", 0.01f, "IntroMove");
            AddTimer("StopMoving", 54.0f, "IntroHalt");*/
        
}
    
void IntroMove(string TimerName)
        {
            
MovePlayerForward(0.005f);
            
AddTimer("MoveForward"0.01f"IntroMove");
        }
    
void IntroHalt(string TimerName)
        {
            
AddDebugMessage("Player stops");
            
RemoveTimer("MoveForward");
        }
    
void CollideScriptArea_1(string ParentNamestring ChildNameint alState)
        {
            
AddDebugMessage("Player collides with " ChildName);
            
OpenDoor("prison_11");
        }
    
void OpenDoor(string door)
        {
            
AddDebugMessage("Door opens");
            
SetSwingDoorDisableAutoClose(doortrue);
            
SetSwingDoorClosed(doorfalsefalse);
            
SetMoveObjectState(door0.1f);
            
AddPropForce(door, -50000"world");
        }
//======================
//Run when map first starts
    
void OnStart()
        {
//==========Map testing
            
if(ScriptDebugOn() and ! HasItem("lantern"))
                {
                    
GiveItemFromFile("lantern""lantern.ent");
                    
SetPlayerLampOil(100.0f);
                    
SetPlayerRunSpeedMul(5.0f);
            
                    for(
int i 0;10;i++)
                        {
                            
GiveItemFromFile("tinderbox""tinderbox.ent");
                        }
                }
//==========Actual map script
            
StartIntro();
            
AddEntityCollideCallback("Player""ScriptArea_1""CollideScriptArea_1"true1);
        }

//=====================
//Run when entering map//
    
void OnEnter()
        {
            
        }

//=====================
//Run when leaving map//
    
void OnLeave()
        {
        
        } 




RE: Calling functions from timers - The chaser - 03-20-2013

When making timers, the parameters (void Example ()) are always "string &in asTimer". So:

Code:
//======================
//Functions
    void AddDebugMessage(string text)// Just for debug purposes
        {
            AddDebugMessage(text, false);
        }
    void StartIntro()//Starts intro sequence
        {
            AddDebugMessage("Intro Started");
            FadeOut(0.0f);
            FadeIn(15.0f);
            SetPlayerActive(false);
            AddTimer("MoveForward", 0.01f, "IntroMove");
            AddTimer("StopMoving", 53.0f, "IntroHalt");
        }
    void IntroMove(string &in asTimer)
        {
            MovePlayerForward(0.005f);
            AddTimer("MoveForward", 0.01f, "IntroMove");
        }
    void IntroHalt(string &in asTimer)
        {
            AddDebugMessage("Player stops");
            RemoveTimer("MoveForward");
            OpenDoor("prison_11");
        }
    void OpenDoor(string door)
        {
            AddDebugMessage("Door opens");
            SetSwingDoorDisableAutoClose(door, true);
            SetSwingDoorClosed(door, false, false);
            SetMoveObjectState(door, 0.1f);
            AddPropForce(door, -500, 0, 0, "world");
        }
//======================
//Run when map first starts
    void OnStart()
        {
            if(ScriptDebugOn() and ! HasItem("lantern"))
                {
                    GiveItemFromFile("lantern", "lantern.ent");
                    SetPlayerLampOil(100.0f);
                    SetPlayerRunSpeedMul(5.0f);
            
                    for(int i = 0;i < 10;i++)
                        {
                            GiveItemFromFile("tinderbox", "tinderbox.ent");
                        }
                }
            StartIntro();
        }

//=====================
//Run when entering map//
    void OnEnter()
        {
            
        }

//=====================
//Run when leaving map//
    void OnLeave()
        {
        
        }

What are you exactly trying to achieve at the OpenDoor thing? I don't understand what you are trying to do.


RE: Calling functions from timers - ingedoom - 03-20-2013

(03-20-2013, 05:53 PM)The chaser Wrote: When making timers, the parameters (void Example ()) are always "string &in asTimer". So:
No they are not. "&in asTimer" can be changed to whatever you please.
As i said, the timers work just fine.

(03-20-2013, 05:53 PM)The chaser Wrote: What are you exactly trying to achieve at the OpenDoor thing? I don't understand what you are trying to do.
OpenDoor is a self tailored function and is called from the IntroHalt timer fucntion, and is meant to open the door with the fuctions that are provided by the engine.


RE: Calling home made functions - PutraenusAlivius - 03-21-2013

StartIntro() and OpenDoor() is NOT a func included in the game. Or maybe that some functions that was in the original game wasn't put in the Script Functions page.


RE: Calling home made functions - ingedoom - 03-21-2013

(03-21-2013, 05:56 AM)JustAnotherPlayer Wrote: StartIntro() and OpenDoor() is NOT a func included in the game. Or maybe that some functions that was in the original game wasn't put in the Script Functions page.

You can make your own functions. Just as i said StartIntro() calls the script inside void StartIntro() and starts the timers FadeIn and what not. My problem is that i can only seem to get the door opening script to work when i use it in the beginning of the map, (inside either OnStart() or StartIntro() ) which is really wierd. Go read the script language and reference guide if you have no clue how my script should work. It might clear out some misunderstandings.


RE: Calling functions from timers - Adrianis - 03-22-2013

(03-20-2013, 06:01 PM)ingedoom Wrote:
(03-20-2013, 05:53 PM)The chaser Wrote: When making timers, the parameters (void Example ()) are always "string &in asTimer". So:
No they are not. "&in asTimer" can be changed to whatever you please.
As i said, the timers work just fine.

The '&' and 'in' are, seperately, both keywords used by AS. The name asTimer can change as that is just the name of the variable, and you can change &in too if you like but you shouldnt. string& is a string type that passes a memory address rather than the actual value to the function. Using &in means that the value of the variable cannot be modified, as opposed to say string &inout (or more simply string&) which would enable you to modify the value.

Checkout this part of the AS manual,
http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_func_ref.html


This line,
Code:
if(ScriptDebugOn() and ! HasItem("lantern"))
Can you use 'and'? the proper operator should be && for and, but forgive me if it works your way. Doesnt look like that would be the cause of the issue anyway.


I'm pretty sure that the cause of the issue is using
void OpenDoor(string door)
I'm surprised it doesn't cause an error, but it's likely not working because OpenDoor("prison_11"); is not passing the value correctly into the function - and because you use that string as the arguments for the rest of the calls in that function (rather than hard-coding it in) it may be just that it doesn't know what to open
Try it out as
Code:
void OpenDoor(string &in door)

If that fails, add or change the AddDebugMessage call in OpenDoor to print the value of the 'door' string so that we can see if it is the name causing the problem, or if there is something wrong with the rest of the calls in that function


RE: Calling functions from timers - ingedoom - 03-22-2013

(03-22-2013, 12:29 PM)Adrianis Wrote: Checkout this part of the AS manual,
http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_func_ref.html
Thx for &in explanation =) It ws really helpful. But it didn't solve the problem though.

(03-22-2013, 12:29 PM)Adrianis Wrote: This line,
Code:
if(ScriptDebugOn() and ! HasItem("lantern"))
Can you use 'and'? the proper operator should be && for and, but forgive me if it works your way. Doesnt look like that would be the cause of the issue anyway.
You can use "and" instead of && just fine. =)

(03-22-2013, 12:29 PM)Adrianis Wrote: If that fails, add or change the AddDebugMessage call in OpenDoor to print the value of the 'door' string so that we can see if it is the name causing the problem, or if there is something wrong with the rest of the calls in that function

PHP Code:
    void OnStart()
                {
        
OpenDoor("prison_11");
                }
    
void OpenDoor(string &in door)
        {
            
AddDebugMessage(door " opens");
            
SetSwingDoorDisableAutoClose(doortrue);
            
SetSwingDoorClosed(doorfalsefalse);
            
SetMoveObjectState(door0.1f);
            
AddPropForce(door, -50000"world");
        } 
This spits out "prison_11 opens" as out would expect and the door opens just fine.

My problem seems to be that this:
PHP Code:
    void CollideScriptArea_1(string &in ParentNamestring &in ChildNameint alState)
        {
            
AddDebugMessage("Player collides with " ChildName);
            
OpenDoor("prison_11");
        }
    
void OpenDoor(string &in door)
        {
            
AddDebugMessage(door " opens");
            
SetSwingDoorDisableAutoClose(doortrue);
            
SetSwingDoorClosed(doorfalsefalse);
            
SetMoveObjectState(door0.1f);
            
AddPropForce(door, -50000"world");
        } 
Spits out the same message "prison_11 opens", but yet the door doesn't open.

No matter what i do, the script beneath only works when i call it in the beginning, like in void OnStart(), but not when call it from somewhere else. ;/
PHP Code:
            SetSwingDoorDisableAutoClose(doortrue);
            
SetSwingDoorClosed(doorfalsefalse);
            
SetMoveObjectState(door0.1f);
            
AddPropForce(door, -50000"world"); 

It is very strange. I hope you know what might be wrong.

Okay i finally solved it.... There is nothing wrong with the script by the way, it is just the way doors behave that seem to be the problem.
I found out that is i if i opened and closed the door, the opening script worked also when called inside the areacollison function.
i solved it by simply setting the openstate to 0.1 in the level editor, and then in the beginning of the script make it close. That enabled my script to work. =)

F**king doors srsly.


RE: Doors behave stangely - Adrianis - 03-22-2013

Haha, brilliant... oh well. At least we all learned something Smile