Frictional Games Forum (read-only)
[SCRIPT] a funtion with the same name and parameter already exists - 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] a funtion with the same name and parameter already exists (/thread-15073.html)



a funtion with the same name and parameter already exists - chweaw - 04-24-2012

Ok hi! I know you hear this a lot but I am new to the whole making of customstories and Im not good with scripting. I tried to read some about it but i get dizzy and get headaches so I figured you guys might help me and teach me a thing about this problem of mine.
So what I have done is that I have created an area that closes a door behind me on collision and what I wanted to do next was to make a sound play as i enter the new room.

Script as it looks like so far:


////////////////////////////
// Run when entering map
void OnEnter()
{
AddUseItemCallback("", "key_1", "door_1", "UsedKeyOnDoor", true);
}


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

void OnStart()
{
AddEntityCollideCallback("Player" , "ScriptArea_1" , "DoorCloseFunc1" , true , 1);
}
void DoorCloseFunc1(string &in asParent , string &in asChild , int alState)
{
SetSwingDoorClosed("door_1", true, true);
}

void OnStart()
{
PreloadSound("00_laugh.snt");
AddEntityCollideCallback("Player", "ScriptArea_1", "Sound", true, 1);
}


void Sound(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("sound", "00_laugh.snt", "ScriptArea_1", 0.0, false);
}
////////////////////////////
// Run when leaving map
void OnLeave()
{

}
I get the error 21,1 : a funtion with the same name and parameter already exists


So what should I do? I want to learn more.



RE: a funtion with the same name and parameter already exists - Your Computer - 04-24-2012

(04-24-2012, 11:19 PM)chweaw Wrote: I want to learn more.

Then do research on function overloading.


RE: a funtion with the same name and parameter already exists - chweaw - 04-24-2012

(04-24-2012, 11:20 PM)Your Computer Wrote:
(04-24-2012, 11:19 PM)chweaw Wrote: I want to learn more.

Then do research on function overloading.
Ok, just need the keywords to search and I will Smile thx
(04-24-2012, 11:20 PM)Your Computer Wrote:
(04-24-2012, 11:19 PM)chweaw Wrote: I want to learn more.

Then do research on function overloading.
You might just think I'm lazy but man, I do not understand how to get this working! could you please just tell me and why so that i can fix my future problems?


RE: a funtion with the same name and parameter already exists - Your Computer - 04-24-2012

(04-24-2012, 11:31 PM)chweaw Wrote: You might just think I'm lazy but man, I do not understand how to get this working! could you please just tell me and why so that i can fix my future problems?

You have two void OnStart() functions. You can only have one.


RE: a funtion with the same name and parameter already exists - TeamSD - 04-25-2012

Here you go. This should do the trick! Smile

////////////////////////////
// Run first time starting map
void OnStart()
{
AddEntityCollideCallback("Player" , "ScriptArea_1" , "DoorCloseFunc1" , true , 1);
PreloadSound("00_laugh.snt");
AddEntityCollideCallback("Player", "ScriptArea_1", "Sound", true, 1);
}


void DoorCloseFunc1(string &in asParent , string &in asChild , int alState)
{
SetSwingDoorClosed("door_1", true, true);
}

void Sound(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("sound", "00_laugh.snt", "ScriptArea_1", 0.0, false);
}

////////////////////////////
// Run when entering map
void OnEnter()
{
AddUseItemCallback("", "key_1", "door_1", "UsedKeyOnDoor", true);
}


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

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

}


RE: a funtion with the same name and parameter already exists - chweaw - 04-25-2012

(04-24-2012, 11:57 PM)Your Computer Wrote:
(04-24-2012, 11:31 PM)chweaw Wrote: You might just think I'm lazy but man, I do not understand how to get this working! could you please just tell me and why so that i can fix my future problems?

You have two void OnStart() functions. You can only have one.
But lets say that i have a series of functions that uses the same name, what do i do to make it work? not having multiple void OnStart() functions?
thanks for the help btw


RE: a funtion with the same name and parameter already exists - SilentStriker - 04-25-2012

btw, Callbacks should be in OnStart since usually you only want the callbacks to happen the first time you enter the map Smile if it's on enter it calls every time you enter the map



RE: a funtion with the same name and parameter already exists - chweaw - 04-25-2012

(04-25-2012, 12:19 PM)TeamSD Wrote: Here you go. This should do the trick! Smile

////////////////////////////
// Run first time starting map
void OnStart()
{
AddEntityCollideCallback("Player" , "ScriptArea_1" , "DoorCloseFunc1" , true , 1);
PreloadSound("00_laugh.snt");
AddEntityCollideCallback("Player", "ScriptArea_1", "Sound", true, 1);
}


void DoorCloseFunc1(string &in asParent , string &in asChild , int alState)
{
SetSwingDoorClosed("door_1", true, true);
}

void Sound(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("sound", "00_laugh.snt", "ScriptArea_1", 0.0, false);
}

////////////////////////////
// Run when entering map
void OnEnter()
{
AddUseItemCallback("", "key_1", "door_1", "UsedKeyOnDoor", true);
}


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

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

}
Thank you! i really appreciate the help Blush