Frictional Games Forum (read-only)
Whats wrong with my script? - 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 (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: Whats wrong with my script? (/thread-8039.html)



Whats wrong with my script? - Sennep - 05-16-2011

Hi!

This is a part of my script:

void OnStart()
{
AddUseItemCallback("", "bedroomkey", "mansion_1", "UsedKeyOnDoor", true);
AddEntityCollideCallback("player", "area_darkmusic", "PlayDarkMusic", true, 1);
}

void PlayDarkMusic(string &in asParent, string &in asChild, int alState)
{
PlayMusic("04_amb.ogg", true, 1.0f, 0, 0, true);
SetEntityActive("servant_grunt_1", true);
}

But there's something wrong with it. What happens is, the Grunt stays inactive and the music doesn't play.

Can you spot the bug?

Oh, and ignore the AddUseItemCallback.


RE: Whats wrong with my script? - Roenlond - 05-16-2011

AddEntityCollideCallback("Player", "area_darkmusic", "PlayDarkMusic", true, 1);

There's your issue. It should be capitalized.


RE: Whats wrong with my script? - Sennep - 05-16-2011

Oh.. Well that was pretty simple.

Thanks for the help!


RE: Whats wrong with my script? - Roenlond - 05-16-2011

Most errors are simple to solve once you spot them Smile


RE: Whats wrong with my script? - Sennep - 05-16-2011

heh yeah Big Grin


RE: Whats wrong with my script? - Sennep - 05-16-2011

Again i have a script question (is there a thread for that?).

void OnStart()
{
AddUseItemCallback("", "bedroomkey", "mansion_1", "UsedKeyOnDoor", true);
AddEntityCollideCallback("Player", "area_darkmusic", "PlayDarkMusic", false, 1);
AddEntityCollideCallback("Player", "area_darkmusic", "StopDarkMusic", false, -1);
}

void StopDarkMusic(string &in asParent, string &in asChild, int alState)
{
StopMusic(3, 0);
}

void PlayDarkMusic(string &in asParent, string &in asChild, int alState)
{
PlayMusic("04_amb.ogg", true, 1.0f, 3, 0, true);
}

That is the beginning of my script. The point is that i want to have music, but only when you are in a special area. The music doesn't go away when you exit area.


RE: Whats wrong with my script? - MrBigzy - 05-16-2011

I assume the script area is large and takes up the whole room? Actually, you can't set the callback for the same area twice. Make two separate areas.


RE: Whats wrong with my script? - Kyle - 05-16-2011

You could do this, but put the area at where the player will enter/exit the room:

Code:
void OnStart()
{
     AddEntityCollideCallback("Player", "area_darkmusic", "PlayDarkMusic", false, 1);
}
void PlayDarkMusic(string &in asParent, string &in asChild, int alState)
{
     PlayMusic("04_amb.ogg", true, 1, 3, 0, true);
     AddTimer("", 2, "Func01");
}
void Func01(string &in asTimer)
{
     AddEntityCollideCallback("Player", "area_darkmusic", "StopDarkMusic", false, 1);
}
void StopDarkMusic(string &in asParent, string &in asChild, int alState)
{
     StopMusic(3, 0);
}

You can further modify the script to where it is impossible for the music to still play when the player leaves the area.


RE: Whats wrong with my script? - Sennep - 05-17-2011

Hm. Didn't know you couldn't set two callbacks for one area. But its working now. Thanks!


RE: Whats wrong with my script? - Tanshaydar - 05-17-2011

Instead, you can use 'alState's to determine when player enters or escapes from the area and use them as intended.

if( alState == 1) -> This is for entering
if( alState == -1) -> This is for escaping
if( alState == 0) -> This is for both