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


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Doors behave stangely
ingedoom Offline
Member

Posts: 120
Threads: 12
Joined: Feb 2012
Reputation: 0
#1
Doors behave stangely

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: (Select All)
//======================
//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: (Select All)
//======================
//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()
        {
        
        } 


[Image: 23778.png]
(This post was last modified: 03-22-2013, 04:53 PM by ingedoom.)
03-20-2013, 05:36 PM
Website Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#2
RE: Calling functions from timers

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

//======================
//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.

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
03-20-2013, 05:53 PM
Find
ingedoom Offline
Member

Posts: 120
Threads: 12
Joined: Feb 2012
Reputation: 0
#3
RE: Calling functions from timers

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

[Image: 23778.png]
03-20-2013, 06:01 PM
Website Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#4
RE: Calling home made functions

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.

"Veni, vidi, vici."
"I came, I saw, I conquered."
(This post was last modified: 03-21-2013, 05:57 AM by PutraenusAlivius.)
03-21-2013, 05:56 AM
Find
ingedoom Offline
Member

Posts: 120
Threads: 12
Joined: Feb 2012
Reputation: 0
#5
RE: Calling home made functions

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

[Image: 23778.png]
03-21-2013, 07:25 AM
Website Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#6
RE: Calling functions from timers

(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...c_ref.html


This line,
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
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

(This post was last modified: 03-22-2013, 01:05 PM by Adrianis.)
03-22-2013, 12:29 PM
Find
ingedoom Offline
Member

Posts: 120
Threads: 12
Joined: Feb 2012
Reputation: 0
#7
RE: Calling functions from timers

(03-22-2013, 12:29 PM)Adrianis Wrote: Checkout this part of the AS manual,
http://www.angelcode.com/angelscript/sdk...c_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,
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: (Select All)
    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: (Select All)
    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: (Select All)
            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.

[Image: 23778.png]
(This post was last modified: 03-22-2013, 04:50 PM by ingedoom.)
03-22-2013, 04:21 PM
Website Find
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#8
RE: Doors behave stangely

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

03-22-2013, 05:18 PM
Find




Users browsing this thread: 1 Guest(s)