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 Fatal Error on this script
jtylerg Offline
Junior Member

Posts: 4
Threads: 2
Joined: Aug 2012
Reputation: 0
#1
Fatal Error on this script

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. }
08-15-2012, 04:07 PM
Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#2
RE: Fatal Error on this script

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

I rate it 3 memes.
08-15-2012, 04:19 PM
Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#3
RE: Fatal Error on this script

////////////////////////////
// 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 ^^

[Image: 18694.png]
(This post was last modified: 08-15-2012, 04:20 PM by Ongka.)
08-15-2012, 04:19 PM
Find
jtylerg Offline
Junior Member

Posts: 4
Threads: 2
Joined: Aug 2012
Reputation: 0
#4
RE: Fatal Error on this script

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 {
(This post was last modified: 08-16-2012, 06:48 PM by jtylerg.)
08-16-2012, 06:44 PM
Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#5
RE: Fatal Error on this script

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

[Image: 18694.png]
(This post was last modified: 08-16-2012, 07:01 PM by Ongka.)
08-16-2012, 07:00 PM
Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#6
RE: Fatal Error on this script

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.

I rate it 3 memes.
08-16-2012, 07:16 PM
Find
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#7
RE: Fatal Error on this script

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.
08-16-2012, 07:21 PM
Find
jtylerg Offline
Junior Member

Posts: 4
Threads: 2
Joined: Aug 2012
Reputation: 0
#8
RE: Fatal Error on this script

(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
08-16-2012, 08:44 PM
Find




Users browsing this thread: 2 Guest(s)