Frictional Games Forum (read-only)
I need help with my coding. - 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: I need help with my coding. (/thread-17428.html)



I need help with my coding. - tristanisms - 08-02-2012

I'm very new at Amnesia custom stories, and VERY new at coding. All I'm trying to do is make a key unlock a door (for now, maybe more help will be needed in the future). This is my work. The error I keep getting is that it won't let me unlock the door, it just says "Item cannot be used that way" please proofread and help me out.


////////////////////////////
// Run when entering map
void OnEnter()
{
AddUseItemCallback("", "Bedroom Key", "Bedroom Door", "UsedKeyOnDoor", true);
}

void UsedDoorKey(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("Bedroom Door", false, true);
PlaySoundAtEntity("", "unlock_door", "Bedroom Door", 0, false);
RemoveItem("Bedroom Key");
}

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

}


RE: I need help with my coding. - Adny - 08-02-2012

In your callback, you made the function "UsedKeyOnDoor" but the function you have is called "UsedDoorKey"; they're supposed to be the same. Also, you should never use spaces in coding (unless you're adding a debug message). Use underscores instead, they look like this --> "_"

Here's a revised version (be sure to change the names of the items in the level editor to match the ones in the script):


void OnStart()
{
AddUseItemCallback("", "Bedroom_Key", "Bedroom_Door", "UsedKeyOnDoor", true);
}

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

void OnEnter()
{

}

void OnLeave()
{

}


RE: I need help with my coding. - tristanisms - 08-02-2012

(08-02-2012, 07:43 PM)andyrockin123 Wrote: In your callback, you made the function "UsedKeyOnDoor" but the function you have is called "UsedDoorKey"; they're supposed to be the same. Also, you should never use spaces in coding (unless you're adding a debug message). Use underscores instead, they look like this --> "_"

Here's a revised version (be sure to change the names of the items in the level editor to match the ones in the script):


void OnStart()
{
AddUseItemCallback("", "Bedroom_Key", "Bedroom_Door", "UsedKeyOnDoor", true);
}

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

void OnEnter()
{

}

void OnLeave()
{

}
Thank you very much! I hope I can rely on people like you in the future.