Frictional Games Forum (read-only)
[SCRIPT] One script for multiple similar functions - 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] One script for multiple similar functions (/thread-13305.html)



One script for multiple similar functions - Shadowfied - 02-13-2012

In my custom story there's a place where you get a key which can, or will be able to open a lot of doors. I know there are ways to make a script like this one from White Night, used for the light switches:

void Lamp_Switcher(string &in asEntity, int alState)

{

if( alState == -1)

SetLampLit("swithcher_1_"+StringSub(asEntity,10,11), false, true);

if( alState == 1)

SetLampLit("swithcher_1_"+StringSub(asEntity,10,11), true, true);

}

I have about 10 doors called "cell_1" and up, can I somehow make a similar script so that I don't have to make individual parts of script for each door?

Thanks in advance.



RE: One script for multiple similar functions - flamez3 - 02-13-2012

AsEntity and asItem are how to do it.

Example:


void OnStart()
{
AddUseItemCallback("", "key_tomb_1", "prison_1", "door1", true);
AddUseItemCallback("", "key_tomb_2", "prison_2", "door1", true);
AddUseItemCallback("", "key_tomb_3", "prison_3", "door1", true);
AddUseItemCallback("", "key_tomb_4", "prison_4", "door1", true);
}

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


RE: One script for multiple similar functions - Shadowfied - 02-13-2012

(02-13-2012, 09:45 AM)flamez3 Wrote: AsEntity and asItem are how to do it.

Example:


void OnStart()
{
AddUseItemCallback("", "key_tomb_1", "prison_1", "door1", true);
AddUseItemCallback("", "key_tomb_2", "prison_2", "door1", true);
AddUseItemCallback("", "key_tomb_3", "prison_3", "door1", true);
AddUseItemCallback("", "key_tomb_4", "prison_4", "door1", true);
}

void door1(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
PlaySoundAtEntity("", "unlock_door", "door1", 0.0f, false);
RemoveItem(asItem);
}
Ah! Thanks! Flamez to the rescue once again ;]





RE: One script for multiple similar functions - Your Computer - 02-13-2012

flamez3 forgot to replace the string door1 with the variable asEntity in the door1 function for PlaySoundAtEntity.


RE: One script for multiple similar functions - flamez3 - 02-14-2012

(02-13-2012, 08:49 PM)Your Computer Wrote: flamez3 forgot to replace the string door1 with the variable asEntity in the door1 function for PlaySoundAtEntity.
Tongue


RE: One script for multiple similar functions - Shadowfied - 02-14-2012

(02-13-2012, 08:49 PM)Your Computer Wrote: flamez3 forgot to replace the string door1 with the variable asEntity in the door1 function for PlaySoundAtEntity.
Yeah I noticed. Thanks though.





RE: One script for multiple similar functions - Ninami - 02-15-2012

Would be nice if people could put "SOLVED" in the title when it's solved Tongue