Frictional Games Forum (read-only)

Full Version: A problem with a key
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a question.
I made a key and a door unlock it using this script
void OnStart()
{
AddUseItemCallback("", "key_tomb_2", "prison_2, "KeyOnDoor", true);
}
void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("prison_2", false, true);
RemoveItem(asItem);
PlaySoundAtEntity("", "unlock_door.snt", "prison_3", 0.0f, true);
}

And I want to do another key and another door
But I have an error. What I did wrong???
AddUseItemCallback("", "key_tomb_3", "prison_3", "KeyOnDoor", true);
}
void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("prison_3", false, true);
RemoveItem(asItem);
PlaySoundAtEntity("", "unlock_door.snt", "prison_3", 0.0f, true);
}
Err, you're using the same function again. You can't have two functions with the same name.
Sorry, I wrote too fast and didn't see that I wrote the same code.
I corrected it and now there is a normal code of my second key and the door.
Not only that...you can't have the same name for a function. Name it KeyOnDoor2 or something.
I tried! But I have an error again!
What's the error? The error always tells you where and what the problem is.

Edit: I see what the problem is anyway. All of your callback functions should be inside OnStart.
If it is possible, can you give me an example of this code?
Here you go:

Code:
void OnStart()
{
  // use "key_tomb_2" on "prison_2" door => calls "KeyOnDoor"
  AddUseItemCallback("", "key_tomb_2", "prison_2", "KeyOnDoor", true);

  // use "key_tomb_3" on "prison_3" door => calls "KeyOnDoor2"
  AddUseItemCallback("", "key_tomb_3", "prison_3", "KeyOnDoor2", true);
}

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

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