Frictional Games Forum (read-only)
Scripting help needed - 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 (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: Scripting help needed (/thread-8291.html)



Scripting help needed - willochill - 05-28-2011

Okay so im scripting this file, and whenever i script maps it seems like SOMETHING ALWAYS has to go wrong. This time it crashes and says:

FATAL ERROR: Could not load (script file)!
main (21, 1) :ERR :Expected expression value
main (27, 1) :ERR :Expected expression value

I copied and pasted the script so far into this thread, plz tell me what im doing wrong cuz im starting to get pissed off, seems like i always mess up one tiny little thing that crashes the entire map.

void OnStart()
{
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_1", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_3", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_6", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_7", 4.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_8", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_9", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_10", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_11", 2.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_12", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_13", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_14", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_15", 2.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_16", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_17", 2.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_18", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_19", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_20", 0.0f, "");
AddEnemyPatrolNode("servant_grunt_1", "PathNodeArea_21", 2.0f, "");
    AddEntityCollideCallback("Player", "AreaActivateGrunt", "Func01", false, 1);
AddEntityCollideCallback("servant_grunty_1", "AreaDisableGrunt", "Func02", false, 1);
PlayMusic("00_creak.ogg", true, 1.0f, 0.0f, 0, true);
}
void Func01(string &in asParent, string &in asChild, int alState)
{
     if (HasItem("lantern_1") == true)
     {
          SetEntityActive("servant_grunt_1", true);
          RemoveEntityCollideCallback("Player", "AreaActivateGrunt");
          return;
     }
}
void Func02(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("servant_grunt_1", false);
}



RE: Scripting help needed - palistov - 05-28-2011

Try taking the RemoveEntityCollideCallback("Player", "AreaActivateGrunt"); out and instead changing the boolean value regarding auto-remove callback on collide to true. Then change your if statement to re-add the collide callback if the player doesn't have the lantern. I've been staring at your script and nothing looks wrong.

I have however, experienced issues with removing collide callbacks in a function that is called by the collision itself.


RE: Scripting help needed - willochill - 05-28-2011

what do you mean by the second suggestion, "change the if statement to re-add the collide callback if the player doesn't have the lantern?" could you show that to me in script?


RE: Scripting help needed - palistov - 05-29-2011

Of course. That means you change AddEntityCollideCallback("Player", "AreaActivateGrunt", "Func01", false, 1); to true. False says that the function will be repeatedly called when the player enters the area. Changing it to true means the callback will happen only once.

Once you do that, you change your if statement to:

void Func01(string &in asParent, string &in asChild, int alState)
{
if(!HasItem("lantern_1")) { AddEntityCollideCallback("Player", "AreaActivateGrunt", "Func01", true, 1); return; }
if(HasItem("lantern_1") SetEntityActive("grunt_1", true);
}

The first if statement says that when the player does not have a lantern, the callback will be re-added. If the player does have the lantern, the first if statement will be ignored and the monster will be activated, without re-adding the callback. It does exactly what your script does, but without removing callbacks via script.