Frictional Games Forum (read-only)

Full Version: Callback func doesn't get called after enemy leaves area
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
PHP Code:
void OnStart()
{
    
//servant_brute_NoSound_1
    
string brute "servant_brute_NoSound_1";
    for (
int x 1<= 17x++) //Initialize all wall-phase collision detections
    
{
        
AddEntityCollideCallback(brute"block_box_"+x"WallPhase"false1); //When the brute collides with a block_box, deactivate the block box.
    
}
    
    
ShowEnemyPlayerPosition(brute);
}

void WallPhase(string &in asParentstring &in asChildint alState//when enemy interacts with block_box, it deactivates it
{    
    
string x StringSub(asChild112);
    
SetEntityActive(asChildfalse); //Deactivate box
    
AddEntityCollideCallback("servant_brute_NoSound_1""ScriptArea_"+x"WallSeal"true, -1); //Waits for enemy to leave area


void WallSeal(string &in asParentstring &in asChildint alState//Called when enemy leaves area
{
    
string x StringSub(asChild112); //get substring to obtain the number that tells us which box to reactivate.
    
SetEntityActive("block_box_"+xfalse); //Reactivate box
    
FadeEnemyToSmoke(asParentfalse); //TEST TO SEE IF THIS METHOD IS CALLED. RIGHT NOW, IT IS NOT.


I'm currently trying to come up with a system to have an enemy be able to phase through walls, much like the one in SCP-CB. Right now, I surround my wall pieces in thin block_box'es and change the wall's collide value to false. Since I cannot change that value freely with scripting alone, I turn to using blockboxes as the actual object that you collide with when you walk into a wall.

Sidenote: while typing this, I just realized that I could just have 2 walls in the same exact spot, 1 that collides, and one that doesn't. When the enemy collides with the collide-able wall, it deactivates that wall, but leave the non-collide-able wall activated. Although, I'm not sure If I can activate/deactivate walls. And it's too late now to change from blockboxes, but whatevs.

Anyway, I also surround the wall with thin ScriptAreas, so that when the enemy is finished walking through the wall, it can reactivate the blockbox so that the player cannot walk through it.

What I've noticed is that the function that is supposed to be called after the enemy leaves the area is not being called. I've had problems with this in the past, and maybe I just need some straight answers. Why is the function not being called when the enemy exits the area.

[Image: Areafeffefef.png]

SetEntityActive("block_box_"+x, false); //Reactivate box
Here's one problem, forgot to change false to true when I copy-pasted.
I'm not too experienced with scripting, but it feels like you're over complicating things. Why not use:

bool GetEntitiesCollide(string& asEntityA, string& asEntityB); + an if/else statement


If true set it block box inactive, if else set active? Seems like the most direct way, you'd just have to type out the functions for each wall (again, sorry if I missed the point of this, I'm not a very experienced scripter).
Quote: bool GetEntitiesCollide(string& asEntityA, string& asEntityB); + an if/else statement
That would work if it was constantly checking for collisions, which would require a looping timer that runs every 0.2 seconds to check. And I'm not too sure how memory-intensive having a timer run that quickly would be. But the same effect can be achieved with callbacks.

EDIT: Could this be a problem if the enemy is already within the area when I create a callback to check to see if he left?
0.2 seconds is fine, you can change it to 0.1 seconds. Have the timer enabled when it needs to be and remove it when its not needed, if your worried about any performance issues.
All right, I'll give it a shot. Smile
Collisions occur when one object enters another object. Simply brushing up against another object is not enough to trigger a collision (callback).
(05-24-2012, 03:10 AM)Your Computer Wrote: [ -> ]Collisions occur when one object enters another object. Simply brushing up against another object is not enough to trigger a collision (callback).
what if there is an script area slightly larger than the block box, would that work?
Well, I've implemented the timer, and my current issue I'm having involves passing which blackbox it was collided with. For every blockbox, there is ScriptArea that, in it's name, has a corresponding number.

Ex. block_box_3 corresponds with ScriptArea_3.

Now, I'm doing a shoddy way of passing this number around. I'm currently using substrings to take the number out of the string. I've tested this, and it seems to not be the value that I'm expecting.

Can I just add another parameter to the callback functions?

Code:
AddEntityCollideCallback(brute, "block_box_"+x, "WallPhase", false, 1, x);

With receiving function:
Code:
void WallPhase(string &in asParent, string &in asChild, int alState, int num) //when enemy interacts with block_box, it deactivates it
{
...
}

Just tried adding extra parameters, and the answer is: nope.
(05-24-2012, 03:13 AM)andyrockin123 Wrote: [ -> ]what if there is an script area slightly larger than the block box, would that work?

Only if the script area is used for the collision callback and not the block box (since script areas don't have any physical properties that prevent objects from entering it).
FIGURED OUT THAT PROBLEM!!
When I was getting the substring, I miscounted the amount of numbers I needed to skip. I had it set to 11, when it should have been 10.

I'm still worried tho. It gets 2 characters within the string, which would work no problem with "block_box_13", but I'm not sure if it will work for "block_box_1", or any other number 1-9.
Pages: 1 2