Frictional Games Forum (read-only)
[SCRIPT] Fatal Error on this script - 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: [SCRIPT] Fatal Error on this script (/thread-17782.html)



Fatal Error on this script - jtylerg - 08-15-2012

All that is on this script is 2 keys which open 2 different doors (Basementkey_1, which opens mansion_1... and startkey, which opens cabinet_1) when i go to start the game it crashes with a fatal error saying "main 15,1 : ERR Unexpected Token '{'

Any fixes or ideas of why this happens? (the code starts on line 1, it's just messed up on here for some reason... also, before i added startkey and cabinet_1 codes... Basementkey_1 and mansion_1 worked perfectly fine)


  1. ////////////////////////////
  2. // Run when entering map
  3. void OnStart()
  4. {
  5. AddUseItemCallback("", "BasementKey_1", "mansion_1", "UsedKeyOnDoor", true);
  6. }
  7. void UsedKeyOnDoor(string &in asItem, string &in asEntity)
  8. {
  9. SetSwingDoorLocked("mansion_1", false, true);
  10. PlaySoundAtEntity("", "unlock_door", "mansion_1", 0, false);
  11. RemoveItem("BasementKey_1");
  12. }
  13. {
  14. AddUseItemCallback("", "startkey", "cabinet_1", "UsedKeyOnDoor", true);
  15. }
  16. void UsedKeyOnDoor(string &in asItem, string &in asEntity)
  17. {
  18. SetSwingDoorLocked("cabinet_1", false, true);
  19. PlaySoundAtEntity("", "unlock_door", "cabinet_1", 0, false);
  20. RemoveItem("startkey");
  21. }
  22. ////////////////////////////
  23. // Run when leaving map
  24. void OnLeave()
  25. {
  26. }



RE: Fatal Error on this script - Adny - 08-15-2012

You must put all callbacks under void OnStart(), you can use void OnEnter() but that has more specific applications. You also can't have two functions with the exact same name (you used UseKeyOnDoor twice). Here's a cool trick you can do using asItem and asEntity that will fix your problem as well as reduce script clutter:


void OnStart()
{
AddUseItemCallback("", "BasementKey_1", "mansion_1", "UsedKeyOnDoor", true);
AddUseItemCallback("", "startkey", "cabinet_1", "UsedKeyOnDoor", true);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, false);
PlaySoundAtEntity("", "unlock_door", asEntity, 0, false);
RemoveItem(asItem);
}


Hope that helped


RE: Fatal Error on this script - Ongka - 08-15-2012

////////////////////////////
// Run when entering map
void OnStart()
{
AddUseItemCallback("", "BasementKey_1", "mansion_1", "UsedKeyOnDoor", true);
AddUseItemCallback("", "startkey", "cabinet_1", "UsedKeyOnDoor", true);
}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_1", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_1", 0, false);
RemoveItem("BasementKey_1");
}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("cabinet_1", false, true);
PlaySoundAtEntity("", "unlock_door", "cabinet_1", 0, false);
RemoveItem("startkey");
}
////////////////////////////
// Run when leaving map
void OnLeave()
{
}



You put brackets around the green function but didn't use a header, this caused the error.
You can just put it in the voidOnStart().

Edit: Andy was a bit faster ^^


RE: Fatal Error on this script - jtylerg - 08-16-2012

I copy and pasted Ongka's solution onto notepad++ ad still recieve a fatal error at 15'1 unexpected token {

(08-15-2012, 04:19 PM)Ongka Wrote: ////////////////////////////
// Run when entering map
void OnStart()
{
AddUseItemCallback("", "BasementKey_1", "mansion_1", "UsedKeyOnDoor", true);
AddUseItemCallback("", "startkey", "cabinet_1", "UsedKeyOnDoor", true);
}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_1", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_1", 0, false);
RemoveItem("BasementKey_1");
}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("cabinet_1", false, true);
PlaySoundAtEntity("", "unlock_door", "cabinet_1", 0, false);
RemoveItem("startkey");
}
////////////////////////////
// Run when leaving map
void OnLeave()
{
}



You put brackets around the green function but didn't use a header, this caused the error.
You can just put it in the voidOnStart().

Edit: Andy was a bit faster ^^
I copy and pasted that and still receive the same error.

(08-15-2012, 04:19 PM)andyrockin123 Wrote: You must put all callbacks under void OnStart(), you can use void OnEnter() but that has more specific applications. You also can't have two functions with the exact same name (you used UseKeyOnDoor twice). Here's a cool trick you can do using asItem and asEntity that will fix your problem as well as reduce script clutter:


void OnStart()
{
AddUseItemCallback("", "BasementKey_1", "mansion_1", "UsedKeyOnDoor", true);
AddUseItemCallback("", "startkey", "cabinet_1", "UsedKeyOnDoor", true);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, false);
PlaySoundAtEntity("", "unlock_door", asEntity, 0, false);
RemoveItem(asItem);
}


Hope that helped
This doesn't work either... same error every time "15,1" Unexpected token {


RE: Fatal Error on this script - Ongka - 08-16-2012

////////////////////////////
// Run when entering map
void OnStart()
{
AddUseItemCallback("", "BasementKey_1", "mansion_1", "UsedKeyOnDoor", true);
AddUseItemCallback("", "startkey", "cabinet_1", "UsedKeyOnCabinet", true);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_1", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_1", 0, false);
RemoveItem("BasementKey_1");
}

void UsedKeyOnCabinet(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("cabinet_1", false, true);
PlaySoundAtEntity("", "unlock_door", "cabinet_1", 0, false);
RemoveItem("startkey");
}

////////////////////////////
// Run when leaving map
void OnLeave()
{
}

Changed the function name, this should work.


RE: Fatal Error on this script - Adny - 08-16-2012

Considering my revision isn't even 15 characters long, I'm almost completely sure you didn't clear/delete your script original before pasting mine in. This concept would also explain why regardless of our solutions, you get the same exact error.


RE: Fatal Error on this script - TheGreatCthulhu - 08-16-2012

True. Also make sure to go to the line that caused the error and inspect the code yourself
The error comes from an "orphaned" method body (the stuff beteen { and } )
Bellow is your original code - the reason for the error is in red:

////////////////////////////
// Run when entering map
void OnStart()
{
AddUseItemCallback("", "BasementKey_1", "mansion_1", "UsedKeyOnDoor", true);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_1", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_1", 0, false);
RemoveItem("BasementKey_1");
}
{
AddUseItemCallback("", "startkey", "cabinet_1", "UsedKeyOnDoor", true);
}


void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("cabinet_1", false, true);
PlaySoundAtEntity("", "unlock_door", "cabinet_1", 0, false);
RemoveItem("startkey");
}

////////////////////////////
// Run when leaving map
void OnLeave()
{
}

You have to take the AddUseItemCallback(...) call out of there, and delete the invalid {} block.


RE: Fatal Error on this script - jtylerg - 08-16-2012

(08-16-2012, 07:00 PM)Ongka Wrote: ////////////////////////////
// Run when entering map
void OnStart()
{
AddUseItemCallback("", "BasementKey_1", "mansion_1", "UsedKeyOnDoor", true);
AddUseItemCallback("", "startkey", "cabinet_1", "UsedKeyOnCabinet", true);
}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("mansion_1", false, true);
PlaySoundAtEntity("", "unlock_door", "mansion_1", 0, false);
RemoveItem("BasementKey_1");
}

void UsedKeyOnCabinet(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("cabinet_1", false, true);
PlaySoundAtEntity("", "unlock_door", "cabinet_1", 0, false);
RemoveItem("startkey");
}

////////////////////////////
// Run when leaving map
void OnLeave()
{
}

Changed the function name, this should work.
Thanks! That worked perfectly