Frictional Games Forum (read-only)

Full Version: Error: Unexpected token {
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
After i have made this script



void OnStart()
{
AddEntityCollideCallback("Player" , "ScriptArea_1" , "MonsterFunc1" , true , 1);
}
void MonsterFunc1(string &in asParent , string &in asChild , int alState)
{
SetEntityActive("servant_grunt_1" , true);
}




{ <------- Complain about this one

AddUseItemCallback("", "Elevator_key", "elevator_door_1", "KeyOnDoor", true);

}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("elevator_door_1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "elevator_door_1", 0.0f, true);
}

I get this Error: Unexpected token { and if i remove the script for the door and key it works, but why wont it work with the key script?
try putting void OnEnter()
above it
Quote:void OnStart()
{
AddEntityCollideCallback("Player" , "ScriptArea_1" , "MonsterFunc1" , true , 1);
}
void MonsterFunc1(string &in asParent , string &in asChild , int alState)
{
SetEntityActive("servant_grunt_1" , true);
}




{ <------- remove

AddUseItemCallback("", "Elevator_key", "elevator_door_1", "KeyOnDoor", true); <------- put inside OnStart or OnEnter.

} <------- remove

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("elevator_door_1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "elevator_door_1", 0.0f, true);
}
None of that did work, all i get is new errors.
Either i already have a void OnStart() or it want indentifiers when i remove { and use void onEnter() or that i should use , or ; efter ()
but none of that work.

Did remove the key and door for the moment, and was going to try this


void OnEnter();
AddEntityCollideCallback("Player" , "ScriptArea_3" , true , 1);


SetEntityActive("wind_1" , true);
SetEntityActive("wind_sound" , true);
PlaySoundAtEntity("wind_sound", "ambience_wind_eerie.snt", "player", 2.0f, false);


I have not added any { }, if i do it says i should remove them or i should add them.
If you intend on using like this

void OnEnter();
AddEntityCollideCallback("Player" , "ScriptArea_3" , true , 1);

You'll need to add { and }

Like this

void OnEnter();
{
AddEntityCollideCallback("Player" , "ScriptArea_3" , true , 1);
}
But if i do like you did i get the error unexpected token { and expected indentifier.
void OnEnter();
{
AddEntityCollideCallback("Player" , "ScriptArea_3" , true , 1);
}

remove the ; from void onEnter(), when you create a function you NEVER put ; behind that. This is also the case for if statements, for loops etc.

It should look like:

void OnEnter()
{
AddEntityCollideCallback("Player" , "ScriptArea_3" , true , 1);
}
Code:
void OnStart()
{
AddEntityCollideCallback("Player" , "ScriptArea_1" , "MonsterFunc1" , true , 1);
AddUseItemCallback("", "Elevator_key", "elevator_door_1", "KeyOnDoor", true);
}

void MonsterFunc1(string &in asParent , string &in asChild , int alState)
{
SetEntityActive("servant_grunt_1" , true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("elevator_door_1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "elevator_door_1", 0.0f, true);
}
Its working now, thanks all Big Grin