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
Script Help Callback func doesn't get called after enemy leaves area
FragdaddyXXL Offline
Member

Posts: 136
Threads: 20
Joined: Apr 2012
Reputation: 7
#1
Callback func doesn't get called after enemy leaves area

PHP Code: (Select All)
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.

Dark Seclusion Here
(This post was last modified: 05-24-2012, 12:57 AM by FragdaddyXXL.)
05-24-2012, 12:42 AM
Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#2
RE: Callback func doesn't get called after enemy leaves area

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

I rate it 3 memes.
05-24-2012, 12:57 AM
Find
FragdaddyXXL Offline
Member

Posts: 136
Threads: 20
Joined: Apr 2012
Reputation: 7
#3
RE: Callback func doesn't get called after enemy leaves area

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?

Dark Seclusion Here
(This post was last modified: 05-24-2012, 02:02 AM by FragdaddyXXL.)
05-24-2012, 01:05 AM
Find
Rapture Offline
Posting Freak

Posts: 1,078
Threads: 79
Joined: May 2011
Reputation: 30
#4
RE: Callback func doesn't get called after enemy leaves area

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.
05-24-2012, 02:39 AM
Find
FragdaddyXXL Offline
Member

Posts: 136
Threads: 20
Joined: Apr 2012
Reputation: 7
#5
RE: Callback func doesn't get called after enemy leaves area

All right, I'll give it a shot. Smile

Dark Seclusion Here
05-24-2012, 02:49 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#6
RE: Callback func doesn't get called after enemy leaves area

Collisions occur when one object enters another object. Simply brushing up against another object is not enough to trigger a collision (callback).

Tutorials: From Noob to Pro
(This post was last modified: 05-24-2012, 03:11 AM by Your Computer.)
05-24-2012, 03:10 AM
Website Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#7
RE: Callback func doesn't get called after enemy leaves area

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

I rate it 3 memes.
05-24-2012, 03:13 AM
Find
FragdaddyXXL Offline
Member

Posts: 136
Threads: 20
Joined: Apr 2012
Reputation: 7
#8
RE: Callback func doesn't get called after enemy leaves area

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?

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

With receiving function:
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.

Dark Seclusion Here
(This post was last modified: 05-24-2012, 03:44 AM by FragdaddyXXL.)
05-24-2012, 03:20 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#9
RE: Callback func doesn't get called after enemy leaves area

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

Tutorials: From Noob to Pro
05-24-2012, 03:22 AM
Website Find
FragdaddyXXL Offline
Member

Posts: 136
Threads: 20
Joined: Apr 2012
Reputation: 7
#10
RE: Callback func doesn't get called after enemy leaves area

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.

Dark Seclusion Here
05-24-2012, 03:49 AM
Find




Users browsing this thread: 1 Guest(s)