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/area problem.
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#14
RE: Script/area problem.

I've tested the script - as far as code goes, it's well formed (should work in theory).

Is your monster by any chance completely inside (or at least intersects with) ScriptArea_1? Like, did you want it to be deactivated once it exits that area? That would explain it all. If it is, then almost as soon as you activate it in cake(), a collision is detected with the script area, so cake1() is called, where the monster is immediately disabled. It happens so fast you can't even see the enemy appearing in game.

If that's it, you can simply fix the problem by editing the cake() function, replacing the last parameter to AddEntityCollideCallback() from 1 (collision detected on enter) to -1 (collision detected on exit):

AddEntityCollideCallback
("suitor", "ScriptArea_1", "cake1", false, -1);


BTW, to avoid errors of this kind, which arise when code is based on "magic numbers", it's a good idea to use named constants - you don't have to worry about actual values all the time, and it improves code readability.

Something like this:
PHP Code: (Select All)
// First you consult the wiki once, to see what the values mean,
// and then you declare them as named constants (use descriptive names).
// Note: constants are oftern written in all caps, to easily distingusih them,
// but it's not required.
const int COLLIDE_ON_ENTER 1;
const 
int COLLIDE_ON_LEAVE = -1;
const 
int COLLIDE_ON_BOTH 0;

void OnStart()
{
    
AddDebugMessage("In OnStart()."false);   // The message will be displayed in the lower left corner
   
    
AddPropForce ("rope_beam02_Body_1"50000"world");  
    
PlayMusic("12_amb.ogg"true0.811true);   
    
AddEntityCollideCallback("Player""area""cake"false0);
}

void cake(string &in asParentstring &in asChildint alState)
{
    
SetEntityActive("suitor"true);   
    
AddEnemyPatrolNode("suitor""PathNode1"0"");   
    
AddEnemyPatrolNode("suitor""PathNode2"0""); 
    
    
// ----- HERE: ----- 
    
AddEntityCollideCallback("suitor""ScriptArea_1""cake1"falseCOLLIDE_ON_LEAVE);
}

void cake1(string &in asParentstring &in asChildint alState)
{
    
SetEntityActive("suitor"false);


P.S. In code editors you can usually make use of the auto-completion feature. In Notepad++, you can start to type the name of the constant, or function you've allready defined/used elsewhere (like: COLL), and then press Ctrl+Enter (on Windows) to get auto-completion suggestions (which will be, in this case, the three constants declared at the top).
(This post was last modified: 01-07-2013, 09:55 PM by TheGreatCthulhu.)
01-07-2013, 09:43 PM
Find


Messages In This Thread



Users browsing this thread: 1 Guest(s)