Frictional Games Forum (read-only)
help with areas and scripting - 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 - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: help with areas and scripting (/thread-14096.html)



help with areas and scripting - wargamer - 03-19-2012

Alright i am new to scripting and this is my first custom story. In my first room, im trying to make a door open as soon as a person walks into a script area right in front of the door.
however im getting these errors:
main (3,1) : INFO : Compiling void OnStart()
main (16,6) : RR : Expected "("

Here is my script so far:

Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
//Add the Lantern and 10 Tinderboxes when in Debug mode
if(ScriptDebugOn())
{
GiveItemFromFile("lantern", "lantern.ent");

for(int i=0;i<10;i++) GiveItemFromFile("potion_oil_large_"+i, "potion_oil_large.ent");
} for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
//Door opens by itself when moving into Trigger_Area1
{
AddEntityCollideCallback("Player", "ScriptArea1", "Collide_Area", true, 1);
}
void Collide_Area(string &in asParent, string &in asChild, int alState)
{
SetSwingDoorClosed("prison_1", false, true);
SetSwingDoorDisableAutoClose("prison_1", true);
AddPropImpulse("prison_1", 900.0f, 0.0f, 0.0f, "");
}
}



RE: help with areas and scripting - Apjjm - 03-19-2012

There seems to be a few issues. I have fixed the bracketing and also merged two for loops based off the assumption that you want to add 10 of both oil and tinderboxes only when in debug mode - the rest of the code looks OK but then again I may have missed something. Try the following:

Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
  //Add the Lantern and 10 Oil + Tinderboxes when in Debug mode
  if(ScriptDebugOn())
   {
    GiveItemFromFile("lantern", "lantern.ent");
    for(int i=0;i<10;i++)
     {
      GiveItemFromFile("potion_oil_large_"+i, "potion_oil_large.ent");
      GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
     }
   }
  
  //Door opens by itself when moving into Trigger_Area1
  AddEntityCollideCallback("Player", "ScriptArea1", "Collide_Area", true, 1);
}

void Collide_Area(string &in asParent, string &in asChild, int alState)
{
  SetSwingDoorClosed("prison_1", false, true);
  SetSwingDoorDisableAutoClose("prison_1", true);
  AddPropImpulse("prison_1", 900.0f, 0.0f, 0.0f, "");
}

It may just be the formatting when copy-pasting but indenting your code really helps you keep track of what brackets belong where - if you do not already do this.


RE: help with areas and scripting - wargamer - 03-19-2012

(03-19-2012, 03:47 AM)Apjjm Wrote: There seems to be a few issues. I have fixed the bracketing and also merged two for loops based off the assumption that you want to add 10 of both oil and tinderboxes only when in debug mode - the rest of the code looks OK but then again I may have missed something. Try the following:

Code:
////////////////////////////
// Run first time starting map
void OnStart()
{
  //Add the Lantern and 10 Oil + Tinderboxes when in Debug mode
  if(ScriptDebugOn())
   {
    GiveItemFromFile("lantern", "lantern.ent");
    for(int i=0;i<10;i++)
     {
      GiveItemFromFile("potion_oil_large_"+i, "potion_oil_large.ent");
      GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
     }
   }
  
  //Door opens by itself when moving into Trigger_Area1
  AddEntityCollideCallback("Player", "ScriptArea1", "Collide_Area", true, 1);
}

void Collide_Area(string &in asParent, string &in asChild, int alState)
{
  SetSwingDoorClosed("prison_1", false, true);
  SetSwingDoorDisableAutoClose("prison_1", true);
  AddPropImpulse("prison_1", 900.0f, 0.0f, 0.0f, "");
}

It may just be the formatting when copy-pasting but indenting your code really helps you keep track of what brackets belong where - if you do not already do this.


omg thank you so much! i have trying for two days straight trying to figure it out myself. ill try to learn from the mistakes i have made. thanks again.